intro.html   [plain text]


<!--$Id: intro.so,v 10.26 2006/11/13 18:05:04 bostic Exp $-->
<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Introduction to the transaction subsystem</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
</head>
<body bgcolor=white>
<a name="2"><!--meow--></a>
<table width="100%"><tr valign=top>
<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Transaction Subsystem</dl></b></td>
<td align=right><a href="../mp/config.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../txn/config.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p align=center><b>Introduction to the transaction subsystem</b></p>
<p>The Transaction subsystem makes operations atomic, consistent, isolated,
and durable in the face of system and application failures.  The subsystem
requires that the data be properly logged and locked in order to attain
these properties.  Berkeley DB contains all the components necessary to
transaction-protect the Berkeley DB access methods, and other forms of data may
be protected if they are logged and locked appropriately.</p>
<p>The Transaction subsystem is created, initialized, and opened by calls to
<a href="../../api_c/env_open.html">DB_ENV-&gt;open</a> with the <a href="../../api_c/env_open.html#DB_INIT_TXN">DB_INIT_TXN</a> flag specified.  Note
that enabling transactions automatically enables logging, but does not
enable locking because a single thread of control that needed atomicity
and recoverability would not require it.</p>
<p>The <a href="../../api_c/txn_begin.html">DB_ENV-&gt;txn_begin</a> function starts a transaction, returning an opaque
handle to a transaction.  If the parent parameter to <a href="../../api_c/txn_begin.html">DB_ENV-&gt;txn_begin</a> is
non-NULL, the new transaction is a child of the designated parent
transaction.</p>
<p>The <a href="../../api_c/txn_abort.html">DB_TXN-&gt;abort</a> function ends the designated transaction and causes
all updates performed by the transaction to be undone.  The end result is
that the database is left in a state identical to the state that existed
prior to the <a href="../../api_c/txn_begin.html">DB_ENV-&gt;txn_begin</a>.  If the aborting transaction has any child
transactions associated with it (even ones that have already been
committed), they are also aborted.  Any transactions that are unresolved
(neither committed nor aborted) when the application or system fails
are aborted during recovery.</p>
<p>The <a href="../../api_c/txn_commit.html">DB_TXN-&gt;commit</a> function ends the designated transaction and makes
all the updates performed by the transaction permanent, even in the face
of application or system failure.  If this is a parent transaction
committing, all child transactions that individually committed or
had not been resolved are also committed.</p>
<p>Transactions are identified by 32-bit unsigned integers.  The ID
associated with any transaction can be obtained using the <a href="../../api_c/txn_id.html">DB_TXN-&gt;id</a>
function.  If an application is maintaining information outside of Berkeley DB
it wants to transaction-protect, it should use this transaction ID as
the locking ID.</p>
<p>The <a href="../../api_c/txn_checkpoint.html">DB_ENV-&gt;txn_checkpoint</a> function causes a transaction checkpoint.  A
checkpoint is performed using to a specific log sequence number (LSN),
referred to as the checkpoint LSN.  When a checkpoint completes
successfully, it means that all data buffers whose updates are described
by LSNs less than the checkpoint LSN have been written to disk.  This, in
turn, means that the log records less than the checkpoint LSN are no
longer necessary for normal recovery (although they would be required for
catastrophic recovery if the database files were lost), and all log files
containing only records prior to the checkpoint LSN may be safely archived
and removed.</p>
<p>The time required to run normal recovery is proportional to the amount
of work done between checkpoints.  If a large number of modifications
happen between checkpoints, many updates recorded in the log may
not have been written to disk when failure occurred, and recovery may
take longer to run.  Generally, if the interval between checkpoints is
short, data may be being written to disk more frequently, but the
recovery time will be shorter.  Often, the checkpoint interval is tuned
for each specific application.</p>
<p>The <a href="../../api_c/txn_stat.html">DB_ENV-&gt;txn_stat</a> method returns information about the status of the
transaction subsystem.  It is the programmatic interface used by the
<a href="../../utility/db_stat.html">db_stat</a> utility.</p>
<p>The transaction system is closed by a call to <a href="../../api_c/env_close.html">DB_ENV-&gt;close</a>.</p>
<p>Finally, the entire transaction system may be removed using the
<a href="../../api_c/env_remove.html">DB_ENV-&gt;remove</a> method.</p>
<!--$Id: m4.methods,v 1.6 2005/03/16 21:26:51 bostic Exp $-->
<table border=1 align=center>
<tr><th>Transaction Subsystem and Related Methods</th><th>Description</th></tr>
<!--DbEnv::txn_checkpoint--><tr><td><a href="../../api_c/txn_checkpoint.html">DB_ENV-&gt;txn_checkpoint</a></td><td>Checkpoint the transaction subsystem</td></tr>
<!--DbEnv::txn_recover--><tr><td><a href="../../api_c/txn_recover.html">DB_ENV-&gt;txn_recover</a></td><td>Distributed transaction recovery</td></tr>
<!--DbEnv::txn_stat--><tr><td><a href="../../api_c/txn_stat.html">DB_ENV-&gt;txn_stat</a></td><td>Return transaction subsystem statistics</td></tr>
<tr><th>Transaction Subsystem Configuration</th><th><br></th></tr>
<!--DbEnv::set_timeout--><tr><td><a href="../../api_c/env_set_timeout.html">DB_ENV-&gt;set_timeout</a></td><td>Set lock and transaction timeout</td></tr>
<!--DbEnv::set_tx_max--><tr><td><a href="../../api_c/env_set_tx_max.html">DB_ENV-&gt;set_tx_max</a></td><td>Set maximum number of transactions</td></tr>
<!--DbEnv::set_tx_timestamp--><tr><td><a href="../../api_c/env_set_tx_timestamp.html">DB_ENV-&gt;set_tx_timestamp</a></td><td>Set recovery timestamp</td></tr>
<tr><th>Transaction Operations</th><th><br></th></tr>
<!--DbEnv::txn_begin--><tr><td><a href="../../api_c/txn_begin.html">DB_ENV-&gt;txn_begin</a></td><td>Begin a transaction</td></tr>
<!--DbTxn::-->
<!--DbTxn::abort--><tr><td><a href="../../api_c/txn_abort.html">DB_TXN-&gt;abort</a></td><td>Abort a transaction</td></tr>
<!--DbTxn::commit--><tr><td><a href="../../api_c/txn_commit.html">DB_TXN-&gt;commit</a></td><td>Commit a transaction</td></tr>
<!--DbTxn::discard--><tr><td><a href="../../api_c/txn_discard.html">DB_TXN-&gt;discard</a></td><td>Discard a prepared but not resolved transaction handle</td></tr>
<!--DbTxn::id--><tr><td><a href="../../api_c/txn_id.html">DB_TXN-&gt;id</a></td><td>Return a transaction's ID</td></tr>
<!--DbTxn::prepare--><tr><td><a href="../../api_c/txn_prepare.html">DB_TXN-&gt;prepare</a></td><td>Prepare a transaction for commit</td></tr>
<!--DbTxn::set_name--><tr><td><a href="../../api_c/txn_set_name.html">DB_TXN-&gt;set_name</a></td><td>Associate a string with a transaction</td></tr>
<!--DbTxn::set_timeout--><tr><td><a href="../../api_c/txn_set_timeout.html">DB_TXN-&gt;set_timeout</a></td><td>Set transaction timeout</td></tr>
</table>
<table width="100%"><tr><td><br></td><td align=right><a href="../mp/config.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../txn/config.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
</body>
</html>