#include <db.h>

DB_ENV->set_event_notify(DB_ENV *dbenv,
    void (*db_event_fcn)(DB_ENV *dbenv, u_int32_t event, 
    void *event_info));  

The DB_ENV->set_event_notify() method configures a callback function which is called to notify the process of specific Berkeley DB events.


Berkeley DB is not re-entrant. Callback functions should not attempt to make library calls (for example, to release locks or close open handles). Re-entering Berkeley DB is not guaranteed to work correctly, and the results are undefined.

The DB_ENV->set_event_notify() method configures operations performed using the specified DB_ENV handle, not all operations performed on the underlying database environment.

The DB_ENV->set_event_notify() method may be called at any time during the life of the application.

The DB_ENV->set_event_notify() method returns a non-zero error value on failure and 0 on success.



The db_event_fcn parameter is the application's event notification function. The function takes three parameters:

  • dbenv

    The dbenv parameter is the enclosing database environment handle.

  • event

    The event parameter is one of the following values:


      Errors can occur in the Berkeley DB library where the only solution is to shut down the application and run recovery (for example, if Berkeley DB is unable to allocate heap memory). In such cases, the Berkeley DB methods will return DB_RUNRECOVERY. It is often easier to simply exit the application when such errors occur rather than gracefully return up the stack.

      When event is set to DB_EVENT_PANIC, the database environment has failed. All threads of control in the database environment should exit the environment, and recovery should be run.


      Recovery is needed in an environment where the DB_REGISTER flag was specified on the DB_ENV->open() method and there is a process attached to the environment. The callback function is triggered once for each process attached.

      The event_info parameter points to a pid_t value containing the process identifier (pid) of the process the Berkeley DB library detects is attached to the environment.


      Recovery is needed in an environment where the DB_REGISTER flag was specified on the DB_ENV->open() method. All threads of control in the database environment should exit the environment.

      This event is different than the DB_EVENT_PANIC event because it can only be triggered when DB_REGISTER was specified. It can be used to distinguish between the case when a process dies in the environment and recovery is initiated versus the case when an error happened (for example, if Berkeley DB is unable to allocate heap memory)


      The local site is now a replication client.


      The local replication site has just won an election. An application using the Base replication API should arrange for a call to the DB_ENV->rep_start() method after receiving this event, to reconfigure the local environment as a replication master.

      Replication Manager applications may safely ignore this event. The Replication Manager calls DB_ENV->rep_start() automatically on behalf of the application when appropriate (resulting in firing of the DB_EVENT_REP_MASTER event).


      The local site is now the master site of its replication group. It is the application's responsibility to begin acting as the master environment.


      The replication group of which this site is a member has just established a new master; the local site is not the new master. The event_info parameter points to an integer containing the environment ID of the new master.


      The replication manager did not receive enough acknowledgements (based on the acknowledgement policy configured with DB_ENV->repmgr_set_ack_policy() ) to ensure a transaction's durability within the replication group. The transaction will be flushed to the master's local disk storage for durability.

      The DB_EVENT_REP_PERM_FAILED event is provided only to applications configured for the replication manager.


      The client has completed startup synchronization and is now processing live log records received from the master.


      A Berkeley DB write to stable storage failed.

  • event_info

    The event_info parameter may reference memory which contains additional information describing an event. By default, event_info is NULL; specific events may pass non-NULL values, in which case the event will also describe the memory's structure.



See Also

Database Environments and Related Methods