Debian Codegraph @

docs/gsg_txn/JAVA/recovery.html

raw
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>Recovery Procedures</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="Getting Started with Berkeley DB Transaction Processing" />
10 <link rel="up" href="filemanagement.html" title="Chapter 5. Managing DB Files" />
11 <link rel="prev" href="backuprestore.html" title="Backup Procedures" />
12 <link rel="next" href="architectrecovery.html" title="Designing Your Application for Recovery" />
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">Recovery Procedures</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="backuprestore.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 5. Managing DB Files</th>
26 <td width="20%" align="right"> <a accesskey="n" href="architectrecovery.html">Next</a></td>
27 </tr>
28 </table>
29 <hr />
30 </div>
31 <div class="sect1" lang="en" xml:lang="en">
32 <div class="titlepage">
33 <div>
34 <div>
35 <h2 class="title" style="clear: both"><a id="recovery"></a>Recovery Procedures</h2>
36 </div>
37 </div>
38 </div>
39 <div class="toc">
40 <dl>
41 <dt>
42 <span class="sect2">
43 <a href="recovery.html#normalrecovery">Normal Recovery</a>
44 </span>
45 </dt>
46 <dt>
47 <span class="sect2">
48 <a href="recovery.html#catastrophicrecovery">Catastrophic Recovery</a>
49 </span>
50 </dt>
51 </dl>
52 </div>
53 <p>
54 DB supports two types of recovery:
55 </p>
56 <div class="itemizedlist">
57 <ul type="disc">
58 <li>
59 <p>
60 Normal recovery, which is run when your environment is
61 opened upon application startup, examines only those
62 log records needed to bring the databases to a consistent
63 state since the last checkpoint. Normal recovery
64 starts with any logs used by any transactions active at
65 the time of the last checkpoint, and examines all logs
66 from then to the current logs.
67 </p>
68 </li>
69 <li>
70 <p>
71 Catastrophic recovery, which is performed in the same
72 way that normal recovery is except that it examines
73 all available log files. You use catastrophic recovery
74 to restore your databases from a previously created backup.
75 </p>
76 </li>
77 </ul>
78 </div>
79 <p>
80 Of these two, normal recovery should be considered a routine
81 matter; in fact you should run normal
82 recovery whenever you start up your application.
83 </p>
84 <p>
85 Catastrophic recovery is run whenever you have lost or
86 corrupted your database files and you want to restore from a
87 backup. You also run catastrophic recovery when
88 you create a hot backup
89 (see <a class="xref" href="hotfailover.html" title="Using Hot Failovers">Using Hot Failovers</a> for more information).
90 </p>
91 <div class="sect2" lang="en" xml:lang="en">
92 <div class="titlepage">
93 <div>
94 <div>
95 <h3 class="title"><a id="normalrecovery"></a>Normal Recovery</h3>
96 </div>
97 </div>
98 </div>
99 <p>
100 Normal recovery examines the contents of your environment's
101 log files, and uses this information to ensure that your
102 database files are consistent relative to the
103 information contained in the log files.
104 </p>
105 <p>
106 Normal recovery also recreates your environment's region files.
107 This has the desired effect of clearing any unreleased locks
108 that your application may have held at the time of an
109 unclean application shutdown.
110 </p>
111 <p>
112 Normal recovery is run only against those log files created
113 since the time of your last checkpoint. For this reason,
114 your recovery time is dependent on how much data has been
115 written since the last checkpoint, and therefore on how
116 much log file information there is to examine. If you run
117 checkpoints infrequently, then normal recovery can
118 take a relatively long time.
119 </p>
120 <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
121 <h3 class="title">Note</h3>
122 <p>
123 You should run normal recovery every
124 time you perform application startup.
125 </p>
126 </div>
127 <p>
128 To run normal recovery:
129 </p>
130 <div class="itemizedlist">
131 <ul type="disc">
132 <li>
133 <p>
134 Make sure all your environment handles are closed.
135 </p>
136 </li>
137 <li>
138 <p>
139 Normal recovery <span class="emphasis"><em>must
140 be</em></span> single-threaded.
141 </p>
142 </li>
143 <li>
144 <p>
145 Specify <code class="literal">true</code> to
146 <code class="methodname">EnvironmentConfig.setRunRecovery()</code>
147 when you open your environment.
148 </p>
149 </li>
150 </ul>
151 </div>
152 <p>
153 You can also run recovery by pausing or shutting down your
154 application and using the <span class="command"><strong>db_recover</strong></span>
155 command line utility.
156 </p>
157 <p>
158 For example:
159 </p>
160 <pre class="programlisting">package db.txn;
161
162 import com.sleepycat.db.DatabaseException;
163 import com.sleepycat.db.Environment;
164 import com.sleepycat.db.EnvironmentConfig;
165
166 import java.io.File;
167 import java.io.FileNotFoundException;
168
169
170 ...
171
172
173 Environment myEnv = null;
174 try {
175 EnvironmentConfig myEnvConfig = new EnvironmentConfig();
176 myEnvConfig.setInitializeCache(true);
177 myEnvConfig.setInitializeLocking(true);
178 myEnvConfig.setInitializeLogging(true);
179 myEnvConfig.setTransactional(true);
180
181 // Run normal recovery
182 myEnvConfig.setRunRecovery(true);
183
184 myEnv = new Environment(new File("/my/env/home"),
185 myEnvConfig);
186
187 // All other operations are identical from here. Notice, however,
188 // that we have not created any other threads of control before
189 // recovery is complete. You want to run recovery for
190 // the first thread in your application that opens an environment,
191 // but not for any subsequent threads.
192
193 } catch (DatabaseException de) {
194 // Exception handling goes here
195 } catch (FileNotFoundException fnfe) {
196 // Exception handling goes here
197 }</pre>
198 </div>
199 <div class="sect2" lang="en" xml:lang="en">
200 <div class="titlepage">
201 <div>
202 <div>
203 <h3 class="title"><a id="catastrophicrecovery"></a>Catastrophic Recovery</h3>
204 </div>
205 </div>
206 </div>
207 <p>
208 Use catastrophic recovery when you are
209 recovering your databases from a previously created backup.
210 Note that to restore your databases from a previous backup, you
211 should copy the backup to a new environment directory, and
212 then run catastrophic recovery. Failure to do so can lead to
213 the internal database structures being out of sync with your log files.
214 </p>
215 <p>
216 Catastrophic recovery must be run single-threaded.
217 </p>
218 <p>
219 To run catastrophic recovery:
220 </p>
221 <div class="itemizedlist">
222 <ul type="disc">
223 <li>
224 <p>
225 Shutdown all database operations.
226 </p>
227 </li>
228 <li>
229 <p>
230 Restore the backup to an empty directory.
231 </p>
232 </li>
233 <li>
234 <p>
235 Specify <code class="literal">true</code> to
236 <code class="methodname">EnvironmentConfig.setRunRecoveryFatal()</code>
237 when you open your environment. This environment
238 open must be single-threaded.
239 </p>
240 </li>
241 </ul>
242 </div>
243 <p>
244 You can also run recovery by pausing or shutting down your
245 application and using the <span class="command"><strong>db_recover</strong></span>
246 command line utility with the the <code class="literal">-c</code> option.
247 </p>
248 <p>
249 Note that catastrophic recovery examines every available
250 log file — not just those log files created since the
251 last checkpoint as is the case for normal recovery. For this reason,
252 catastrophic recovery is likely to take longer than does
253 normal recovery.
254 </p>
255 <p>
256 For example:
257 </p>
258 <pre class="programlisting">package db.txn;
259
260 import com.sleepycat.db.DatabaseException;
261 import com.sleepycat.db.Environment;
262 import com.sleepycat.db.EnvironmentConfig;
263
264 import java.io.File;
265 import java.io.FileNotFoundException;
266
267
268 ...
269
270
271 Environment myEnv = null;
272 try {
273 EnvironmentConfig myEnvConfig = new EnvironmentConfig();
274 myEnvConfig.setInitializeCache(true);
275 myEnvConfig.setInitializeLocking(true);
276 myEnvConfig.setInitializeLogging(true);
277 myEnvConfig.setTransactional(true);
278
279 // Run catastrophic recovery
280 <strong class="userinput"><code>myEnvConfig.setRunFatalRecovery(true);</code></strong>
281
282 myEnv = new Environment(new File("/my/env/home"),
283 myEnvConfig);
284
285 } catch (DatabaseException de) {
286 // Exception handling goes here
287 } catch (FileNotFoundException fnfe) {
288 // Exception handling goes here
289 }</pre>
290 </div>
291 </div>
292 <div class="navfooter">
293 <hr />
294 <table width="100%" summary="Navigation footer">
295 <tr>
296 <td width="40%" align="left"><a accesskey="p" href="backuprestore.html">Prev</a> </td>
297 <td width="20%" align="center">
298 <a accesskey="u" href="filemanagement.html">Up</a>
299 </td>
300 <td width="40%" align="right"> <a accesskey="n" href="architectrecovery.html">Next</a></td>
301 </tr>
302 <tr>
303 <td width="40%" align="left" valign="top">Backup Procedures </td>
304 <td width="20%" align="center">
305 <a accesskey="h" href="index.html">Home</a>
306 </td>
307 <td width="40%" align="right" valign="top"> Designing Your Application for Recovery</td>
308 </tr>
309 </table>
310 </div>
311 </body>
312 </html>