ug_ch7.htm

来自「db.* (pronounced dee-be star) is an adva」· HTM 代码 · 共 1,725 行 · 第 1/5 页

HTM
1,725
字号
<p><font size="2">d_setlock(<i>SET</i>, <i>type</i>, <i>task,dbn</i>)</font></p></td><td width="60%" valign="top"><p><font size="2">Lock data files associated with settype</font></p></td></tr><tr><td width="40%" valign="top"><p><font size="2">d_keylock(<i>FIELD</i>, <i>type</i>, <i>task,dbn</i>)</font></p></td><td width="60%" valign="top"><p><font size="2">Lock key file containing key field</font></p></td></tr><tr><td width="40%" valign="top"><p><font size="2">d_lock(<i>num</i>, <i>pkt</i>, <i>task,dbn</i>)</font></p></td><td width="60%" valign="top"><p><font size="2">Lock group of record and set types</font></p></td></tr><tr><td width="40%" valign="top"><p><font size="2">d_recfree(<i>REC</i>, <i>task,dbn</i>)</font></p></td><td width="60%" valign="top"><p><font size="2">Free lock on record type</font></p></td></tr><tr><td width="40%" valign="top"><p><font size="2">d_setfree(<i>SET</i>, <i>task,dbn</i>)</font></p></td><td width="60%" valign="top"><p><font size="2">Free lock on set type</font></p></td></tr><tr><td width="40%" valign="top"><p><font size="2">d_keyfree(<i>FIELD</i>, <i>task,dbn</i>)</font></p></td><td width="60%" valign="top"><p><font size="2">Free lock on key field type</font></p></td></tr><tr><td width="40%" valign="top"><p><font size="2">d_freeall(<i>task</i>)</font></p></td><td width="60%" valign="top"><p><font size="2">Free all read locks</font></p></td></tr><tr><td width="40%" valign="top"><p><font size="2">d_reclstat(<i>REC</i>, <i>type</i>, <i>task,dbn</i>)</font></p></td><td width="60%" valign="top"><p><font size="2">Get record type's lock status</font></p></td></tr><tr><td width="40%" valign="top"><p><font size="2">d_setlstat(<i>SET</i>, <i>type</i>, <i>task,dbn</i>)</font></p></td><td width="60%" valign="top"><p><font size="2">Get set type's lock status</font></p></td></tr><tr><td width="40%" valign="top"><p><font size="2">d_keylstat(<i>FIELD</i>, <i>type</i>, <i>task,dbn</i>)</font></p></td><td width="60%" valign="top"><p><font size="2">Get key field type's lock status</font></p></td></tr><tr><td width="40%" valign="top"><p><font size="2">d_timeout(<i>secs, task</i>)</font></p></td><td width="60%" valign="top"><p><font size="2">Specify wait time before timeout</font></p></td></tr></table><p><font size="2">Note that functions <b>d_trend</b> and<b>d_trabort</b> are also used with file locking although they arenot listed here. Recall that both functions free locked files. Theremaining pages of this section describe the functions listed inTable 7-3.</font></p><p>Function <b>d_reclock</b> locks the data file containing therecord type, as well as all key files containing key fields definedin the specified record type. For example, assume the following DDLstatements appear in your schema:</p><pre><font color="#0000FF">data file "tims.d01" contains system, key_word, intersect;data file "tims.d02" contains author, borrower, info, text;key  file "tims.k01" contains id_code;key  file "tims.k02" contains friend, word;...record info {   unique key char id_code[16];   /* dewey dec. code */   char info_title[80];           /* title of book, article, mag. */   char publisher[32];            /* name of publisher */   char pub_date[12];             /* date of publication */   int info_type;                 /* 0=book, 1=mag, 2=art */}...record key_word {   unique key char word[32];      /* subject key words */}...set key_to_info {   order last;   owner key_word;   member intersect;}</font></pre><p><font size="2">The call <b>d_reclock</b>(INFO, "r", task,CURR_DB) will cause <b>tims.d02</b> and <b>tims.k01</b> to beread-locked. The call <b>d_reclock</b>(KEY_WORD,"r", task, CURR_DB)will cause <b>tims.d01</b> and <b>tims.k02</b> to be read-locked.Record locks are always necessary when creating a record with keys,or when modifying key fields in records, because they guaranteethat all of the files related to the record will belocked.</font></p><p>Function <b>d_setlock</b> locks the data files that contain theowner and member record types of the specified set. The call<b>d_setlock</b>(KEY_TO_INFO, "r", CURR_DB) will cause only file<b>tims.d01</b> to be read-locked, because both record types arecontained in the same file. This function does not lock key filesassociated with records. Set locks are necessary when connecting ordisconnecting records in sets, or when traversing sets, becausethey guarantee that all of the files related to the set will belocked. Note, however, that if record locks had already beenapplied to both the <b>key_word</b> and <b>intersect</b> recordtypes, the set lock would not be needed (although it would beaccepted). Any time the correct files have been locked, even thoughby a different locking call, functions that use the files willexecute without locking errors.</p><p>Function <b>d_keylock</b> locks the key file that contains thespecified key field. The call <b>d_keylock</b>(ID_CODE, "r",CURR_DB) will lock only file <b>tims.k01</b>. By locking only a keyfile, you may scan keys, as in the following code:</p><pre><font color="#0000FF">d_keylock(ID_CODE, "r", task, CURR_DB);for ( (status=d_keyfrst(ID_CODE, task, CURR_DB));      status == S_OKAY;       (status=d_keynext(ID_CODE, task, CURR_DB)) ) {   d_keyread(id_code, task, CURR_DB);   printf("id code: %s\n", id_code);}d_keyfree (ID_CODE, task, CURR_DB);</font></pre><p><font size="2">By locking only the key file, you eliminate theoverhead of obtaining locks on the data file, and possibly otherkey files related to the same record type. Also, in a multi-userenvironment, it is important not to lock any files that are notgoing to be used, because you may be preventing other users frommaking progress.</font></p><p>Function <b>d_lock</b> is used to lock a group of record and settypes, and is described in detail in section 7.3.6, "Grouped LockRequests."</p><p>Table 7-4 lists the types of locks that can be applied.</p><p align="center"><b>Table 7-4. File Lock Types</b></p><table cellspacing="0" border="0" cellpadding="7" width="542"><tr><td width="32%" valign="top"><p><b><font size="2">Type</font></b></p></td><td width="68%" valign="top"><p><b><font size="2">Description</font></b></p></td></tr><tr><td width="32%" valign="top"><p><font size="2">'r'</font></p></td><td width="68%" valign="top"><p><font size="2">Read lock</font></p></td></tr><tr><td width="32%" valign="top"><p><font size="2">'w'</font></p></td><td width="68%" valign="top"><p><font size="2">Write lock</font></p></td></tr><tr><td width="32%" valign="top"><p><font size="2">'x'</font></p></td><td width="68%" valign="top"><p><font size="2">Exclusive lock</font></p></td></tr><tr><td width="32%" valign="top"><p><font size="2">'k'</font></p></td><td width="68%" valign="top"><p><font size="2">Keep lock</font></p></td></tr></table><p><font size="2">Functions <b>d_recfree</b>, <b>d_setfree</b>, and<b>d_keyfree</b> free read locks or exclusive locks on theirrespective record, set, or key field types for their database.Function <b>d_freeall</b> will free all read-locked files acrossall databases.</font></p><p>The current lock status of a record, set, or key type can befound by calling functions <b>d_reclstat</b>, <b>d_setlstat</b>, or<b>d_keylstat</b>.</p><p>Function <b>d_timeout</b> is used to inform the lock manager ofthe number of seconds that lock requests from this process are towait on the queue before being denied.</p><h3><a name="Read" id="Read"></a>7.3.2 Read Locks</h3><p><font size="2">A lock type 'r' passed to a locking functionspecifies that the files are to be read-locked. A read lock on afile prevents other processes from placing a write or exclusivelock on that file. Other processes are allowed to read-lock thefile. Thus, when a file is read-locked, other processes are allowedto read the file but are prevented from updating thefile.</font></p><p>Functions that only read from the database but cannot be safelyexecuted concurrently with updates require that the files involvedbe read-locked. In addition, the key access functions and setnavigation functions require that the files be read-locked. Therecord access functions listed in Table 7-5 can be executedconcurrently with updates and, therefore, do not require that thedata file be locked. If the record being read happens to have beendeleted, status code S_DELETED will be returned by thefunction.</p><blockquote><b><i>Note:</i></b> Using these functions without alock will retrieve data from your local cache without ensuring thatit is the most up-to-date data. To ensure synchronization of cachepages, use a read lock.</blockquote><p align="center"><b><font size="2">Table 7-5. Read Functions thatDo Not Need a Lock</font></b></p><table cellspacing="0" border="0" cellpadding="7" width="542"><tr><td width="46%" valign="top"><p><b><font size="2">Function</font></b></p></td><td width="54%" valign="top"><p><b><font size="2">Definition</font></b></p></td></tr><tr><td width="46%" valign="top"><p><font size="2">d_cmtype(<i>SET</i>, <i>&amp;type, task,dbn</i>)</font></p></td><td width="54%" valign="top"><p><font size="2">Get record type of current member</font></p></td></tr><tr><td width="46%" valign="top"><p><font size="2">d_cotype(<i>SET</i>, <i>&amp;type</i>, <i>task,dbn</i>)</font></p></td><td width="54%" valign="top"><p><font size="2">Get record type of current owner</font></p></td></tr><tr><td width="46%" valign="top"><p><font size="2">d_crread(<i>FIELD</i>, <i>&amp;val</i>, <i>task,dbn</i>)</font></p></td><td width="54%" valign="top"><p><font size="2">Read field from current record</font></p></td></tr><tr><td width="46%" valign="top"><p><font size="2">d_csmread(<i>SET</i>, <i>FIELD</i>,<i>&amp;val</i>, <i>task, dbn</i>)</font></p></td><td width="54%" valign="top"><p><font size="2">Read field from current member</font></p></td></tr><tr><td width="46%" valign="top"><p><font size="2">d_csoread(<i>SET</i>, <i>FIELD</i>,<i>&amp;val</i>, <i>task, dbn</i>)</font></p></td><td width="54%" valign="top"><p><font size="2">Read field from current owner</font></p></td></tr><tr><td width="46%" valign="top"><p><font size="2">d_members(<i>SET</i>, <i>&amp;count</i>, <i>task,dbn</i>)</font></p></td><td width="54%" valign="top"><p><font size="2">Get count of set members</font></p></td></tr><tr><td width="46%" valign="top"><p><font size="2">d_recfrst(<i>REC</i>, <i>task,dbn</i>)</font></p></td><td width="54%" valign="top"><p><font size="2">Position to first occurrence of recordtype</font></p></td></tr><tr><td width="46%" valign="top"><p><font size="2">d_reclast(<i>REC</i>, <i>task,dbn</i>)</font></p></td><td width="54%" valign="top"><p><font size="2">Position to last occurrence of recordtype</font></p></td></tr><tr><td width="46%" valign="top"><p><font size="2">d_recnext(<i>task, dbn</i>)</font></p></td><td width="54%" valign="top"><p><font size="2">Position to next occurrence of record

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?