⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ug_ch6.htm

📁 db.* (pronounced dee-be star) is an advanced, high performance, small footprint embedded database fo
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org"><meta http-equiv="content-type" content="text/html; charset=us-ascii"><meta name="Generator" content="Microsoft Word 97"><title>db.* User's Guide Chapter 6</title></head><body><h1><a name="Transaction" id="Transaction"></a>Chapter 6<br>Transaction Processing</h1><h2><a name="Introduction" id="Introduction"></a>6.1Introduction</h2><p><font size="2">Transaction processing is used to maintain thelogical consistency of a database by allowing multiple, relatedupdates to be grouped together and then written to the database asa unit. For example, in the <b>tims</b> database the entry of abook into the library could involve the creation of up to fiverecords (<b>author</b>, <b>info</b>, <b>text</b>, <b>intersect</b>,<b>key_word</b>) and connections to five sets (<b>author_list</b>,<b>has_published</b>, <b>abstract</b>, <b>info_to_key</b>,<b>key_to_info</b>). If all of these changes were coded as atransaction and a failure occurred before the transaction ended,none of the changes would be in the database. Without transactionprocessing, the changes would be written to the database only asnecessary, and a failure would leave the database in aninconsistent state (for example, it could leave an <b>info</b>record that is not connected to an <b>author</b>record).</font></p><p>Transaction processing is required during multi-user operation(see Chapter 7, "Multi-User Database Control"). It is recommendedduring one-user or exclusive operation, but not required.</p><blockquote><b><i>Note:</i></b> Transactions are <i>not</i>intended for use when reading the database. Reading may occuroutside of transactions (with read locks if in shared mode). Atransaction should begin only when an application is fully ready toperform an update to the database. Fully ready, in this case, meansthat the application should not have to wait for any moreinformation from the user or otherwise during the update. Thetransaction should go from beginning to end without userinterruption.</blockquote><p><font size="2">Transaction logging is used to provide dataintegrity protection if a failure occurs while a transaction'schanges are actually being written to the database. The processwherein the changes are written to the database is called thetransaction commit. Failures that occur during a commit aredetected by the system, automatically initiating a recoveryoperation, which takes a copy of the changes stored on thetransaction log and completes the commit by writing those changesto the database. Transaction logging is the process of writing thechanges to the transaction log before doing the commit.</font></p><h2><a name="Environment" id="Environment"></a>6.2 OperationalEnvironment</h2><p><font size="2">Transaction processing affects the followingfiles:</font></p><blockquote style="MARGIN-RIGHT: 0px"><p><b>Control files:<br>db.star.taf<br><i>dbuserid</i> .log</b></p><p>Database files:<br>Data and key files defined in the DDL specification</p></blockquote><p>The file named <b>db.star.taf</b> is a database-familytransaction activity file (TAF). In it are stored the names of thelog files of all currently committing transactions. Log files aretypically named by adding the <b>.log</b> suffix to the DBUSERID,but not necessarily. The DBUSERID is set with the environmentvariable DBUSERID, or with the <b>d_dbuserid</b> function. Thedirectory containing the TAF file is determined from a<b>d_dbtaf</b> function call, the <b>db.star.ini</b> file, or theDBTAF environment variable. If none of the former define a path,then the current directory is used. The directory containing thelog file is determined from a <b>d_dblog</b> function call, the<b>db.star.ini</b> file, or the DBLOG environment variable. Thecurrent directory is used if no DBLOG value is found.</p><h2><a name="Functions" id="Functions"></a>6.3 TransactionProcessing Functions</h2><p><font size="2">Three functions are provided in<b><i>db.*</i></b> to support transaction processing. These arelisted in Table 6-1. Function <b>d_trbegin</b> is used to mark thebeginning of a transaction. All changes specified after the<b>d_trbegin</b> call are written to the database at the same time,when function <b>d_trend</b> is called to end the transaction. Ifany errors are detected, or if a requested lock is not availableafter <b>d_trbegin</b> has been called, function <b>d_trabort</b>can be called to abort the transaction. Function <b>d_trabort</b>will discard any changes that have been made since the beginning ofthe transaction, ensuring that the state of the database is thesame after <b>d_trabort</b> as it was before<b>d_trbegin</b>.</font></p><p align="center"><b>Table 6-1. Transaction ProcessingFunctions</b></p><table cellspacing="0" border="0" cellpadding="7" width="542"><tr><td width="35%" valign="top"><p><b><font size="2">d_trbegin</font>(trx_id, task)</b></p></td><td width="65%" valign="top"><p><font size="2">Begin transaction</font></p></td></tr><tr><td width="35%" valign="top"><p><b><font size="2">d_trend</font>(task)</b></p></td><td width="65%" valign="top"><p><font size="2">End transaction</font></p></td></tr><tr><td width="35%" valign="top"><p><b><font size="2">d_trabort</font>(task)</b></p></td><td width="65%" valign="top"><p><font size="2">Abort transaction</font></p></td></tr></table><font size="2"><br><br></font><p><font size="2">When a database is opened in shared access mode(see Chapter 7, "Multi-User Database Control"), all databaseupdates must be made from within a transaction (unless the filesbeing updated have been exclusively lockedsee section 7.3.4,"Exclusive Locks"). When using one-user or exclusive modes,transactions are not required, but are recommended for all databaseupdates.</font></p><p>Function <b>d_trbegin</b> is called to notify the<b><i>db.*</i></b> runtime of the start of a new transaction.Transactions cannot be nested within a task. If <b>d_trbegin</b> iscalled from within a task with active transaction, error codeS_TRACTIVE will be returned.</p><p>Function <b>d_trend</b> completes a transaction by committingall changes to the database.</p><p>Function <b>d_trabort</b> disregards all changes proposed sincethe <b>d_trbegin</b> call, and frees all unkept and non-exclusivefile locks.</p><h2><a name="Processing" id="Processing"></a>6.4 TransactionProcessing</h2><p><font size="2">A single transaction performs a great deal ofwork in order to guarantee the successful commit of an update. Itis necessary to guarantee that either <i>all</i> changes areapplied, or <i>no</i> changes are applied (all transaction updatesare considered an <i>atomic</i> operation). The following listshows the sequence of function calls to be made by an application,along with the underlying action performed by<b><i>db.*</i></b>.</font></p><p align="center"><b>Table 6-2. Actions of Transaction ProcessingFunctions</b></p><table cellspacing="0" border="0" cellpadding="7" width="542"><tr><td width="23%" valign="top"><p><b><font size="2">Function</font></b></p></td><td width="77%" valign="top"><p><b><font size="2">Action</font></b></p></td></tr><tr><td width="23%" valign="top"><p><b><font size="2">d_trbegin</font></b></p></td><td width="77%" valign="top"><p><font size="2">The log file, usually <b><i>dbuserid</i>.log</b>,is initialized.</font></p></td></tr><tr><td width="23%" valign="top"><p><b><font size="2">d_lock</font></b></p></td><td width="77%" valign="top"><p><font size="2">A group lock request is issued. All locks aregranted or denied as a unit. A group lock is recommended over a

⌨️ 快捷键说明

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