Debian Codegraph @

docs/programmer_reference/transapp_reclimit.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>Berkeley DB recoverability</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_filesys.html" title="Recovery and filesystem operations" />
12 <link rel="next" href="transapp_tune.html" title="Transaction tuning" />
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">Berkeley DB recoverability</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="transapp_filesys.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="transapp_tune.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_reclimit"></a>Berkeley DB recoverability</h2>
38 </div>
39 </div>
40 </div>
41 <p>
42 Berkeley DB recovery is based on write-ahead logging. This means
43 that when a change is made to a database page, a description of the
44 change is written into a log file. This description in the log
45 file is guaranteed to be written to stable storage before the
46 database pages that were changed are written to stable storage.
47 This is the fundamental feature of the logging system that makes
48 durability and rollback work.
49 </p>
50 <p>
51 If the application or system crashes, the log is reviewed during
52 recovery. Any database changes described in the log that were part
53 of committed transactions and that were never written to the actual
54 database itself are written to the database as part of recovery.
55 Any database changes described in the log that were never committed
56 and that were written to the actual database itself are backed-out
57 of the database as part of recovery. This design allows the
58 database to be written lazily, and only blocks from the log file
59 have to be forced to disk as part of transaction commit.
60 </p>
61 <p>
62 There are two interfaces that are a concern when considering
63 Berkeley DB recoverability:
64 </p>
65 <div class="orderedlist">
66 <ol type="1">
67 <li>
68 The interface between Berkeley DB and the operating
69 system/filesystem.
70 </li>
71 <li>
72 The interface between the operating system/filesystem and the
73 underlying stable storage hardware.
74 </li>
75 </ol>
76 </div>
77 <p>
78 Berkeley DB uses the operating system interfaces and its underlying
79 filesystem when writing its files. This means that Berkeley DB can
80 fail if the underlying filesystem fails in some unrecoverable way.
81 Otherwise, the interface requirements here are simple: The system
82 call that Berkeley DB uses to flush data to disk (normally fsync or
83 fdatasync), must guarantee that all the information necessary for a
84 file's recoverability has been written to stable storage before it
85 returns to Berkeley DB, and that no possible application or system
86 crash can cause that file to be unrecoverable.
87 </p>
88 <p>
89 In addition, Berkeley DB implicitly uses the interface between the
90 operating system and the underlying hardware. The interface
91 requirements here are not as simple.
92 </p>
93 <p>
94 First, it is necessary to consider the underlying page size of the
95 Berkeley DB databases. The Berkeley DB library performs all
96 database writes using the page size specified by the application,
97 and Berkeley DB assumes pages are written atomically. This means
98 that if the operating system performs filesystem I/O in blocks of
99 different sizes than the database page size, it may increase the
100 possibility for database corruption. For example, assume that
101 Berkeley DB is writing 32KB pages for a database, and the operating
102 system does filesystem I/O in 16KB blocks. If the operating system
103 writes the first 16KB of the database page successfully, but
104 crashes before being able to write the second 16KB of the database,
105 the database has been corrupted and this corruption may or may not
106 be detected during recovery. For this reason, it may be important
107 to select database page sizes that will be written as single block
108 transfers by the underlying operating system. If you do not select
109 a page size that the underlying operating system will write as a
110 single block, you may want to configure the database to use
111 checksums (see the <a href="../api_reference/C/dbset_flags.html" class="olink">DB-&gt;set_flags()</a> flag for more information). By
112 configuring checksums, you guarantee this kind of corruption will
113 be detected at the expense of the CPU required to generate the
114 checksums. When such an error is detected, the only course of
115 recovery is to perform catastrophic recovery to restore the
116 database.
117 </p>
118 <p>
119 Second, if you are copying database files (either as part of doing
120 a hot backup or creation of a hot failover area), there is an
121 additional question related to the page size of the Berkeley DB
122 databases. You must copy databases atomically, in units of the
123 database page size. In other words, the reads made by the copy
124 program must not be interleaved with writes by other threads of
125 control, and the copy program must read the databases in multiples
126 of the underlying database page size. On Unix systems, this is not
127 a problem, as these operating systems already make this guarantee
128 and system utilities normally read in power-of-2 sized chunks,
129 which are larger than the largest possible Berkeley DB database
130 page size. Other operating systems, particularly those based on
131 Linux and Windows, do not provide this guarantee and hot backups may
132 not be performed on these systems by reading data from the file
133 system. The <a href="../api_reference/C/db_hotbackup.html" class="olink">db_hotbackup</a> utility should be used on these
134 systems.
135 </p>
136 <p>
137 An additional problem we have seen in this area was in some
138 releases of Solaris where the cp utility was implemented using the
139 mmap system call rather than the read system call. Because the
140 Solaris' mmap system call did not make the same guarantee of read
141 atomicity as the read system call, using the cp utility could
142 create corrupted copies of the databases. Another problem we have
143 seen is implementations of the tar utility doing 10KB block reads
144 by default, and even when an output block size was specified to
145 that utility, not reading from the underlying databases in
146 multiples of the block size. Using the dd utility instead of the
147 cp or tar utilities (and specifying an appropriate block size),
148 fixes these problems. If you plan to use a system utility to copy
149 database files, you may want to use a system call trace utility
150 (for example, ktrace or truss) to check for an I/O size smaller
151 than or not a multiple of the database page size and system calls
152 other than read.
153 </p>
154 <p>
155 Third, it is necessary to consider the behavior of the system's
156 underlying stable storage hardware. For example, consider a SCSI
157 controller that has been configured to cache data and return to the
158 operating system that the data has been written to stable storage,
159 when, in fact, it has only been written into the controller RAM
160 cache. If power is lost before the controller is able to flush its
161 cache to disk, and the controller cache is not stable (that is, the
162 writes will not be flushed to disk when power returns), the writes
163 will be lost. If the writes include database blocks, there is no
164 loss because recovery will correctly update the database. If the
165 writes include log file blocks, it is possible that transactions
166 that were already committed may not appear in the recovered
167 database, although the recovered database will be coherent after a
168 crash.
169 </p>
170 <p>
171 If the underlying hardware can fail in any way so that only part of
172 the block was written, the failure conditions are the same as those
173 described previously for an operating system failure that writes
174 only part of a logical database block. In such cases, configuring
175 the database for checksums will ensure the corruption is
176 detected.
177 </p>
178 <p>
179 For these reasons, it may be important to select hardware that does
180 not do partial writes and does not cache data writes (or does not
181 return that the data has been written to stable storage until it
182 has either been written to stable storage or the actual writing of
183 all of the data is guaranteed, barring catastrophic hardware
184 failure — that is, your disk drive exploding).
185 </p>
186 <p>
187 If the disk drive on which you are storing your databases explodes,
188 you can perform normal Berkeley DB catastrophic recovery, because
189 it requires only a snapshot of your databases plus the log files
190 you have archived since those snapshots were taken. In this case,
191 you should lose no database changes at all.
192 </p>
193 <p>
194 If the disk drive on which you are storing your log files explodes,
195 you can also perform catastrophic recovery, but you will lose any
196 database changes made as part of transactions committed since your
197 last archival of the log files. Alternatively, if your database
198 environment and databases are still available after you lose the
199 log file disk, you should be able to dump your databases. However,
200 you may see an inconsistent snapshot of your data after doing the
201 dump, because changes that were part of transactions that were not
202 yet committed may appear in the database dump. Depending on the
203 value of the data, a reasonable alternative may be to perform both
204 the database dump and the catastrophic recovery and then compare
205 the databases created by the two methods.
206 </p>
207 <p>
208 Regardless, for these reasons, storing your databases and log files
209 on different disks should be considered a safety measure as well as
210 a performance enhancement.
211 </p>
212 <p>
213 Finally, you should be aware that Berkeley DB does not protect
214 against all cases of stable storage hardware failure, nor does it
215 protect against simple hardware misbehavior (for example, a disk
216 controller writing incorrect data to the disk). However,
217 configuring the database for checksums will ensure that any such
218 corruption is detected.
219 </p>
220 </div>
221 <div class="navfooter">
222 <hr />
223 <table width="100%" summary="Navigation footer">
224 <tr>
225 <td width="40%" align="left"><a accesskey="p" href="transapp_filesys.html">Prev</a> </td>
226 <td width="20%" align="center">
227 <a accesskey="u" href="transapp.html">Up</a>
228 </td>
229 <td width="40%" align="right"> <a accesskey="n" href="transapp_tune.html">Next</a></td>
230 </tr>
231 <tr>
232 <td width="40%" align="left" valign="top">Recovery and filesystem operations </td>
233 <td width="20%" align="center">
234 <a accesskey="h" href="index.html">Home</a>
235 </td>
236 <td width="40%" align="right" valign="top"> Transaction tuning</td>
237 </tr>
238 </table>
239 </div>
240 </body>
241 </html>