Debian Codegraph @

docs/programmer_reference/transapp_faq.html

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <title>Transaction FAQ</title>
7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9 <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" />
10 <link rel="up" href="transapp.html" title="Chapter 11.  Berkeley DB Transactional Data Store Applications" />
11 <link rel="prev" href="transapp_throughput.html" title="Transaction throughput" />
12 <link rel="next" href="rep.html" title="Chapter 12.  Berkeley DB Replication" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">Transaction FAQ</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="transapp_throughput.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 11. 
26 Berkeley DB Transactional Data Store Applications
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="rep.html">Next</a></td>
29 </tr>
30 </table>
31 <hr />
32 </div>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
35 <div>
36 <div>
37 <h2 class="title" style="clear: both"><a id="transapp_faq"></a>Transaction FAQ</h2>
38 </div>
39 </div>
40 </div>
41 <div class="orderedlist">
42 <ol type="1">
43 <li>
44 <p>
45 <span class="bold"><strong>What should a transactional program do when an error occurs?</strong></span>
46 </p>
47 <p>
48 Any time an error occurs, such that a transactionally protected
49 set of operations cannot complete successfully, the transaction
50 must be aborted. While deadlock is by far the most common of
51 these errors, there are other possibilities; for example,
52 running out of disk space for the filesystem. In Berkeley DB
53 transactional applications, there are three classes of error
54 returns: "expected" errors, "unexpected but recoverable"
55 errors, and a single "unrecoverable" error. Expected errors
56 are errors like
57 <a class="link" href="program_errorret.html#program_errorret.DB_NOTFOUND">DB_NOTFOUND</a>,
58 which indicates that a searched-for key item is not present in
59 the database. Applications may want to explicitly test for and
60 handle this error, or, in the case where the absence of a key
61 implies the enclosing transaction should fail, simply call
62 <a href="../api_reference/C/txnabort.html" class="olink">DB_TXN-&gt;abort()</a>. Unexpected but recoverable errors are errors like
63 <a class="link" href="program_errorret.html#program_errorret.DB_LOCK_DEADLOCK">DB_LOCK_DEADLOCK</a>,
64 which indicates that an operation has been selected to resolve
65 a deadlock, or a system error such as EIO, which likely
66 indicates that the filesystem has no available disk space.
67 Applications must immediately call <a href="../api_reference/C/txnabort.html" class="olink">DB_TXN-&gt;abort()</a> when these
68 returns occur, as it is not possible to proceed otherwise. The
69 only unrecoverable error is
70 <a class="link" href="program_errorret.html#program_errorret.DB_RUNRECOVERY">DB_RUNRECOVERY</a>,
71 which indicates that the system must stop and recovery must be
72 run.
73 </p>
74 </li>
75 <li>
76 <p>
77 <span class="bold"><strong>How can hot backups work? Can't you get an
78 inconsistent picture of the database when you copy
79 it?</strong></span>
80 </p>
81 <p>
82 First, Berkeley DB is based on the technique of "write-ahead
83 logging", which means that before any change is made to a
84 database, a log record is written that describes the change.
85 Further, Berkeley DB guarantees that the log record that
86 describes the change will always be written to stable storage
87 (that is, disk) before the database page where the change was
88 made is written to stable storage. Because of this guarantee,
89 we know that any change made to a database will appear either
90 in just a log file, or both the database and a log file, but
91 never in just the database.
92 </p>
93 <p>
94 Second, you can always create a consistent and correct database
95 based on the log files and the databases from a database
96 environment. So, during a hot backup, we first make a copy of
97 the databases and then a copy of the log files. The tricky
98 part is that there may be pages in the database that are
99 related for which we won't get a consistent picture during this
100 copy. For example, let's say that we copy pages 1-4 of the
101 database, and then are swapped out. For whatever reason
102 (perhaps because we needed to flush pages from the cache, or
103 because of a checkpoint), the database pages 1 and 5 are
104 written. Then, the hot backup process is re-scheduled, and it
105 copies page 5. Obviously, we have an inconsistent database
106 snapshot, because we have a copy of page 1 from before it was
107 written by the other thread of control, and a copy of page 5
108 after it was written by the other thread. What makes this work
109 is the order of operations in a hot backup. Because of the
110 write-ahead logging guarantees, we know that any page written
111 to the database will first be referenced in the log. If we
112 copy the database first, then we can also know that any
113 inconsistency in the database will be described in the log
114 files, and so we know that we can fix everything up during
115 recovery.
116 </p>
117 </li>
118 <li>
119 <p>
120 <span class="bold"><strong>My application has <a class="link" href="program_errorret.html#program_errorret.DB_LOCK_DEADLOCK">DB_LOCK_DEADLOCK</a>
121 errors. Is the normal, and what should I do?</strong></span>
122 </p>
123 <p>
124 It is quite rare for a transactional application to be deadlock
125 free. All applications should be prepared to handle deadlock
126 returns, because even if the application is deadlock free when
127 deployed, future changes to the application or the Berkeley DB
128 implementation might introduce deadlocks.
129 </p>
130 <p>
131 Practices which reduce the chance of deadlock include:
132
133 </p>
134 <div class="itemizedlist">
135 <ul type="disc">
136 <li>Not using cursors which move backwards through the database (<a href="../api_reference/C/dbcget.html#dbcget_DB_PREV" class="olink">DB_PREV</a>),
137 as backward scanning cursors can deadlock with page splits;</li>
138 <li>Configuring <a href="../api_reference/C/dbset_flags.html#dbset_flags_DB_REVSPLITOFF" class="olink">DB_REVSPLITOFF</a> to turn off reverse splits in
139 applications which repeatedly delete and re-insert the same keys, to
140 minimize the number of page splits as keys are re-inserted;</li>
141 <li>Not configuring <a href="../api_reference/C/dbopen.html#dbopen_DB_READ_UNCOMMITTED" class="olink">DB_READ_UNCOMMITTED</a> as that flag requires write
142 transactions upgrade their locks when aborted, which can lead to deadlock.
143 Generally, <a href="../api_reference/C/dbcget.html#dbcget_DB_READ_COMMITTED" class="olink">DB_READ_COMMITTED</a> or non-transactional read operations
144 are less prone to deadlock than <a href="../api_reference/C/dbopen.html#dbopen_DB_READ_UNCOMMITTED" class="olink">DB_READ_UNCOMMITTED</a>.</li>
145 </ul>
146 </div>
147 <p>
148 </p>
149 </li>
150 <li>
151 <p>
152 <span class="bold"><strong>How can I move a database from one
153 transactional environment into another?</strong></span>
154 </p>
155 <p>
156 Because database pages contain references to log records,
157 databases cannot be simply moved into different database
158 environments. To move a database into a different environment,
159 dump and reload the database before moving it. If the database
160 is too large to dump and reload, the database may be prepared
161 in place using the <a href="../api_reference/C/envlsn_reset.html" class="olink">DB_ENV-&gt;lsn_reset()</a> method or the <span class="bold"><strong>-r</strong></span> argument to the <a href="../api_reference/C/db_load.html" class="olink">db_load</a> utility.
162 </p>
163 </li>
164 <li>
165 <p>
166 <span class="bold"><strong>I'm seeing the error "log_flush: LSN past
167 current end-of-log", what does that mean?</strong></span>
168 </p>
169 <p>
170 The most common cause of this error is that a system
171 administrator has removed all of the log files from a database
172 environment. You should shut down your database environment as
173 gracefully as possible, first flushing the database environment
174 cache to disk, if that's possible. Then, dump and reload your
175 databases. If the database is too large to dump and reload,
176 the database may be reset in place using the <a href="../api_reference/C/envlsn_reset.html" class="olink">DB_ENV-&gt;lsn_reset()</a>
177 method or the <span class="bold"><strong>-r</strong></span> argument to
178 the <a href="../api_reference/C/db_load.html" class="olink">db_load</a> utility. However, if you reset the database in place,
179 you should verify your databases before using them again. (It
180 is possible for the databases to be corrupted by running after
181 all of the log files have been removed, and the longer the
182 application runs, the worse it can get.)
183 </p>
184 </li>
185 </ol>
186 </div>
187 </div>
188 <div class="navfooter">
189 <hr />
190 <table width="100%" summary="Navigation footer">
191 <tr>
192 <td width="40%" align="left"><a accesskey="p" href="transapp_throughput.html">Prev</a> </td>
193 <td width="20%" align="center">
194 <a accesskey="u" href="transapp.html">Up</a>
195 </td>
196 <td width="40%" align="right"> <a accesskey="n" href="rep.html">Next</a></td>
197 </tr>
198 <tr>
199 <td width="40%" align="left" valign="top">Transaction throughput </td>
200 <td width="20%" align="center">
201 <a accesskey="h" href="index.html">Home</a>
202 </td>
203 <td width="40%" align="right" valign="top"> Chapter 12. 
204 Berkeley DB Replication
205 </td>
206 </tr>
207 </table>
208 </div>
209 </body>
210 </html>