Debian Codegraph @

docs/gsg_txn/CXX/maxtxns.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 Transaction 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="usingtxns.html" title="Chapter 3. Transaction Basics" />
11 <link rel="prev" href="txnindices.html" title="Secondary Indices with Transaction Applications" />
12 <link rel="next" href="txnconcurrency.html" title="Chapter 4. Concurrency" />
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 Transaction Subsystem</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="txnindices.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 3. Transaction Basics</th>
26 <td width="20%" align="right"> <a accesskey="n" href="txnconcurrency.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="maxtxns"></a>Configuring the Transaction Subsystem</h2>
36 </div>
37 </div>
38 </div>
39 <p>
40 Most of the configuration activities that you need to perform
41 for your transactional DB application will involve the
42 locking and logging subsystems. See
43 <a class="xref" href="txnconcurrency.html" title="Chapter 4. Concurrency">Concurrency</a>
44 and
45 <a class="xref" href="filemanagement.html" title="Chapter 5. Managing DB Files">Managing DB Files</a>
46 for details.
47 </p>
48 <p>
49 However, there are a couple of things that you can do to
50 configure your transaction subsystem directly. These things
51 are:
52 </p>
53 <div class="itemizedlist">
54 <ul type="disc">
55 <li>
56 <span>
57 <p>
58
59 <span>
60 Configure
61 </span>
62
63 the maximum number of simultaneous
64 transactions needed by your application.
65 In general, you should not need to do this unless you
66 use deeply nested transactions or you have many threads all
67 of which have active transactions. In addition, you may
68 need to configure a higher maximum number of transactions if you
69 are using snapshot isolation. See
70 <a class="xref" href="isolation.html#sisolation_maxtxn" title="Snapshot Isolation Transactional Requirements">Snapshot Isolation Transactional Requirements</a>
71 for details.
72 </p>
73 <p>
74 By default, your application can support 20 active
75 transactions.
76 </p>
77 <p>
78 You can set the maximum number of simultaneous
79 transactions supported by your application using
80 <span>
81 the
82
83 <code class="methodname">DbEnv::set_tx_max()</code>
84 method. Note that this method must be called
85 before the environment has been opened.
86 </span>
87
88 </p>
89 <p>
90 If your application has exceeded this maximum value,
91 then any attempt to begin a new transaction will fail.
92 </p>
93 <p>
94 This value can also be set using the
95 <code class="literal">DB_CONFIG</code> file's
96 <code class="literal">set_tx_max</code> parameter. Remember that
97 the <code class="literal">DB_CONFIG</code> must reside in your
98 environment home directory.
99 </p>
100 </span>
101 </li>
102 <li>
103 <span>
104 <p>
105 <span>
106 Configure the timeout value for your transactions.
107 </span>
108
109
110 This value represents the longest period of time a
111 transaction can be active. Note, however, that
112 transaction timeouts are checked only when DB
113 examines its lock tables for blocked locks
114 (see <a class="xref" href="blocking_deadlocks.html" title="Locks, Blocks, and Deadlocks">Locks, Blocks, and Deadlocks</a>
115 for more information). Therefore, a transaction's timeout can
116 have expired, but the application will not be notified until DB
117 has a reason to examine its lock tables.
118 </p>
119 <p>
120 Be aware that some transactions may be
121 inappropriately timed out before the transaction has a
122 chance to complete. You should therefore use this
123 mechanism only if you know your application
124 might have unacceptably long transactions and
125 you want to make sure your application will
126 not stall during their execution.
127 (This might happen if, for example, your
128 transaction blocks or requests too much
129 data.)
130 </p>
131 <p>
132 Note that by default transaction timeouts are set to 0 seconds, which means that they never time
133 out.
134 </p>
135 <p>
136 To set the maximum timeout value for your transactions,
137 use the
138
139 <span><code class="methodname">DbEnv::set_timeout()</code></span>
140
141 method. This method configures the entire
142 environment; not just the handle used to set the
143 configuration. Further, this value may
144 be set at any time during the application's
145 lifetime.
146 </p>
147 <p>
148 This value can also be set using the
149 <code class="literal">DB_CONFIG</code> file's
150 <code class="literal">set_txn_timeout</code> parameter.
151 </p>
152
153 </span>
154 </li>
155 </ul>
156 </div>
157 <p>
158 For example:
159 </p>
160 <pre class="programlisting">#include "db_cxx.h"
161
162 ...
163
164 int main(void)
165 {
166 u_int32_t env_flags = DB_CREATE | // If the environment does not
167 // exist, create it.
168 DB_INIT_LOCK | // Initialize locking
169 DB_INIT_LOG | // Initialize logging
170 DB_INIT_MPOOL | // Initialize the cache
171 DB_THREAD | // Free-thread the env handle
172 DB_INIT_TXN; // Initialize transactions
173
174 std::string envHome("/export1/testEnv");
175 DbEnv myEnv(0);
176
177 try {
178
179 // Configure a maximum transaction timeout of 1 second.
180 myEnv.set_timeout(1000000, DB_SET_TXN_TIMEOUT);
181 // Configure 40 maximum transactions.
182 myEnv.set_tx_max(40);
183 myEnv.open(envHome.c_str(), env_flags, 0);
184
185 // From here, you open your databases, proceed with your
186 // database operations, and respond to deadlocks as
187 // is normal (omitted for brevity).
188
189
190 ...</pre>
191 </div>
192 <div class="navfooter">
193 <hr />
194 <table width="100%" summary="Navigation footer">
195 <tr>
196 <td width="40%" align="left"><a accesskey="p" href="txnindices.html">Prev</a> </td>
197 <td width="20%" align="center">
198 <a accesskey="u" href="usingtxns.html">Up</a>
199 </td>
200 <td width="40%" align="right"> <a accesskey="n" href="txnconcurrency.html">Next</a></td>
201 </tr>
202 <tr>
203 <td width="40%" align="left" valign="top">Secondary Indices with Transaction Applications </td>
204 <td width="20%" align="center">
205 <a accesskey="h" href="index.html">Home</a>
206 </td>
207 <td width="40%" align="right" valign="top"> Chapter 4. Concurrency</td>
208 </tr>
209 </table>
210 </div>
211 </body>
212 </html>