| 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>DB_ENV->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 DB_ENV Handle" /> |
| 11 | <link rel="prev" href="envset_encrypt.html" title="DB_ENV->set_encrypt()" /> |
| 12 | <link rel="next" href="envset_errcall.html" title="DB_ENV->set_errcall()" /> |
| 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">DB_ENV->set_event_notify()</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="envset_encrypt.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 5. |
| 26 | The DB_ENV Handle |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="envset_errcall.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="envevent_notify"></a>DB_ENV->set_event_notify()</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <pre class="programlisting">#include <db.h> |
| 42 | |
| 43 | int |
| 44 | DB_ENV->set_event_notify(DB_ENV *dbenv, |
| 45 | void (*db_event_fcn)(DB_ENV *dbenv, u_int32_t event, |
| 46 | void *event_info)); </pre> |
| 47 | <p> |
| 48 | The <code class="methodname">DB_ENV->set_event_notify()</code> method |
| 49 | configures a callback function which is called to notify the |
| 50 | process of specific Berkeley DB events. |
| 51 | </p> |
| 52 | <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> |
| 53 | <h3 class="title">Note</h3> |
| 54 | <p> |
| 55 | Berkeley DB is not re-entrant. Callback functions should |
| 56 | not attempt to make library calls (for example, to release |
| 57 | locks or close open handles). Re-entering Berkeley DB is |
| 58 | not guaranteed to work correctly, and the results are |
| 59 | undefined. |
| 60 | </p> |
| 61 | </div> |
| 62 | <p> |
| 63 | The <code class="methodname">DB_ENV->set_event_notify()</code> method |
| 64 | configures operations performed using the specified |
| 65 | <a class="link" href="env.html" title="Chapter 5. The DB_ENV Handle">DB_ENV</a> handle, not all operations |
| 66 | performed on the underlying database environment. |
| 67 | </p> |
| 68 | <p> |
| 69 | The <code class="methodname">DB_ENV->set_event_notify()</code> method may |
| 70 | be called at any time during the life of the application. |
| 71 | </p> |
| 72 | <p> |
| 73 | The <code class="methodname">DB_ENV->set_event_notify()</code> <span> |
| 74 | <span> |
| 75 | method returns a non-zero error value on failure and 0 on success. |
| 76 | </span> |
| 77 | |
| 78 | </span> |
| 79 | </p> |
| 80 | <div class="sect2" lang="en" xml:lang="en"> |
| 81 | <div class="titlepage"> |
| 82 | <div> |
| 83 | <div> |
| 84 | <h3 class="title"><a id="idp51899040"></a>Parameters</h3> |
| 85 | </div> |
| 86 | </div> |
| 87 | </div> |
| 88 | <div class="sect3" lang="en" xml:lang="en"> |
| 89 | <div class="titlepage"> |
| 90 | <div> |
| 91 | <div> |
| 92 | <h4 class="title"><a id="idp51881440"></a>db_event_fcn</h4> |
| 93 | </div> |
| 94 | </div> |
| 95 | </div> |
| 96 | <p> |
| 97 | The <span class="bold"><strong>db_event_fcn</strong></span> parameter is the |
| 98 | application's event notification function. The function takes three |
| 99 | parameters: |
| 100 | </p> |
| 101 | <div class="itemizedlist"> |
| 102 | <ul type="disc"> |
| 103 | <li> |
| 104 | <p> |
| 105 | <code class="literal">dbenv</code> |
| 106 | </p> |
| 107 | <p> |
| 108 | The <span class="bold"><strong>dbenv</strong></span> |
| 109 | parameter is the enclosing database environment |
| 110 | handle. |
| 111 | </p> |
| 112 | </li> |
| 113 | <li> |
| 114 | <p> |
| 115 | <code class="literal">event</code> |
| 116 | </p> |
| 117 | <p> |
| 118 | The <span class="bold"><strong>event</strong></span> parameter is one of the |
| 119 | following values: |
| 120 | </p> |
| 121 | <div class="itemizedlist"> |
| 122 | <ul type="circle"> |
| 123 | <li> |
| 124 | <p><a id="event_notify_DB_EVENT_PANIC"></a> |
| 125 | <code class="literal">DB_EVENT_PANIC</code> |
| 126 | </p> |
| 127 | <p> |
| 128 | Errors can occur in the Berkeley DB library where the only solution |
| 129 | is to shut down the application and run recovery (for example, if |
| 130 | Berkeley DB is unable to allocate heap memory). In such cases, the |
| 131 | Berkeley DB methods will return |
| 132 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_RUNRECOVERY" class="olink">DB_RUNRECOVERY</a>. |
| 133 | It is often easier to simply exit the application when such errors |
| 134 | occur rather than gracefully return up the stack. |
| 135 | </p> |
| 136 | <p> |
| 137 | When <span class="bold"><strong>event</strong></span> is set to |
| 138 | <code class="literal">DB_EVENT_PANIC</code>, the database environment has |
| 139 | failed. All threads of control in the database environment should |
| 140 | exit the environment, and recovery should be run. |
| 141 | </p> |
| 142 | </li> |
| 143 | <li> |
| 144 | <p><a id="event_notify_DB_EVENT_REG_ALIVE"></a> |
| 145 | <code class="literal">DB_EVENT_REG_ALIVE</code> |
| 146 | </p> |
| 147 | <p> |
| 148 | Recovery is needed in an environment where the |
| 149 | <a class="link" href="envopen.html#envopen_DB_REGISTER">DB_REGISTER</a> |
| 150 | flag was specified on the |
| 151 | <a class="xref" href="envopen.html" title="DB_ENV->open()">DB_ENV->open()</a> method and there is |
| 152 | a process attached to the environment. The callback function is triggered |
| 153 | once for each process attached. |
| 154 | </p> |
| 155 | <p> |
| 156 | The <span class="bold"><strong>event_info</strong></span> parameter points to a pid_t value |
| 157 | containing the process identifier (pid) of the process the Berkeley DB library |
| 158 | detects is attached to the environment. |
| 159 | </p> |
| 160 | </li> |
| 161 | <li> |
| 162 | <p><a id="event_notify_DB_EVENT_REG_PANIC"></a> |
| 163 | <code class="literal">DB_EVENT_REG_PANIC</code> |
| 164 | </p> |
| 165 | <p> |
| 166 | Recovery is needed in an environment where the |
| 167 | <a class="link" href="envopen.html#envopen_DB_REGISTER">DB_REGISTER</a> |
| 168 | flag was specified |
| 169 | on the <a class="xref" href="envopen.html" title="DB_ENV->open()">DB_ENV->open()</a> method. All threads |
| 170 | of control in the database environment should exit the environment. |
| 171 | </p> |
| 172 | <p> |
| 173 | This event is different than the <code class="literal">DB_EVENT_PANIC</code> event |
| 174 | because it can only be triggered when <code class="literal">DB_REGISTER</code> was |
| 175 | specified. It can be used to distinguish between the case when a process |
| 176 | dies in the environment and recovery is initiated versus the case when an |
| 177 | error happened (for example, if Berkeley DB is unable to allocate heap |
| 178 | memory) |
| 179 | </p> |
| 180 | </li> |
| 181 | <li> |
| 182 | <p><a id="event_notify_DB_EVENT_REP_CLIENT"></a> |
| 183 | <code class="literal">DB_EVENT_REP_CLIENT</code> |
| 184 | </p> |
| 185 | <p> |
| 186 | The local site is now a replication client. |
| 187 | </p> |
| 188 | <p> |
| 189 | This event is generated when the replication role changes to client, |
| 190 | either from master or from being unset. The role is unset when an |
| 191 | environment is first created and after an environment is recovered. |
| 192 | This event is not generated when restarting replication in an |
| 193 | environment that was previously a client and was opened without |
| 194 | recovery. |
| 195 | </p> |
| 196 | </li> |
| 197 | <li> |
| 198 | <p><a id="event_notify_DB_EVENT_REP_CONNECT_BROKEN"></a> |
| 199 | <code class="literal">DB_EVENT_REP_CONNECT_BROKEN</code> |
| 200 | </p> |
| 201 | <p> |
| 202 | A previously established replication message connection between the |
| 203 | local site and a remote site has been broken. This event supplies |
| 204 | the EID of the remote site, and an integer error code that |
| 205 | identifies the reason the connection was broken. |
| 206 | </p> |
| 207 | <p> |
| 208 | A non-zero error code indicates an unexpected |
| 209 | condition such as a hardware failure or a |
| 210 | protocol error. An application might respond |
| 211 | by emitting an informational message or passing |
| 212 | this information to other parts of the |
| 213 | application using the |
| 214 | <code class="literal">app_private</code> |
| 215 | field. A zero error code indicates that the |
| 216 | connection was cleanly closed by the other end. |
| 217 | Replication Manager retries broken connections |
| 218 | periodically until they are restored. |
| 219 | </p> |
| 220 | </li> |
| 221 | <li> |
| 222 | <p><a id="event_notify_DB_EVENT_REP_CONNECT_ESTD"></a> |
| 223 | <code class="literal">DB_EVENT_REP_CONNECT_ESTD</code> |
| 224 | </p> |
| 225 | <p> |
| 226 | A replication message connection has been established between the |
| 227 | local site and a remote site. This event supplied the EID of the |
| 228 | remote site. |
| 229 | </p> |
| 230 | </li> |
| 231 | <li> |
| 232 | <p><a id="event_notify_DB_EVENT_REP_CONNECT_TRY_FAILED"></a> |
| 233 | <code class="literal">DB_EVENT_REP_CONNECT_TRY_FAILED</code> |
| 234 | </p> |
| 235 | <p> |
| 236 | An attempt to establish a connection between the local site and a |
| 237 | remote site has failed. This event supplies the EID of the remote |
| 238 | site, and an integer error code that identifies the reason the |
| 239 | connection attempt failed. |
| 240 | </p> |
| 241 | </li> |
| 242 | <li> |
| 243 | <p><a id="event_notify_DB_EVENT_REP_DUPMASTER"></a> |
| 244 | <code class="literal">DB_EVENT_REP_DUPMASTER</code> |
| 245 | </p> |
| 246 | <p> |
| 247 | Replication Manager has detected a duplicate master situation, and |
| 248 | has changed the local site to the client role as a result. If the |
| 249 | <a class="link" href="repconfig.html#config_DB_REPMGR_CONF_ELECTIONS">DB_REPMGR_CONF_ELECTIONS</a> |
| 250 | configuration parameter has been turned off, the application should |
| 251 | now choose and assign the correct master site. If |
| 252 | <code class="literal">DB_REPMGR_CONF_ELECTIONS</code> is turned on, the |
| 253 | application may ignore this event. |
| 254 | </p> |
| 255 | <p> |
| 256 | The <code class="literal">DB_EVENT_REP_DUPMASTER</code> event is provided |
| 257 | only to applications configured for the replication manager. |
| 258 | </p> |
| 259 | </li> |
| 260 | <li> |
| 261 | <p><a id="event_notify_DB_EVENT_REP_ELECTED"></a> |
| 262 | <code class="literal">DB_EVENT_REP_ELECTED</code> |
| 263 | </p> |
| 264 | <p> |
| 265 | The local replication site has just won an election. An application |
| 266 | using the Base replication API should arrange for a call to the |
| 267 | <a class="xref" href="repstart.html" title="DB_ENV->rep_start()">DB_ENV->rep_start()</a> method |
| 268 | after receiving this event, to reconfigure the local environment as a |
| 269 | replication master. |
| 270 | </p> |
| 271 | <p> |
| 272 | Replication Manager applications may safely ignore this event. The |
| 273 | Replication Manager calls <a class="xref" href="repstart.html" title="DB_ENV->rep_start()">DB_ENV->rep_start()</a> |
| 274 | automatically on behalf of the application when appropriate (resulting |
| 275 | in firing of the DB_EVENT_REP_MASTER event). |
| 276 | </p> |
| 277 | </li> |
| 278 | <li> |
| 279 | <p><a id="event_notify_DB_EVENT_REP_ELECTION_FAILED"></a> |
| 280 | <code class="literal">DB_EVENT_REP_ELECTION_FAILED</code> |
| 281 | </p> |
| 282 | <p> |
| 283 | Replication Manager tried to run an election to choose a master |
| 284 | site, but the election failed due to lack of timely participation by |
| 285 | a sufficient number of other sites. Replication Manager will |
| 286 | automatically retry the election later. This event is for |
| 287 | information only. |
| 288 | </p> |
| 289 | <p> |
| 290 | The <code class="literal">DB_EVENT_REP_ELECTION_FAILED</code> event is |
| 291 | provided only to applications configured for the replication |
| 292 | manager. |
| 293 | </p> |
| 294 | </li> |
| 295 | <li> |
| 296 | <p><a id="event_notify_DB_EVENT_REP_ELECTION_STARTED"></a> |
| 297 | <code class="literal">DB_EVENT_REP_ELECTION_STARTED</code> |
| 298 | </p> |
| 299 | <p> |
| 300 | Replication Manager has started an election |
| 301 | to choose a master site. |
| 302 | </p> |
| 303 | </li> |
| 304 | <li> |
| 305 | <p><a id="event_notify_DB_EVENT_REP_INIT_DONE"></a> |
| 306 | <code class="literal">DB_EVENT_REP_INIT_DONE</code> |
| 307 | </p> |
| 308 | <p> |
| 309 | Replication Manager has completed an |
| 310 | internal initialization procedure. |
| 311 | </p> |
| 312 | </li> |
| 313 | <li> |
| 314 | <p><a id="event_notify_DB_EVENT_REP_JOIN_FAILURE"></a> |
| 315 | <code class="literal">DB_EVENT_REP_JOIN_FAILURE</code> |
| 316 | </p> |
| 317 | <p> |
| 318 | The local client site is unable to synchronize with a new master, |
| 319 | possibly because the client has turned off automatic internal |
| 320 | initialization by setting the |
| 321 | <a class="link" href="repconfig.html#config_DB_REP_CONF_AUTOINIT">DB_REP_CONF_AUTOINIT</a> |
| 322 | flag to <code class="literal">0</code>. |
| 323 | </p> |
| 324 | </li> |
| 325 | <li> |
| 326 | <p><a id="event_notify_DB_EVENT_REP_LOCAL_SITE_REMOVED"></a> |
| 327 | <code class="literal">DB_EVENT_REP_LOCAL_SITE_REMOVED</code> |
| 328 | </p> |
| 329 | <p> |
| 330 | The local site has been |
| 331 | removed from the replication group. |
| 332 | </p> |
| 333 | </li> |
| 334 | <li> |
| 335 | <p><a id="event_notify_DB_EVENT_REP_MASTER"></a> |
| 336 | <code class="literal">DB_EVENT_REP_MASTER</code> |
| 337 | </p> |
| 338 | <p> |
| 339 | The local site is now the master site of its replication group. It is |
| 340 | the application's responsibility to begin acting as the master |
| 341 | environment. |
| 342 | </p> |
| 343 | <p> |
| 344 | This event is generated when the replication role changes to master, |
| 345 | either from client or from being unset. The role is unset when an |
| 346 | environment is first created and after an environment is recovered. |
| 347 | This event is not generated when restarting replication in an |
| 348 | environment that was previously a master and was opened without |
| 349 | recovery. |
| 350 | </p> |
| 351 | </li> |
| 352 | <li> |
| 353 | <p><a id="event_notify_DB_EVENT_REP_MASTER_FAILURE"></a> |
| 354 | <code class="literal">DB_EVENT_REP_MASTER_FAILURE</code> |
| 355 | </p> |
| 356 | <p> |
| 357 | A Replication Manager client site has detected the loss of |
| 358 | connection to the master site. If the |
| 359 | <a class="link" href="repconfig.html#config_DB_REPMGR_CONF_ELECTIONS">DB_REPMGR_CONF_ELECTIONS</a> |
| 360 | configuration parameter is turned on, Replication Manager will |
| 361 | automatically start an election in order to choose a new master. In |
| 362 | this case, this event may be ignored. |
| 363 | </p> |
| 364 | <p> |
| 365 | When <code class="literal">DB_REPMGR_CONF_ELECTIONS</code> is turned off, the |
| 366 | application should choose and assign a new master. Failure to do so |
| 367 | means that your replication group has no master, and so it cannot |
| 368 | service write requests. |
| 369 | </p> |
| 370 | <p> |
| 371 | The <code class="literal">DB_EVENT_REP_MASTER_FAILURE</code> event is provided |
| 372 | only to applications configured for the replication manager. |
| 373 | </p> |
| 374 | </li> |
| 375 | <li> |
| 376 | <p><a id="event_notify_DB_EVENT_REP_NEWMASTER"></a> |
| 377 | <code class="literal">DB_EVENT_REP_NEWMASTER</code> |
| 378 | </p> |
| 379 | <p> |
| 380 | The replication group of which this site is a member has just |
| 381 | established a new master; the local site is not the new master. The |
| 382 | <span class="bold"><strong>event_info</strong></span> parameter points to an |
| 383 | integer containing the environment ID of the new master. |
| 384 | </p> |
| 385 | </li> |
| 386 | <li> |
| 387 | <p><a id="event_notify_DB_EVENT_REP_PERM_FAILED"></a> |
| 388 | <code class="literal">DB_EVENT_REP_PERM_FAILED</code> |
| 389 | </p> |
| 390 | <p> |
| 391 | The replication manager did not receive enough acknowledgements (based |
| 392 | on the acknowledgement policy configured with |
| 393 | <a class="xref" href="repmgrset_ack_policy.html" title="DB_ENV->repmgr_set_ack_policy()">DB_ENV->repmgr_set_ack_policy()</a> ) |
| 394 | to ensure a transaction's durability within the replication group. |
| 395 | The transaction will be flushed to the master's local disk storage for |
| 396 | durability. |
| 397 | </p> |
| 398 | <p> |
| 399 | The <code class="literal">DB_EVENT_REP_PERM_FAILED</code> event is provided |
| 400 | only to applications configured for the replication manager. |
| 401 | </p> |
| 402 | </li> |
| 403 | <li> |
| 404 | <p><a id="event_notify_DB_EVENT_REP_SITE_ADDED"></a> |
| 405 | <code class="literal">DB_EVENT_REP_SITE_ADDED</code> |
| 406 | </p> |
| 407 | <p> |
| 408 | A new site has joined the group. |
| 409 | The |
| 410 | <span class="bold"><strong>event_info</strong></span> parameter points to an |
| 411 | integer containing the environment ID of the new site. |
| 412 | </p> |
| 413 | </li> |
| 414 | <li> |
| 415 | <p><a id="event_notify_DB_EVENT_REP_SITE_REMOVED"></a> |
| 416 | <code class="literal">DB_EVENT_REP_SITE_REMOVED</code> |
| 417 | </p> |
| 418 | <p> |
| 419 | An existing remote site has been removed from the group. The |
| 420 | <span class="bold"><strong>event_info</strong></span> parameter points to an |
| 421 | integer containing the environment ID of the site that was removed. |
| 422 | </p> |
| 423 | </li> |
| 424 | <li> |
| 425 | <p><a id="event_notify_DB_EVENT_REP_STARTUPDONE"></a> |
| 426 | <code class="literal">DB_EVENT_REP_STARTUPDONE</code> |
| 427 | </p> |
| 428 | <p> |
| 429 | The client has completed startup synchronization and is now processing |
| 430 | live log records received from the master. |
| 431 | </p> |
| 432 | </li> |
| 433 | <li> |
| 434 | <p><a id="event_notify_DB_EVENT_WRITE_FAILED"></a> |
| 435 | <code class="literal">DB_EVENT_WRITE_FAILED</code> |
| 436 | </p> |
| 437 | <p> |
| 438 | A Berkeley DB write to stable storage failed. |
| 439 | </p> |
| 440 | </li> |
| 441 | </ul> |
| 442 | </div> |
| 443 | </li> |
| 444 | <li> |
| 445 | <p> |
| 446 | <code class="literal">event_info</code> |
| 447 | </p> |
| 448 | <p> |
| 449 | The <span class="bold"><strong>event_info</strong></span> parameter may |
| 450 | reference memory which contains additional information describing an |
| 451 | event. By default, <span class="bold"><strong>event_info</strong></span> is |
| 452 | NULL; specific events may pass non-NULL values, in which case the |
| 453 | event will also describe the memory's structure. |
| 454 | </p> |
| 455 | </li> |
| 456 | </ul> |
| 457 | </div> |
| 458 | </div> |
| 459 | </div> |
| 460 | <div class="sect2" lang="en" xml:lang="en"> |
| 461 | <div class="titlepage"> |
| 462 | <div> |
| 463 | <div> |
| 464 | <h3 class="title"><a id="idp51933176"></a>Class</h3> |
| 465 | </div> |
| 466 | </div> |
| 467 | </div> |
| 468 | <p> |
| 469 | <a class="link" href="env.html" title="Chapter 5. The DB_ENV Handle">DB_ENV</a> |
| 470 | </p> |
| 471 | </div> |
| 472 | <div class="sect2" lang="en" xml:lang="en"> |
| 473 | <div class="titlepage"> |
| 474 | <div> |
| 475 | <div> |
| 476 | <h3 class="title"><a id="idp51912200"></a>See Also</h3> |
| 477 | </div> |
| 478 | </div> |
| 479 | </div> |
| 480 | <p> |
| 481 | <a class="xref" href="env.html#envlist" title="Database Environments and Related Methods">Database Environments and Related Methods</a> |
| 482 | </p> |
| 483 | </div> |
| 484 | </div> |
| 485 | <div class="navfooter"> |
| 486 | <hr /> |
| 487 | <table width="100%" summary="Navigation footer"> |
| 488 | <tr> |
| 489 | <td width="40%" align="left"><a accesskey="p" href="envset_encrypt.html">Prev</a> </td> |
| 490 | <td width="20%" align="center"> |
| 491 | <a accesskey="u" href="env.html">Up</a> |
| 492 | </td> |
| 493 | <td width="40%" align="right"> <a accesskey="n" href="envset_errcall.html">Next</a></td> |
| 494 | </tr> |
| 495 | <tr> |
| 496 | <td width="40%" align="left" valign="top">DB_ENV->set_encrypt() </td> |
| 497 | <td width="20%" align="center"> |
| 498 | <a accesskey="h" href="index.html">Home</a> |
| 499 | </td> |
| 500 | <td width="40%" align="right" valign="top"> DB_ENV->set_errcall()</td> |
| 501 | </tr> |
| 502 | </table> |
| 503 | </div> |
| 504 | </body> |
| 505 | </html> |