Debian Codegraph @

docs/gsg_txn/JAVA/wrapup.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>Chapter 6. Summary and Examples</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="index.html" title="Getting Started with Berkeley DB Transaction Processing" />
11 <link rel="prev" href="logconfig.html" title="Configuring the Logging Subsystem" />
12 <link rel="next" href="txnexample_java.html" title="Base API Transaction Example" />
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">Chapter 6. Summary and Examples</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="logconfig.html">Prev</a> </td>
25 <th width="60%" align="center"> </th>
26 <td width="20%" align="right"> <a accesskey="n" href="txnexample_java.html">Next</a></td>
27 </tr>
28 </table>
29 <hr />
30 </div>
31 <div class="chapter" lang="en" xml:lang="en">
32 <div class="titlepage">
33 <div>
34 <div>
35 <h2 class="title"><a id="wrapup"></a>Chapter 6. Summary and Examples</h2>
36 </div>
37 </div>
38 </div>
39 <div class="toc">
40 <p>
41 <b>Table of Contents</b>
42 </p>
43 <dl>
44 <dt>
45 <span class="sect1">
46 <a href="wrapup.html#anatomy">Anatomy of a Transactional Application</a>
47 </span>
48 </dt>
49 <dt>
50 <span class="sect1">
51 <a href="txnexample_java.html">Base API Transaction Example</a>
52 </span>
53 </dt>
54 <dd>
55 <dl>
56 <dt>
57 <span class="sect2">
58 <a href="txnexample_java.html#txnguideexample">TxnGuide.java</a>
59 </span>
60 </dt>
61 <dt>
62 <span class="sect2">
63 <a href="txnexample_java.html#payloaddata">PayloadData.java</a>
64 </span>
65 </dt>
66 <dt>
67 <span class="sect2">
68 <a href="txnexample_java.html#dbwriter">DBWriter.java</a>
69 </span>
70 </dt>
71 </dl>
72 </dd>
73 <dt>
74 <span class="sect1">
75 <a href="txnexample_dpl.html">DPL Transaction Example</a>
76 </span>
77 </dt>
78 <dd>
79 <dl>
80 <dt>
81 <span class="sect2">
82 <a href="txnexample_dpl.html#txnguideexample_dpl">TxnGuide.java</a>
83 </span>
84 </dt>
85 <dt>
86 <span class="sect2">
87 <a href="txnexample_dpl.html#payloaddataentity">PayloadDataEntity.java</a>
88 </span>
89 </dt>
90 <dt>
91 <span class="sect2">
92 <a href="txnexample_dpl.html#storewriter">StoreWriter.java</a>
93 </span>
94 </dt>
95 </dl>
96 </dd>
97 <dt>
98 <span class="sect1">
99 <a href="inmem_txnexample_java.html">Base API In-Memory Transaction Example</a>
100 </span>
101 </dt>
102 </dl>
103 </div>
104 <p>
105 Throughout this manual we have presented the concepts and
106 mechanisms that you need to provide transactional protection for
107 your application. In this chapter, we summarize these
108 mechanisms, and we provide a complete example of a multi-threaded
109 transactional DB application.
110 </p>
111 <div class="sect1" lang="en" xml:lang="en">
112 <div class="titlepage">
113 <div>
114 <div>
115 <h2 class="title" style="clear: both"><a id="anatomy"></a>Anatomy of a Transactional Application</h2>
116 </div>
117 </div>
118 </div>
119 <p>
120 Transactional applications are characterized by performing the
121 following activities:
122 </p>
123 <div class="orderedlist">
124 <ol type="1">
125 <li>
126 <p>
127 Create your environment handle.
128 </p>
129 </li>
130 <li>
131 <p>
132 Open your environment, specifying that the following
133 subsystems be used:
134 </p>
135 <div class="itemizedlist">
136 <ul type="disc">
137 <li>
138 <p>
139 Transactional Subsystem (this also initializes the
140 logging subsystem).
141 </p>
142 </li>
143 <li>
144 <p>
145 Memory pool (the in-memory cache).
146 </p>
147 </li>
148 <li>
149 <p>
150 Logging subsystem.
151 </p>
152 </li>
153 <li>
154 <p>
155 Locking subsystem (if your application is multi-process or multi-threaded).
156 </p>
157 </li>
158 </ul>
159 </div>
160 <p>
161 It is also highly recommended that you run normal recovery
162 upon first environment open. Normal recovery examines only those logs required
163 to ensure your database files are consistent relative to the information found in your
164 log files.
165 </p>
166 </li>
167 <li>
168 <p>
169 Optionally spawn off any utility threads that you might need. Utility
170 threads can be used to run checkpoints periodically, or to
171 periodically run a deadlock detector if you do not want to
172 use DB's built-in deadlock detector.
173 </p>
174 </li>
175 <li>
176 <p>
177 If you are using the base API, open whatever database handles
178 that you need. Otherwise, open your store such that it is
179 configured for transactions.
180 </p>
181 </li>
182 <li>
183 <p>
184 Spawn off worker threads. How many of these you need and
185 how they split their DB workload is entirely up to your
186 application's requirements. However, any worker threads
187 that perform write operations will do the following:
188 </p>
189 <div class="orderedlist">
190 <ol type="a">
191 <li>
192 <p>
193 Begin a transaction.
194 </p>
195 </li>
196 <li>
197 <p>
198 Perform one or more read and write
199 operations.
200 </p>
201 </li>
202 <li>
203 <p>
204 Commit the transaction if all goes well.
205 </p>
206 </li>
207 <li>
208 <p>
209 Abort and retry the operation if a deadlock is
210 detected.
211 </p>
212 </li>
213 <li>
214 <p>
215 Abort the transaction for most other errors.
216 </p>
217 </li>
218 </ol>
219 </div>
220 </li>
221 <li>
222 <p>
223 On application shutdown:
224 </p>
225 <div class="orderedlist">
226 <ol type="a">
227 <li>
228 <p>
229 Make sure there are no opened cursors.
230 </p>
231 </li>
232 <li>
233 <p>
234 Make sure there are no active transactions. Either
235 abort or commit all transactions before shutting
236 down.
237 </p>
238 </li>
239 <li>
240 <p>
241 Close your databases or store.
242 </p>
243 </li>
244 <li>
245 <p>
246 Close your environment.
247 </p>
248 </li>
249 </ol>
250 </div>
251 </li>
252 </ol>
253 </div>
254 <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
255 <h3 class="title">Note</h3>
256 <p>
257 Robust DB applications should monitor their worker threads to
258 make sure they have not died unexpectedly. If a thread does
259 terminate abnormally, you must shutdown all your worker threads
260 and then run normal recovery (you will have to reopen your
261 environment to do this). This is the only way to clear any
262 resources (such as a lock or a mutex) that the abnormally
263 exiting worker thread might have been holding at the time that
264 it died.
265 </p>
266 <p>
267 Failure to perform this recovery can cause your
268 still-functioning worker threads to eventually block forever
269 while waiting for a lock that will never be released.
270 </p>
271 </div>
272 <p>
273 In addition to these activities, which are all entirely handled by
274 code within your application, there are some administrative
275 activities that you should perform:
276 </p>
277 <div class="itemizedlist">
278 <ul type="disc">
279 <li>
280 <p>
281 Periodically checkpoint your application. Checkpoints will
282 reduce the time to run recovery in the event that one is
283 required. See <a class="xref" href="filemanagement.html#checkpoints" title="Checkpoints">Checkpoints</a>
284 for details.
285 </p>
286 </li>
287 <li>
288 <p>
289 Periodically back up your database and log files. This is
290 required in order to fully obtain the durability guarantee
291 made by DB's transaction ACID support. See
292 <a class="xref" href="backuprestore.html" title="Backup Procedures">Backup Procedures</a>
293 for more information.
294 </p>
295 </li>
296 <li>
297 <p>
298 You may want to maintain a hot failover if 24x7 processing
299 with rapid restart in the face of a disk hit is important
300 to you. See <a class="xref" href="hotfailover.html" title="Using Hot Failovers">Using Hot Failovers</a>
301 for more information.
302 </p>
303 </li>
304 </ul>
305 </div>
306 </div>
307 </div>
308 <div class="navfooter">
309 <hr />
310 <table width="100%" summary="Navigation footer">
311 <tr>
312 <td width="40%" align="left"><a accesskey="p" href="logconfig.html">Prev</a> </td>
313 <td width="20%" align="center"> </td>
314 <td width="40%" align="right"> <a accesskey="n" href="txnexample_java.html">Next</a></td>
315 </tr>
316 <tr>
317 <td width="40%" align="left" valign="top">Configuring the Logging Subsystem </td>
318 <td width="20%" align="center">
319 <a accesskey="h" href="index.html">Home</a>
320 </td>
321 <td width="40%" align="right" valign="top"> Base API Transaction Example</td>
322 </tr>
323 </table>
324 </div>
325 </body>
326 </html>