Debian Codegraph @

docs/gsg_txn/JAVA/logconfig.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>Configuring the Logging Subsystem</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="logfileremoval.html" title="Removing Log Files" />
12 <link rel="next" href="wrapup.html" title="Chapter 6. Summary and Examples" />
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">Configuring the Logging Subsystem</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="logfileremoval.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="wrapup.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="logconfig"></a>Configuring the Logging Subsystem</h2>
36 </div>
37 </div>
38 </div>
39 <div class="toc">
40 <dl>
41 <dt>
42 <span class="sect2">
43 <a href="logconfig.html#logfilesize">Setting the Log File Size</a>
44 </span>
45 </dt>
46 <dt>
47 <span class="sect2">
48 <a href="logconfig.html#logregionsize">Configuring the Logging Region Size</a>
49 </span>
50 </dt>
51 <dt>
52 <span class="sect2">
53 <a href="logconfig.html#inmemorylogging">Configuring In-Memory Logging</a>
54 </span>
55 </dt>
56 <dt>
57 <span class="sect2">
58 <a href="logconfig.html#logbuffer">Setting the In-Memory Log Buffer Size</a>
59 </span>
60 </dt>
61 </dl>
62 </div>
63 <p>
64 You can configure the following aspects of the logging
65 subsystem:
66 </p>
67 <div class="itemizedlist">
68 <ul type="disc">
69 <li>
70 <p>
71 Size of the log files.
72 </p>
73 </li>
74 <li>
75 <p>
76 Size of the logging subsystem's region.
77 See <a class="xref" href="logconfig.html#logregionsize" title="Configuring the Logging Region Size">Configuring the Logging Region Size</a>.
78 </p>
79 </li>
80 <li>
81 <p>
82 Maintain logs entirely in-memory.
83 See <a class="xref" href="logconfig.html#inmemorylogging" title="Configuring In-Memory Logging">Configuring In-Memory Logging</a>
84 for more information.
85 </p>
86 </li>
87 <li>
88 <p>
89 Size of the log buffer in memory.
90 See <a class="xref" href="logconfig.html#logbuffer" title="Setting the In-Memory Log Buffer Size">Setting the In-Memory Log Buffer Size</a>.
91 </p>
92 </li>
93 <li>
94 <p>
95 On-disk location of your log files. See
96 <a class="xref" href="enabletxn.html#splittingdata" title="Identifying Specific File Locations">Identifying Specific File Locations</a>.
97 </p>
98 </li>
99 </ul>
100 </div>
101 <div class="sect2" lang="en" xml:lang="en">
102 <div class="titlepage">
103 <div>
104 <div>
105 <h3 class="title"><a id="logfilesize"></a>Setting the Log File Size</h3>
106 </div>
107 </div>
108 </div>
109 <p>
110 Whenever a pre-defined amount of data is written to a
111 log file (10 MB by default), DB stops using the
112 current log file and starts writing to a new file.
113 You can change the maximum amount of data contained in each
114 log file by using the
115
116 <span>
117 <code class="methodname">EnvironmentConfig.setMaxLogFileSize()</code>
118 method.
119 </span>
120 Note that this method can be used at any time
121 during an application's lifetime.
122 </p>
123 <p>
124 Setting the log file size to something larger than its
125 default value is largely a matter of
126 convenience and a reflection of the application's
127 preference in backup media and frequency. However, if
128 you set the log file size too low relative to your
129 application's traffic patterns, you can cause
130 yourself trouble.
131 </p>
132 <p>
133 From a performance perspective, setting the log file
134 size to a low value can cause your active transactions to
135 pause their writing activities more frequently than would
136 occur with larger log file sizes. Whenever a
137 transaction completes the log buffer is flushed to
138 disk. Normally other transactions can continue to
139 write to the log buffer while this flush is in
140 progress. However, when one log file is being closed
141 and another created, all transactions must cease
142 writing to the log buffer until the switch over is
143 completed.
144 </p>
145 <p>
146 Beyond performance concerns, using smaller log files
147 can cause you to use more physical files on disk.
148 As a result, your application could run out
149 of log sequence numbers, depending on how busy your
150 application is.
151 </p>
152 <p>
153 Every log file is identified with a 10 digit number.
154 Moreover, the maximum number of log files that your application
155 is allowed to create in its lifetime is 2,000,000,000.
156 </p>
157 <p>
158 For example, if your application performs 6,000 transactions per
159 second for 24 hours a day, and you are logging 500 bytes of
160 data per transaction into 10 MB log files, then you
161 will run out of log files in around 221 years:
162 </p>
163 <pre class="programlisting"> (10 * 2^20 * 2000000000) / (6000 * 500 * 365 * 60 *60 * 24) = 221 </pre>
164 <p>
165 However, if you were writing 2000 bytes of data per
166 transaction, and using 1 MB log files, then the same
167 formula shows you running out of log files in 5 years time.
168 </p>
169 <p>
170 All of these time frames are quite long, to be sure,
171 but if you do run out of log files after, say, 5 years
172 of continuous operations, then you must reset your log
173 sequence numbers. To do so:
174 </p>
175 <div class="orderedlist">
176 <ol type="1">
177 <li>
178 <p>
179 Backup your databases as if to prepare for
180 catastrophic failure. See
181 <a class="xref" href="backuprestore.html" title="Backup Procedures">Backup Procedures</a>
182 for more information.
183 </p>
184 </li>
185 <li>
186 <p>
187 Reset the log file's sequence number using the
188 <span class="command"><strong>db_load</strong></span> utility's
189 <code class="literal">-r</code> option.
190 </p>
191 </li>
192 <li>
193 <p>
194 Remove all of the log files from your
195 environment. Note that this is the only
196 situation in which all of the log files are
197 removed from an environment; in all other
198 cases, at least a single log file is retained.
199 </p>
200 </li>
201 <li>
202 <p>
203 Restart your application.
204 </p>
205 </li>
206 </ol>
207 </div>
208 </div>
209 <div class="sect2" lang="en" xml:lang="en">
210 <div class="titlepage">
211 <div>
212 <div>
213 <h3 class="title"><a id="logregionsize"></a>Configuring the Logging Region Size</h3>
214 </div>
215 </div>
216 </div>
217 <p>
218 The logging subsystem's default region size is 60 KB. The
219 logging region is used to store filenames, and so you may
220 need to increase its size if a large number of files (that
221 is, if you have a very large number of databases) will
222 be opened and registered with DB's log manager.
223 </p>
224 <p>
225 You can set the size of your logging region by using the
226
227 <span>
228 <code class="methodname">EnvironmentConfig.setLogRegionSize()</code>
229 </span>
230 method. Note that this method can only be called before the
231 first environment handle for your application is opened.
232 </p>
233 </div>
234 <div class="sect2" lang="en" xml:lang="en">
235 <div class="titlepage">
236 <div>
237 <div>
238 <h3 class="title"><a id="inmemorylogging"></a>Configuring In-Memory Logging</h3>
239 </div>
240 </div>
241 </div>
242 <p>
243 It is possible to configure your logging subsystem such
244 that logs are maintained entirely in memory. When
245 you do this, you give up your transactional durability
246 guarantee. Without log files, you have no way to run
247 recovery so any system or software failures that you might
248 experience can corrupt your databases.
249 </p>
250 <p>
251 However, by giving up your durability guarantees, you can
252 greatly improve your application's throughput by avoiding
253 the disk I/O necessary to write logging information to
254 disk. In this case, you still retain your transactional
255 atomicity, consistency, and isolation guarantees.
256 </p>
257 <p>
258 To configure your logging subsystem to maintain your logs
259 entirely in-memory:
260 </p>
261 <div class="itemizedlist">
262 <ul type="disc">
263 <li>
264 <p>
265 Make sure your log buffer is capable of holding all
266 log information that can accumulate during the longest
267 running transaction. See <a class="xref" href="logconfig.html#logbuffer" title="Setting the In-Memory Log Buffer Size">Setting the In-Memory Log Buffer Size</a> for details.
268 </p>
269 </li>
270 <li>
271 <p>
272 Do not run normal recovery when you open your environment. In this configuration, there are no
273 log files available against which you can run recovery. As a result, if you specify recovery
274 when you open your environment, it is ignored.
275 </p>
276 </li>
277 <li>
278 <p>
279 Specify
280
281 <span>
282 <code class="literal">true</code>
283 to the
284 <code class="methodname">EnvironmentConfig.setLogInMemory()</code>
285 </span>
286 method. Note that you must specify this before
287 your application opens its first environment
288 handle.
289 </p>
290 </li>
291 </ul>
292 </div>
293 <p>
294 For example:
295 </p>
296 <pre class="programlisting">package db.txn;
297
298 import com.sleepycat.db.Database;
299 import com.sleepycat.db.DatabaseConfig;
300 import com.sleepycat.db.DatabaseEntry;
301 import com.sleepycat.db.DatabaseException;
302 import com.sleepycat.db.Environment;
303 import com.sleepycat.db.EnvironmentConfig;
304
305 import java.io.File;
306
307 ...
308
309 Database myDatabase = null;
310 Environment myEnv = null;
311 try {
312 EnvironmentConfig myEnvConfig = new EnvironmentConfig();
313 myEnvConfig.setInitializeCache(true);
314 myEnvConfig.setInitializeLocking(true);
315 myEnvConfig.setInitializeLogging(true);
316 myEnvConfig.setTransactional(true);
317
318 // Specify in-memory logging
319 myEnvConfig.setLogInMemory(true);
320
321 // Specify the in-memory log buffer size.
322 myEnvConfig.setLogBufferSize(10 * 1024 * 1024);
323
324 myEnv = new Environment(new File("/my/env/home"),
325 myEnvConfig);
326
327 // From here, you open databases, create transactions and
328 // perform database operations exactly as you would if you
329 // were logging to disk. This part is omitted for brevity. </pre>
330 </div>
331 <div class="sect2" lang="en" xml:lang="en">
332 <div class="titlepage">
333 <div>
334 <div>
335 <h3 class="title"><a id="logbuffer"></a>Setting the In-Memory Log Buffer Size</h3>
336 </div>
337 </div>
338 </div>
339 <p>
340 When your application is configured for on-disk logging
341 (the default behavior for transactional applications), log
342 information is stored in-memory until the storage space
343 fills up, or a transaction commit forces the log
344 information to be flushed to disk.
345 </p>
346 <p>
347 It is possible to increase the amount of memory available
348 to your file log buffer. Doing so improves throughput for
349 long-running transactions, or for transactions that produce
350 a large amount of data.
351 </p>
352 <p>
353 When you have your logging subsystem configured to maintain
354 your log entirely in memory (see
355 <a class="xref" href="logconfig.html#inmemorylogging" title="Configuring In-Memory Logging">Configuring In-Memory Logging</a>), it is very important
356 to configure your log buffer size because the log buffer
357 must be capable of holding all log information that can
358 accumulate during the longest running transaction.
359 You must make sure that the in-memory log buffer size is
360 large enough that no transaction will ever span the entire
361 buffer. You must also avoid a state where the in-memory
362 buffer is full and no space can be freed because a
363 transaction that started the first log "file" is still
364 active.
365 </p>
366 <p>
367 When your logging subsystem is configured for on-disk
368 logging, the default log buffer space is 32 KB. When
369 in-memory logging is configured, the default log buffer
370 space is 1 MB.
371 </p>
372 <p>
373 You can increase your log buffer space using the
374
375 <span>
376 <code class="methodname">EnvironmentConfig.setLogBufferSize()</code>
377 </span>
378 method. Note that this method can only be called before the
379 first environment handle for your application is opened.
380 </p>
381 </div>
382 </div>
383 <div class="navfooter">
384 <hr />
385 <table width="100%" summary="Navigation footer">
386 <tr>
387 <td width="40%" align="left"><a accesskey="p" href="logfileremoval.html">Prev</a> </td>
388 <td width="20%" align="center">
389 <a accesskey="u" href="filemanagement.html">Up</a>
390 </td>
391 <td width="40%" align="right"> <a accesskey="n" href="wrapup.html">Next</a></td>
392 </tr>
393 <tr>
394 <td width="40%" align="left" valign="top">Removing Log Files </td>
395 <td width="20%" align="center">
396 <a accesskey="h" href="index.html">Home</a>
397 </td>
398 <td width="40%" align="right" valign="top"> Chapter 6. Summary and Examples</td>
399 </tr>
400 </table>
401 </div>
402 </body>
403 </html>