| 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>Berkeley DB configuration</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="Berkeley DB Programmer's Reference Guide" /> |
| 10 | <link rel="up" href="stl.html" title="Chapter 7. Standard Template Library API" /> |
| 11 | <link rel="prev" href="stl_examples.html" title="Dbstl examples" /> |
| 12 | <link rel="next" href="stl_db_advanced_usage.html" title="Using advanced Berkeley DB features with dbstl" /> |
| 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">Berkeley DB configuration</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="stl_examples.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 7. Standard Template Library API</th> |
| 26 | <td width="20%" align="right"> <a accesskey="n" href="stl_db_advanced_usage.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="stl_db_usage"></a>Berkeley DB configuration</h2> |
| 36 | </div> |
| 37 | </div> |
| 38 | </div> |
| 39 | <div class="toc"> |
| 40 | <dl> |
| 41 | <dt> |
| 42 | <span class="sect2"> |
| 43 | <a href="stl_db_usage.html#idp51381760">Registering database and environment handles</a> |
| 44 | </span> |
| 45 | </dt> |
| 46 | <dt> |
| 47 | <span class="sect2"> |
| 48 | <a href="stl_db_usage.html#idp51405208">Truncate requirements</a> |
| 49 | </span> |
| 50 | </dt> |
| 51 | <dt> |
| 52 | <span class="sect2"> |
| 53 | <a href="stl_db_usage.html#idp51416888">Auto commit support</a> |
| 54 | </span> |
| 55 | </dt> |
| 56 | <dt> |
| 57 | <span class="sect2"> |
| 58 | <a href="stl_db_usage.html#idp51379224">Database and environment identity checks</a> |
| 59 | </span> |
| 60 | </dt> |
| 61 | <dt> |
| 62 | <span class="sect2"> |
| 63 | <a href="stl_db_usage.html#idp51415360">Products, constructors and configurations</a> |
| 64 | </span> |
| 65 | </dt> |
| 66 | </dl> |
| 67 | </div> |
| 68 | <p> |
| 69 | While dbstl behaves like the C++ STL APIs in most situations, there |
| 70 | are some Berkeley DB configuration activities that you can and |
| 71 | should perform using dbstl. These activities are described in the |
| 72 | following sections. |
| 73 | </p> |
| 74 | <div class="sect2" lang="en" xml:lang="en"> |
| 75 | <div class="titlepage"> |
| 76 | <div> |
| 77 | <div> |
| 78 | <h3 class="title"><a id="idp51381760"></a>Registering database and environment handles</h3> |
| 79 | </div> |
| 80 | </div> |
| 81 | </div> |
| 82 | <p> |
| 83 | Remember the following things as you use Berkeley DB Database |
| 84 | and Environment handles with dbstl: |
| 85 | </p> |
| 86 | <div class="itemizedlist"> |
| 87 | <ul type="disc"> |
| 88 | <li> |
| 89 | <p> |
| 90 | If you share environment or database handles among multiple |
| 91 | threads, remember to specify the <a href="../api_reference/C/dbopen.html#open_DB_THREAD" class="olink">DB_THREAD</a> flag in the open call to |
| 92 | the handle. |
| 93 | </p> |
| 94 | </li> |
| 95 | <li> |
| 96 | <p> |
| 97 | If you create or open environment and/or database handles without |
| 98 | using the dbstl helper functions, |
| 99 | <code class="function">dbstl::open_db()</code> or |
| 100 | <code class="function">dbstl::open_env()</code>, remember that your |
| 101 | environment and database handles should be: |
| 102 | </p> |
| 103 | <div class="orderedlist"> |
| 104 | <ol type="1"> |
| 105 | <li> |
| 106 | <p> |
| 107 | Allocated in the heap via "new" operator. |
| 108 | </p> |
| 109 | </li> |
| 110 | <li> |
| 111 | <p> |
| 112 | Created using the <a href="../api_reference/CXX/envcreate.html#env_DB_CXX_NO_EXCEPTIONS" class="olink">DB_CXX_NO_EXCEPTIONS</a> flag. |
| 113 | </p> |
| 114 | </li> |
| 115 | <li> |
| 116 | <p> |
| 117 | In each thread sharing the handles, the handles are registered using |
| 118 | either <code class="function">dbstl::register_db()</code> or |
| 119 | <code class="function">dbstl::register_dbenv()</code>. |
| 120 | </p> |
| 121 | </li> |
| 122 | </ol> |
| 123 | </div> |
| 124 | </li> |
| 125 | <li> |
| 126 | <p> |
| 127 | If you opened the database or environment handle using the |
| 128 | <code class="function">open_db()</code> or <code class="function">open_env()</code> |
| 129 | functions, the thread opening the handles should not call |
| 130 | <code class="function">register_db()</code> or <code class="function">register_env()</code> |
| 131 | again. This is because they have already been registered by the |
| 132 | <code class="function">open_db()</code> or <code class="function">open_env()</code> |
| 133 | functions. However, other threads sharing these handles still must register |
| 134 | them locally. |
| 135 | </p> |
| 136 | </li> |
| 137 | </ul> |
| 138 | </div> |
| 139 | </div> |
| 140 | <div class="sect2" lang="en" xml:lang="en"> |
| 141 | <div class="titlepage"> |
| 142 | <div> |
| 143 | <div> |
| 144 | <h3 class="title"><a id="idp51405208"></a>Truncate requirements</h3> |
| 145 | </div> |
| 146 | </div> |
| 147 | </div> |
| 148 | <p> |
| 149 | Some Berkeley DB operations require there to be no open cursors on the |
| 150 | database handle at the time the operation occurs. Dbstl is aware of |
| 151 | these requirements, and will attempt to close the cursors opened in the |
| 152 | current thread when it performs these operations. However, the scope of |
| 153 | dbstl's activities in this regard are limited to the current thread; it |
| 154 | makes no attempt to close cursors opened in other threads. So you |
| 155 | are required to ensure there are no open cursors on database handles |
| 156 | shared across threads when operations are performed that require all |
| 157 | cursors on that handle to be closed. |
| 158 | </p> |
| 159 | <p> |
| 160 | |
| 161 | There are only a a few operations which require all open cursors to be closed. |
| 162 | This include all container <code class="methodname">clear()</code> and |
| 163 | <code class="methodname">swap()</code> functions, and all versions of |
| 164 | <code class="methodname">db_vection<>::assign()</code> functions. These |
| 165 | functions require all cursors to be closed for the database because by default |
| 166 | they remove all key/data pairs from the database by truncating it. |
| 167 | </p> |
| 168 | <p> |
| 169 | When a function removes all key/data pairs from a database, there are |
| 170 | two ways it can perform this activity: |
| 171 | </p> |
| 172 | <div class="itemizedlist"> |
| 173 | <ul type="disc"> |
| 174 | <li> |
| 175 | <p> |
| 176 | The default method is to truncate the database, which is an |
| 177 | operation that requires all cursors to be closed. As mentioned |
| 178 | above, it is your responsibility to close cursors opened in other |
| 179 | threads before performing this operation. Otherwise, the operation |
| 180 | will fail. |
| 181 | </p> |
| 182 | </li> |
| 183 | <li> |
| 184 | <p> |
| 185 | Alternatively, you can specify that the database not be truncated. |
| 186 | Instead, you can cause dbstl to delete all key/data pairs |
| 187 | individually, one after another. In this situation, |
| 188 | open cursors in the database will not cause the delete operations to |
| 189 | fail. However, due to lock contention, the delete operations might not |
| 190 | complete until all cursors are closed, which is when all their read locks |
| 191 | are released. |
| 192 | </p> |
| 193 | </li> |
| 194 | </ul> |
| 195 | </div> |
| 196 | </div> |
| 197 | <div class="sect2" lang="en" xml:lang="en"> |
| 198 | <div class="titlepage"> |
| 199 | <div> |
| 200 | <div> |
| 201 | <h3 class="title"><a id="idp51416888"></a>Auto commit support</h3> |
| 202 | </div> |
| 203 | </div> |
| 204 | </div> |
| 205 | <p> |
| 206 | |
| 207 | Dbstl supports auto commit for some of its container's operations. When a dbstl |
| 208 | container is created using a <code class="classname">Db</code> or <code class="classname">DbEnv</code> |
| 209 | object, if that object was opened using the <a href="../api_reference/C/envset_flags.html#envset_flags_DB_AUTO_COMMIT" class="olink">DB_AUTO_COMMIT</a> flag, then |
| 210 | every operation subsequently performed on that object will be |
| 211 | automatically enclosed in a unique transaction (unless the operation is already in an |
| 212 | external transaction). This |
| 213 | is identical to how the Berkeley DB C, C++ and Java APIs behave. |
| 214 | </p> |
| 215 | <p> |
| 216 | Note that only a subset of a container's operations support auto |
| 217 | commit. This is because those operations that accept or return an |
| 218 | iterator have to exist in an external transactional context and so |
| 219 | cannot support auto commit. |
| 220 | </p> |
| 221 | <p> |
| 222 | The dbstl API documentation identifies when a method supports auto |
| 223 | commit transactions. |
| 224 | </p> |
| 225 | </div> |
| 226 | <div class="sect2" lang="en" xml:lang="en"> |
| 227 | <div class="titlepage"> |
| 228 | <div> |
| 229 | <div> |
| 230 | <h3 class="title"><a id="idp51379224"></a>Database and environment identity checks</h3> |
| 231 | </div> |
| 232 | </div> |
| 233 | </div> |
| 234 | <p> |
| 235 | When a container member function involves another container (for example, |
| 236 | <code class="methodname">db_vector::swap(self& v2)</code>), the two |
| 237 | containers involved in the operation must not use the same database. |
| 238 | Further, if the function is in an external or internal transaction context, |
| 239 | then both containers must belong |
| 240 | to the same transactional database environment; Otherwise, the two containers |
| 241 | can belong to the same database environment, or two different ones. |
| 242 | </p> |
| 243 | <p> |
| 244 | For example, if <code class="methodname">db_vector::swap(self& v2)</code> |
| 245 | is an auto commit method or it is in an external transaction context, |
| 246 | then <code class="literal">v2</code> must be in the same transactional database |
| 247 | environment as this container, because a transaction is started |
| 248 | internally that must be used by both <code class="literal">v2</code> and this |
| 249 | container. If this container and the <code class="literal">v2</code> container |
| 250 | have different database environments, and either of them are using transactions, |
| 251 | an exception is thrown. This condition is checked in every such member |
| 252 | function. |
| 253 | </p> |
| 254 | <p> |
| 255 | However, if the function is not in a transactional context, |
| 256 | then the databases used by these |
| 257 | containers can be in different environments because in this situation |
| 258 | dbstl makes no attempt to wrap container operations in a common transaction |
| 259 | context. |
| 260 | </p> |
| 261 | </div> |
| 262 | <div class="sect2" lang="en" xml:lang="en"> |
| 263 | <div class="titlepage"> |
| 264 | <div> |
| 265 | <div> |
| 266 | <h3 class="title"><a id="idp51415360"></a>Products, constructors and configurations</h3> |
| 267 | </div> |
| 268 | </div> |
| 269 | </div> |
| 270 | <p> |
| 271 | You can use dbstl with all Berkeley DB products (DS, CDS, TDS, and HA). |
| 272 | Because dbstl is a Berkeley DB interface, all necessary configurations |
| 273 | for these products are performed using Berkeley DB's standard |
| 274 | create/open/set APIs. |
| 275 | </p> |
| 276 | <p> |
| 277 | As a result, the dbstl container constructors differ from those of C++ |
| 278 | STL because in dbstl no configuration is supported using the container |
| 279 | constructors. On the other hand, dbstl container constructors accept |
| 280 | already opened and configured environment and database handles. They |
| 281 | also provide functions to retrieve some handle configuration, such as |
| 282 | key comparison and hash functions, as required by the C++ STL |
| 283 | specifications. |
| 284 | </p> |
| 285 | <p> |
| 286 | The constructors verify that the handles passed to them are well |
| 287 | configured. This means they ensure that no banned settings are used, as |
| 288 | well as ensuring that all required setting are performed. If the |
| 289 | handles are not well configured, an |
| 290 | <code class="classname">InvalidArgumentException</code> is thrown. |
| 291 | </p> |
| 292 | <p> |
| 293 | If a container constructor is not passed a database or environment |
| 294 | handle, an internal anonymous database is created for you by dbstl. This anonymous |
| 295 | database does not provide data persistence. |
| 296 | </p> |
| 297 | </div> |
| 298 | </div> |
| 299 | <div class="navfooter"> |
| 300 | <hr /> |
| 301 | <table width="100%" summary="Navigation footer"> |
| 302 | <tr> |
| 303 | <td width="40%" align="left"><a accesskey="p" href="stl_examples.html">Prev</a> </td> |
| 304 | <td width="20%" align="center"> |
| 305 | <a accesskey="u" href="stl.html">Up</a> |
| 306 | </td> |
| 307 | <td width="40%" align="right"> <a accesskey="n" href="stl_db_advanced_usage.html">Next</a></td> |
| 308 | </tr> |
| 309 | <tr> |
| 310 | <td width="40%" align="left" valign="top">Dbstl examples </td> |
| 311 | <td width="20%" align="center"> |
| 312 | <a accesskey="h" href="index.html">Home</a> |
| 313 | </td> |
| 314 | <td width="40%" align="right" valign="top"> Using advanced Berkeley DB features with dbstl</td> |
| 315 | </tr> |
| 316 | </table> |
| 317 | </div> |
| 318 | </body> |
| 319 | </html> |