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