| 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>DbEnv::close()</title> |
| 7 | <link rel="stylesheet" href="apiReference.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 C++ API Reference" /> |
| 10 | <link rel="up" href="env.html" title="Chapter 5. The DbEnv Handle" /> |
| 11 | <link rel="prev" href="envbackup.html" title="DbEnv::backup()" /> |
| 12 | <link rel="next" href="envcreate.html" title="DbEnv" /> |
| 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">DbEnv::close()</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="envbackup.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 5. |
| 26 | The DbEnv Handle |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="envcreate.html">Next</a></td> |
| 29 | </tr> |
| 30 | </table> |
| 31 | <hr /> |
| 32 | </div> |
| 33 | <div class="sect1" lang="en" xml:lang="en"> |
| 34 | <div class="titlepage"> |
| 35 | <div> |
| 36 | <div> |
| 37 | <h2 class="title" style="clear: both"><a id="envclose"></a>DbEnv::close()</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <pre class="programlisting">#include <db_cxx.h> |
| 42 | |
| 43 | DbEnv::close(u_int32_t flags);</pre> |
| 44 | <p> |
| 45 | The <code class="methodname">DbEnv::close()</code> method closes the |
| 46 | Berkeley DB environment, freeing any allocated resources and |
| 47 | closing all database handles opened with this environment handle, |
| 48 | as well as closing any underlying subsystems. |
| 49 | </p> |
| 50 | <p> |
| 51 | When you call the <code class="methodname">DbEnv::close()</code> method, |
| 52 | all open <a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> handles and |
| 53 | <a class="link" href="dbc.html" title="Chapter 3. The Dbc Handle">Dbc</a> handles are closed |
| 54 | automatically by this function. And, when you close a database |
| 55 | handle, all cursors opened with it are closed automatically. |
| 56 | </p> |
| 57 | <p> |
| 58 | In multiple threads of control, each thread of control opens a |
| 59 | database environment and the database handles within it. When you |
| 60 | close each database handle using the |
| 61 | <code class="methodname">DbEnv::close()</code> method, by default, the |
| 62 | database is not synchronized and is similar to calling the |
| 63 | <code class="methodname">Db::close(DB_NOSYNC)</code> method. This is to |
| 64 | avoid unncessary database synchronization when there are multiple |
| 65 | environment handles open. To ensure all open database handles are |
| 66 | synchronized when you close the last environment handle, set the |
| 67 | flag parameter value of the <code class="methodname">DbEnv::close()</code> |
| 68 | method to DB_FORCESYNC. This is similar to calling the |
| 69 | <code class="methodname">Db::close(0)</code> method to close each database |
| 70 | handle. |
| 71 | </p> |
| 72 | <p> |
| 73 | If a database close operation fails, the method returns a non-zero |
| 74 | error value for the first instance of such an error, and continues |
| 75 | to close the rest of the database and environment handles. |
| 76 | </p> |
| 77 | <p> |
| 78 | The <a class="link" href="env.html" title="Chapter 5. The DbEnv Handle">DbEnv</a> handle should |
| 79 | not be closed while any other handle that refers to it is not yet |
| 80 | closed; for example, database environment handles must not be closed |
| 81 | while transactions in the environment |
| 82 | have not yet been committed or aborted. Specifically, this includes the |
| 83 | <a class="link" href="txn.html" title="Chapter 13. The DbTxn Handle">DbTxn</a>, |
| 84 | <a class="link" href="logc.html" title="The DbLogc Handle">DbLogc</a> and |
| 85 | <a class="link" href="memp.html" title="Chapter 9. The DbMpoolFile Handle">DbMpoolFile</a> handles. |
| 86 | </p> |
| 87 | <p> |
| 88 | Where the environment was initialized with the |
| 89 | <a class="link" href="envopen.html#envopen_DB_INIT_LOCK">DB_INIT_LOCK</a> flag, |
| 90 | calling <code class="methodname">DbEnv::close()</code> does not release any locks still held by the |
| 91 | closing process, providing functionality for long-lived locks. |
| 92 | Processes that want to have all their locks released can do so by |
| 93 | issuing the appropriate <a class="xref" href="lockvec.html" title="DbEnv::lock_vec()">DbEnv::lock_vec()</a> call. |
| 94 | </p> |
| 95 | <p> |
| 96 | Where the environment was initialized with the |
| 97 | <a class="link" href="envopen.html#envopen_DB_INIT_MPOOL">DB_INIT_MPOOL</a> flag, |
| 98 | calling <code class="methodname">DbEnv::close()</code> implies calls to |
| 99 | <a class="xref" href="mempfclose.html" title="DbMpoolFile::close()">DbMpoolFile::close()</a> for any |
| 100 | remaining open files in the memory pool that were returned to this |
| 101 | process by calls to <a class="xref" href="mempfopen.html" title="DbMpoolFile::open()">DbMpoolFile::open()</a>. It does |
| 102 | not imply a call to <a class="xref" href="mempfsync.html" title="DbMpoolFile::sync()">DbMpoolFile::sync()</a> for those |
| 103 | files. |
| 104 | </p> |
| 105 | <p> |
| 106 | Where the environment was initialized with the |
| 107 | <a class="link" href="envopen.html#envopen_DB_INIT_TXN">DB_INIT_TXN</a> |
| 108 | flag, calling <code class="methodname">DbEnv::close()</code> aborts any |
| 109 | unresolved transactions. Applications should not depend on this |
| 110 | behavior for transactions involving Berkeley DB databases; all |
| 111 | such transactions should be explicitly resolved. The problem with |
| 112 | depending on this semantic is that aborting an unresolved |
| 113 | transaction involving database operations requires a database |
| 114 | handle. Because the database handles should have been closed |
| 115 | before calling <code class="methodname">DbEnv::close()</code>, it will not |
| 116 | be possible to abort the transaction, and recovery will have to be |
| 117 | run on the Berkeley DB environment before further operations are |
| 118 | done. |
| 119 | </p> |
| 120 | <p> |
| 121 | Where log cursors were created using the |
| 122 | <a class="xref" href="logcursor.html" title="DbEnv::log_cursor()">DbEnv::log_cursor()</a> method, |
| 123 | calling <code class="methodname">DbEnv::close()</code> does not imply |
| 124 | closing those cursors. |
| 125 | </p> |
| 126 | <p> |
| 127 | In multithreaded applications, only a single thread may call the |
| 128 | <code class="methodname">DbEnv::close()</code> method. |
| 129 | </p> |
| 130 | <p> |
| 131 | After <code class="methodname">DbEnv::close()</code> has been called, |
| 132 | regardless of its return, the Berkeley DB environment handle may |
| 133 | not be accessed again. |
| 134 | </p> |
| 135 | <p> |
| 136 | The <code class="methodname">DbEnv::close()</code> <span> |
| 137 | |
| 138 | <span> |
| 139 | method either returns a non-zero error value or throws an |
| 140 | exception that encapsulates a non-zero error value on |
| 141 | failure, and returns 0 on success. |
| 142 | </span> |
| 143 | </span> |
| 144 | </p> |
| 145 | <div class="sect2" lang="en" xml:lang="en"> |
| 146 | <div class="titlepage"> |
| 147 | <div> |
| 148 | <div> |
| 149 | <h3 class="title"><a id="idp6614672"></a>Parameters</h3> |
| 150 | </div> |
| 151 | </div> |
| 152 | </div> |
| 153 | <div class="sect3" lang="en" xml:lang="en"> |
| 154 | <div class="titlepage"> |
| 155 | <div> |
| 156 | <div> |
| 157 | <h4 class="title"><a id="idp6601736"></a>flags</h4> |
| 158 | </div> |
| 159 | </div> |
| 160 | </div> |
| 161 | <p> |
| 162 | The <span class="bold"><strong>flags</strong></span> parameter must be set to 0 |
| 163 | or be set to the following value: |
| 164 | </p> |
| 165 | <div class="itemizedlist"> |
| 166 | <ul type="disc"> |
| 167 | <li> |
| 168 | <p><a id="dbenvclose_DB_FORCESYNC"></a> |
| 169 | <code class="literal">DB_FORCESYNC</code> |
| 170 | </p> |
| 171 | <p> |
| 172 | When closing each database handle internally, |
| 173 | synchronize the database. If this flag is not |
| 174 | specified, the database handle is closed without |
| 175 | synchronizing the database. |
| 176 | </p> |
| 177 | </li> |
| 178 | </ul> |
| 179 | </div> |
| 180 | </div> |
| 181 | </div> |
| 182 | <div class="sect2" lang="en" xml:lang="en"> |
| 183 | <div class="titlepage"> |
| 184 | <div> |
| 185 | <div> |
| 186 | <h3 class="title"><a id="idp6638656"></a>Class</h3> |
| 187 | </div> |
| 188 | </div> |
| 189 | </div> |
| 190 | <p> |
| 191 | <a class="link" href="env.html" title="Chapter 5. The DbEnv Handle">DbEnv</a> |
| 192 | </p> |
| 193 | </div> |
| 194 | <div class="sect2" lang="en" xml:lang="en"> |
| 195 | <div class="titlepage"> |
| 196 | <div> |
| 197 | <div> |
| 198 | <h3 class="title"><a id="idp6633896"></a>See Also</h3> |
| 199 | </div> |
| 200 | </div> |
| 201 | </div> |
| 202 | <p> |
| 203 | <a class="xref" href="env.html#envlist" title="Database Environments and Related Methods">Database Environments and Related Methods</a> |
| 204 | </p> |
| 205 | </div> |
| 206 | </div> |
| 207 | <div class="navfooter"> |
| 208 | <hr /> |
| 209 | <table width="100%" summary="Navigation footer"> |
| 210 | <tr> |
| 211 | <td width="40%" align="left"><a accesskey="p" href="envbackup.html">Prev</a> </td> |
| 212 | <td width="20%" align="center"> |
| 213 | <a accesskey="u" href="env.html">Up</a> |
| 214 | </td> |
| 215 | <td width="40%" align="right"> <a accesskey="n" href="envcreate.html">Next</a></td> |
| 216 | </tr> |
| 217 | <tr> |
| 218 | <td width="40%" align="left" valign="top">DbEnv::backup() </td> |
| 219 | <td width="20%" align="center"> |
| 220 | <a accesskey="h" href="index.html">Home</a> |
| 221 | </td> |
| 222 | <td width="40%" align="right" valign="top"> DbEnv</td> |
| 223 | </tr> |
| 224 | </table> |
| 225 | </div> |
| 226 | </body> |
| 227 | </html> |