📄 ug_ch6.htm
字号:
series of <b>d_reclock</b> and <b>d_setlock</b> calls to avoiddeadlock.*</font></p></td></tr><tr><td width="23%" valign="top"><p><b><font size="2">transaction body</font></b></p></td><td width="77%" valign="top"><p><font size="2">Here, a series of function calls to modify thedatabase are made. If modified pages fill the cache (called atransaction overflow), then extra cache space is created by writingmodified pages to the log file.</font></p></td></tr><tr><td width="23%" valign="top"><p><b><font size="2">d_trend</font></b></p></td><td width="77%" valign="top"><p><font size="2">During this call, the commit is made to thedatabase. At any point after the <b>d_trbegin</b> and before the<b>d_trend</b>, updates can be thrown away and locks released byissuing a <b>d_trabort</b> call. During a <b>d_trend</b>, thefollowing sequence occurs:</font></p><p>1. Modified database pages are written to the transaction logfile<br>(if transaction logging is enabled).<br>2. Lock manager is informed of the commit.*<br>3. The name of the log file is added to the TAF.<br>4. Changed pages are written to the database from cache. If anoverflow occurred earlier, then changed pages contained only in thelog file are read from it and written to the database.<br>5. The log file name is deleted from the TAF.<br>6. Lock manager is informed of the end of the transaction.*<br>7. All unkept and non-exclusive file locks are freed.</p></td></tr></table><font size="1"><br><br></font><blockquote style="MARGIN-RIGHT: 0px"><blockquote style="MARGIN-RIGHT: 0px"><p><font size="1">* This step occurs in a multi-user environmentonly.</font></p></blockquote></blockquote><p><font size="2">One log file is maintained for each user. Thisfile is used within a transaction for storing modified databasepages after the page buffers (cache) have been filled. Thus, thereis effectively no limit to the number of changes that can be madewithin a transaction. When the transaction ends, all modified pagesare first written to this file (whether or not an overflowoccurred). The database is then updated.</font></p><p>If a transaction is aborted, the modified pages in the pagebuffers are cleared.</p><p>An indexing technique has been developed to provide fast accessto the changed database pages that are stored in the log file aftera cache overflow has occurred. It utilizes a separate cache for themanagement of all database pages on the log file. The size of thisindex cache (that is, the number of page buffers) is specified asan argument to function <b>d_setpages</b> as follows:</p><pre><font color="#0000FF">d_setpages(dbpgs, ixpgs, task)</font></pre><p><font size="2">where <i>dbpgs</i> is an integer specifying thenumber of pages to be used for the standard database cache and<i>ixpgs</i> is an integer specifying the number of pages to beused for the overflow index cache. Both arguments are required onany call to <b>d_setpages</b>.</font></p><p>If your application is prone to large transaction overflows, youwill want a fairly large index cache (for example, 17 pages).Usually, however, a small number of index pages is all that isnecessary (for example, five pages, the default).</p><h2><a name="Recovery" id="Recovery"></a>6.5 Database Recovery</h2><p><font size="2">If a program crashes while a transaction isactive (after the <b>d_trbegin</b> but before a transaction end or<b>d_trend</b> has been issued), the database is guaranteed to beconsistent since it has not been written to. Only the changes madesince the beginning of the transaction are lost. If the programfails while the modified pages are being written to the log file(step 1 in section 6.4, above), the same situation exists. However,after the changes have been written to the log file, if the programfails while the database is being updated, recovery is possible. Ifthe program fails while committing the database from the log file,recovery is required.</font></p><h3><a name="External" id="External"></a>6.5.1 ExternalRecovery</h3><p><font size="2">In a system with only one active user (one-usermode, or multi-user mode with only one active user), recovery isfacilitated by the TAF. If this one user crashes after the log filename has been written to the TAF (step 3 in section 6.4, above),but before it has been removed (step 5), then the assumption ismade that the database needs recovering. The TAF is checked thenext time a database is opened. If one or more log file names arepresent in the TAF, they are all recovered by the first applicationto use this TAF during the <b>d_open</b> call.</font></p><h3><a name="Automatic" id="Automatic"></a>6.5.2 AutomaticRecovery</h3><p><font size="2">In multi-user shared mode, automatic recovery isaccomplished through cooperation between the transaction processingfunctions and the lock manager. The lock manager, which runs as anindependent process, is given the name of the log file when theupdate is initiated (referred to as the transaction commit point,step 2 in section 6.4, above) and is notified when the update iscomplete (step 6). The recovery automatically occurs when the lockmanager determines that a process performing a transaction commithas abnormally terminated. When failed processes that were notdoing a transaction commit are detected by the lock manager, thelock manager simply releases the locks held by the failedprocess.</font></p><p>The recovery will occur automatically when the lock managerreceives an open or lock request from another active process usingthe same TAF. The lock manager will transfer responsibility for thecompletion of the failed transaction to the process requesting theopen or lock. The read locks held by the failed process are freed,but write locks are held until the transaction has recovered.</p><p>Upon successful completion of the commit, the lock manager isinformed and the log file name is removed from the TAF. If both thecommitting process and the lock manager fail, all<b><i>db.*</i></b> processes on the system should be shut down.When the lock manager is restarted, the first database process toopen a database will check the TAF and perform an external recoveryon any listed transaction log files. The lock manager will delayall other database processes for the database families using thatTAF until the recovery is complete.</p><p>Both the log file and the TAF need to be accessible by alldatabase tasks. Moreover, all the log files for the users of eachTAF need to be in the same physical directory. The path and namesof these files can be established through use of functions<b>d_dblog</b> and <b>d_dbtaf</b>, or through environment variablesDBLOG and DBTAF, or with the <b>db.star.ini</b> file (see section6.2, above). All users of all databases need to have read/writeaccess to all database files. It is possible for an applicationusing one database to do recovery for a completely differentdatabase, but only when both databases are using the same TAF. Itis recommended that each database family use a different TAF.</p><p>Whenever <b><i>db.*</i></b> initiates a recovery operation, theerror reporter is called with the message "recovery about tooccur." The purpose of this function is simply to inform the userthat a recovery is about to take place. You will probably wish totailor the error reporting for your particular applicationrequirements through <b>d_set_dberr</b>. S_RECOVERY is probably oneof the return codes that you will want to "ignore" in your errorreporter.</p><h2><a name="Logging" id="Logging"></a>6.6 Archive Logging</h2><p><font size="2">A system-wide transaction archive log can besupported through user-defined functions, which can be calledautomatically by the <b><i>db.*</i></b> runtime system. In the rareevent that automatic recovery is not possible, the transactionidentifier for the incomplete transaction will be known by the lockmanager, and a user-initiated database restore can be performed.This would involve reloading the database from the last completebackup and using a utility to reapply the changes recorded on thearchive log, up to but not including the lasttransaction.</font></p><p><font size="2">Module <b>trlog.c</b> contains completeinformation, along with the skeletal function declarationsnecessary for implementing archive logging.</font></p><p><font size="2">The user-defined functions are needed because ofthe diversity of devices that could be used for storing the archivedata (for example, cartridge tapes, floppies, files, nine-tracktapes, write-once laser disks, etc.). Access to these devicescannot be accommodated through any standard techniques.</font></p><p><font size="2">However, the performance cost incurred bymaintaining an archive log, in addition to automatic transactionlogging, would almost always be much greater than the benefits ofthe additional level of recoverability. Keeping regular backups ofthe database files is the best method for protecting the databasebeyond the automatic recovery capability previouslydescribed.</font></p><p> <a href="UG_Ch7.htm">Next Page</a></p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -