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::set_event_notify()</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="envset_encrypt.html" title="DbEnv::set_encrypt()" /> 12 <link rel="next" href="envset_errcall.html" title="DbEnv::set_errcall()" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">DbEnv::set_event_notify()</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="envset_encrypt.html">Prev</a> </td> 22 <th width="60%" align="center">Chapter 5. 23 The DbEnv Handle 24 </th> 25 <td width="20%" align="right"> <a accesskey="n" href="envset_errcall.html">Next</a></td> 26 </tr> 27 </table> 28 <hr /> 29 </div> 30 <div class="sect1" lang="en" xml:lang="en"> 31 <div class="titlepage"> 32 <div> 33 <div> 34 <h2 class="title" style="clear: both"><a id="envevent_notify"></a>DbEnv::set_event_notify()</h2> 35 </div> 36 </div> 37 </div> 38 <pre class="programlisting">#include <db_cxx.h> 39 40int 41DbEnv::set_event_notify( 42 void (*db_event_fcn)(DB_ENV *dbenv, u_int32_t event, 43 void *event_info));</pre> 44 <p> 45 The <code class="methodname">DbEnv::set_event_notify()</code> method configures a callback function 46 which is called to notify the process of specific Berkeley DB events. 47 </p> 48 <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> 49 <h3 class="title">Note</h3> 50 <p> 51 Berkeley DB is not re-entrant. Callback functions should not attempt to make library calls (for 52 example, to release locks or close open handles). Re-entering Berkeley DB is not guaranteed to work 53 correctly, and the results are undefined. 54 </p> 55 </div> 56 <p> 57 The <code class="methodname">DbEnv::set_event_notify()</code> method configures operations performed 58 using the specified <a class="link" href="env.html" title="Chapter 5. The DbEnv Handle">DbEnv</a> handle, not all 59 operations performed on the underlying database environment. 60 </p> 61 <p> 62 The <code class="methodname">DbEnv::set_event_notify()</code> method may be called at any time 63 during the life of the application. 64 </p> 65 <p> 66 The <code class="methodname">DbEnv::set_event_notify()</code> <span> 67 68 <span> 69 method either returns a non-zero error value or throws an 70 exception that encapsulates a non-zero error value on 71 failure, and returns 0 on success. 72 </span> 73 </span> 74 </p> 75 <div class="sect2" lang="en" xml:lang="en"> 76 <div class="titlepage"> 77 <div> 78 <div> 79 <h3 class="title"><a id="id1670100"></a>Parameters</h3> 80 </div> 81 </div> 82 </div> 83 <div class="sect3" lang="en" xml:lang="en"> 84 <div class="titlepage"> 85 <div> 86 <div> 87 <h4 class="title"><a id="id1670325"></a>db_event_fcn</h4> 88 </div> 89 </div> 90 </div> 91 <p> 92 The <span class="bold"><strong>db_event_fcn</strong></span> parameter is the 93 application's event notification function. The function takes three 94 parameters: 95 </p> 96 <div class="itemizedlist"> 97 <ul type="disc"> 98 <li> 99 <p> 100 <code class="literal">dbenv</code> 101 </p> 102 <p> 103 The <span class="bold"><strong>dbenv</strong></span> parameter is the enclosing 104 database environment handle. 105 </p> 106 </li> 107 <li> 108 <p> 109 <code class="literal">event</code> 110 </p> 111 <p> 112 The <span class="bold"><strong>event</strong></span> parameter is one of the 113 following values: 114 </p> 115 <div class="itemizedlist"> 116 <ul type="circle"> 117 <li> 118 <p><a id="event_notify_DB_EVENT_PANIC"></a> 119 <code class="literal">DB_EVENT_PANIC</code> 120 </p> 121 <p> 122 Errors can occur in the Berkeley DB library where the only solution is 123 to shut down the application and run recovery (for example, if 124 Berkeley DB is unable to allocate heap memory). In such cases, the 125 Berkeley DB methods will return 126 <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_RUNRECOVERY" class="olink">DB_RUNRECOVERY</a>. 127 It is often easier to simply exit the application when such errors 128 occur rather than gracefully return up the stack. 129 </p> 130 <p> 131 When <span class="bold"><strong>event</strong></span> is set to DB_EVENT_PANIC, 132 the database environment has failed. All threads of control in the 133 database environment should exit the environment, and recovery should 134 be run. 135 </p> 136 </li> 137 <li> 138 <p><a id="event_notify_DB_EVENT_REG_ALIVE"></a> 139 <code class="literal">DB_EVENT_REG_ALIVE</code> 140 </p> 141 <p> 142 Recovery is needed in an environment where the 143 <a class="link" href="envopen.html#envopen_DB_REGISTER">DB_REGISTER</a> 144 flag was specified on the 145 <a class="xref" href="envopen.html" title="DbEnv::open()">DbEnv::open()</a> method and there is 146 a process attached to the environment. The callback function is triggered 147 once for each process attached. 148 </p> 149 <p> 150 The <span class="bold"><strong>event_info</strong></span> parameter points to a pid_t value 151 containing the process identifier (pid) of the process the Berkeley DB library 152 detects is attached to the environment. 153 </p> 154 </li> 155 <li> 156 <p><a id="event_notify_DB_EVENT_REG_PANIC"></a> 157 <code class="literal">DB_EVENT_REG_PANIC</code> 158 </p> 159 <p> 160 Recovery is needed in an environment where the 161 <a class="link" href="envopen.html#envopen_DB_REGISTER">DB_REGISTER</a> 162 flag was specified 163 on the <a class="xref" href="envopen.html" title="DbEnv::open()">DbEnv::open()</a> method. All threads 164 of control in the database environment should exit the environment. 165 </p> 166 <p> 167 This event is different than the <code class="literal">DB_EVENT_PANIC</code> event 168 because it can only be triggered when <code class="literal">DB_REGISTER</code> was 169 specified. It can be used to distinguish between the case when a process 170 dies in the environment and recovery is initiated versus the case when an 171 error happened (for example, if Berkeley DB is unable to allocate heap 172 memory) 173 </p> 174 </li> 175 <li> 176 <p><a id="event_notify_DB_EVENT_REP_CLIENT"></a> 177 <code class="literal">DB_EVENT_REP_CLIENT</code> 178 </p> 179 <p> 180 The local site is now a replication client. 181 </p> 182 </li> 183 <li> 184 <p><a id="event_notify_DB_EVENT_REP_ELECTED"></a> 185 <code class="literal">DB_EVENT_REP_ELECTED</code> 186 </p> 187 <p> 188 The local replication site has just won an election. An application 189 using the Base replication API should arrange for a call to the 190 <a class="xref" href="repstart.html" title="DbEnv::rep_start()">DbEnv::rep_start()</a> method 191 after receiving this event, to reconfigure the local environment as a 192 replication master. 193 </p> 194 <p> 195 Replication Manager applications may safely ignore this event. The 196 Replication Manager calls <a class="xref" href="repstart.html" title="DbEnv::rep_start()">DbEnv::rep_start()</a> 197 automatically on behalf of the application when appropriate (resulting 198 in firing of the DB_EVENT_REP_MASTER event). 199 </p> 200 </li> 201 <li> 202 <p><a id="event_notify_DB_EVENT_REP_MASTER"></a> 203 <code class="literal">DB_EVENT_REP_MASTER</code> 204 </p> 205 <p> 206 The local site is now the master site of its replication group. It is 207 the application's responsibility to begin acting as the master 208 environment. 209 </p> 210 </li> 211 <li> 212 <p><a id="event_notify_DB_EVENT_REP_NEWMASTER"></a> 213 <code class="literal">DB_EVENT_REP_NEWMASTER</code> 214 </p> 215 <p> 216 The replication group of which this site is a member has just 217 established a new master; the local site is not the new master. The 218 <span class="bold"><strong>event_info</strong></span> parameter points to an 219 integer containing the environment ID of the new master. 220 </p> 221 </li> 222 <li> 223 <p><a id="event_notify_DB_EVENT_REP_PERM_FAILED"></a> 224 <code class="literal">DB_EVENT_REP_PERM_FAILED</code> 225 </p> 226 <p> 227 The replication manager did not receive enough acknowledgements (based 228 on the acknowledgement policy configured with 229 <a class="xref" href="repmgrset_ack_policy.html" title="DbEnv::repmgr_set_ack_policy()">DbEnv::repmgr_set_ack_policy()</a> ) 230 to ensure a transaction's durability within the replication group. 231 The transaction will be flushed to the master's local disk storage for 232 durability. 233 </p> 234 <p> 235 The DB_EVENT_REP_PERM_FAILED event is provided only to applications 236 configured for the replication manager. 237 </p> 238 </li> 239 <li> 240 <p><a id="event_notify_DB_EVENT_REP_STARTUPDONE"></a> 241 <code class="literal">DB_EVENT_REP_STARTUPDONE</code> 242 </p> 243 <p> 244 The client has completed startup synchronization and is now processing 245 live log records received from the master. 246 </p> 247 </li> 248 <li> 249 <p><a id="event_notify_DB_EVENT_WRITE_FAILED"></a> 250 <code class="literal">DB_EVENT_WRITE_FAILED</code> 251 </p> 252 <p> 253 A Berkeley DB write to stable storage failed. 254 </p> 255 </li> 256 </ul> 257 </div> 258 </li> 259 <li> 260 <p> 261 <code class="literal">event_info</code> 262 </p> 263 <p> 264 The <span class="bold"><strong>event_info</strong></span> parameter may 265 reference memory which contains additional information describing an 266 event. By default, <span class="bold"><strong>event_info</strong></span> is 267 NULL; specific events may pass non-NULL values, in which case the 268 event will also describe the memory's structure. 269 </p> 270 </li> 271 </ul> 272 </div> 273 </div> 274 </div> 275 <div class="sect2" lang="en" xml:lang="en"> 276 <div class="titlepage"> 277 <div> 278 <div> 279 <h3 class="title"><a id="id1670587"></a>Class</h3> 280 </div> 281 </div> 282 </div> 283 <p> 284 <a class="link" href="env.html" title="Chapter 5. The DbEnv Handle">DbEnv</a> 285 </p> 286 </div> 287 <div class="sect2" lang="en" xml:lang="en"> 288 <div class="titlepage"> 289 <div> 290 <div> 291 <h3 class="title"><a id="id1670912"></a>See Also</h3> 292 </div> 293 </div> 294 </div> 295 <p> 296 <a class="xref" href="env.html#envlist" title="Database Environments and Related Methods">Database Environments and Related Methods</a> 297 </p> 298 </div> 299 </div> 300 <div class="navfooter"> 301 <hr /> 302 <table width="100%" summary="Navigation footer"> 303 <tr> 304 <td width="40%" align="left"><a accesskey="p" href="envset_encrypt.html">Prev</a> </td> 305 <td width="20%" align="center"> 306 <a accesskey="u" href="env.html">Up</a> 307 </td> 308 <td width="40%" align="right"> <a accesskey="n" href="envset_errcall.html">Next</a></td> 309 </tr> 310 <tr> 311 <td width="40%" align="left" valign="top">DbEnv::set_encrypt() </td> 312 <td width="20%" align="center"> 313 <a accesskey="h" href="index.html">Home</a> 314 </td> 315 <td width="40%" align="right" valign="top"> DbEnv::set_errcall()</td> 316 </tr> 317 </table> 318 </div> 319 </body> 320</html> 321