summaryrefslogtreecommitdiff
path: root/db/docs/ref/transapp/atomicity.html
blob: 5bedba0788dac09a6b4bb00133ec6b6b9cc95127 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!--$Id: atomicity.so,v 10.3 2002/05/17 15:48:41 bostic Exp $-->
<!--Copyright 1997-2006 by Oracle Corporation-->
<!--All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Atomicity</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>
<table width="100%"><tr valign=top>
<td><h3><dl><dt>Berkeley DB Reference Guide:<dd>Berkeley DB Transactional Data Store Applications</dl></h3></td>
<td align=right><a href="../transapp/put.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../transapp/inc.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p>
<h3 align=center>Atomicity</h3>
<p>The second reason listed for using transactions was <i>atomicity</i>.
Atomicity means that multiple operations can be grouped into a single
logical entity, that is, other threads of control accessing the database
will either see all of the changes or none of the changes.  Atomicity
is important for applications wanting to update two related databases
(for example, a primary database and secondary index)  in a single
logical action.  Or, for an application wanting to update multiple
records in one database in a single logical action.</p>
<p>Any number of operations on any number of databases can be included in
a single transaction to ensure the atomicity of the operations.  There
is, however, a trade-off between the number of operations included in
a single transaction and both throughput and the possibility of
deadlock.  The reason for this is because transactions acquire locks
throughout their lifetime and do not release the locks until commit or
abort time.  So, the more operations included in a transaction, the more
likely it is that a transaction will block other operations and that
deadlock will occur.  However, each transaction commit requires a
synchronous disk I/O, so grouping multiple operations into a transaction
can increase overall throughput.  (There is one exception to this: the
<a href="../../api_c/env_set_flags.html#DB_TXN_WRITE_NOSYNC">DB_TXN_WRITE_NOSYNC</a> and <a href="../../api_c/env_set_flags.html#DB_TXN_NOSYNC">DB_TXN_NOSYNC</a> flags cause
transactions to exhibit the ACI (atomicity, consistency and isolation)
properties, but not D (durability); avoiding the write and/or
synchronous disk I/O on transaction commit greatly increases transaction
throughput for some applications.)</p>
<p>When applications do create complex transactions, they often avoid
having more than one complex transaction at a time because simple
operations like a single <a href="../../api_c/db_put.html">DB-&gt;put</a> are unlikely to deadlock with
each other or the complex transaction; while multiple complex
transactions are likely to deadlock with each other because they will
both acquire many locks over their lifetime.  Alternatively, complex
transactions can be broken up into smaller sets of operations, and each
of those sets may be encapsulated in a nested transaction.  Because
nested transactions may be individually aborted and retried without
causing the entire transaction to be aborted, this allows complex
transactions to proceed even in the face of heavy contention, repeatedly
trying the suboperations until they succeed.</p>
<p>It is also helpful to order operations within a transaction; that is,
access the databases and items within the databases in the same order,
to the extent possible, in all transactions.  Accessing databases and
items in different orders greatly increases the likelihood of operations
being blocked and failing due to deadlocks.</p>
<table width="100%"><tr><td><br></td><td align=right><a href="../transapp/put.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../transapp/inc.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1>Copyright (c) 1996-2006 Oracle Corporation - All rights reserved.</font>
</body>
</html>