Debian Codegraph @

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