Library Version 12.1.6.2

DbEnv::set_event_notify()
Prev | Chapter 5. The DbEnv Handle | Next

## DbEnv::set_event_notify()

    #include <db_cxx.h>

    int
    DbEnv::set_event_notify(
        void (*db_event_fcn)(DB_ENV *dbenv, u_int32_t event,
        void *event_info));

The `DbEnv::set_event_notify()` method configures a callback function which is called to notify the process of specific Berkeley DB events.

### Note

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 `DbEnv::set_event_notify()` method configures operations performed using the specified DbEnv handle, not all operations performed on the underlying database environment.

The `DbEnv::set_event_notify()` method may be called at any time during the life of the application.

The `DbEnv::set_event_notify()` method either returns a non-zero error value or throws an exception that encapsulates a non-zero error value on failure, and returns 0 on success.

### Parameters

#### db_event_fcn

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:

  - `DB_EVENT_FAILCHK_PANIC`

    The thread is about to return a DB_RUNRECOVERY error because a prior panic event has occurred and the thread has been marked by DbEnv::failchk() as being held by a crashed process.

    The event_info parameter is a pointer to a `DB_FAILCHK_PANIC_INFO` structure, which contains these fields:

        int error;
        char symptom[DB_FAILURE_SYMPTOM_SIZE];

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

    This event is generated only when failchk broadcasting is configured. You configured broadcasting by specifying `--enable-failchk_broadcast` when you compile your Berkeley DB library.

  - `DB_EVENT_MUTEX_DIED`

    The thread is about to return a DB_RUNRECOVERY error because a mutex it requires has been marked by DbEnv::failchk() as being held by a crashed process.

    The event_info parameter is a pointer to a `DB_MUTEX_DIED_INFO` structure, which contains these fields:

         pid_t         mtxdied_pid;
        db_threadid_t mtxdied_tid;
        db_mutex_t    mtxdied_mtx;
        char          mtxdied_desc[DB_MUTEX_DESCRIBE_STRLEN];

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

    This event is generated only when failchk broadcasting is configured. You configured broadcasting by specifying `--enable-failchk_broadcast` when you compile your Berkeley DB library.

  - `DB_EVENT_PANIC`

    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.

  - `DB_EVENT_REG_ALIVE`

    Recovery is needed in an environment where the DB_REGISTER flag was specified on the DbEnv::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.

  - `DB_EVENT_REG_PANIC`

    Recovery is needed in an environment where the DB_REGISTER flag was specified on the DbEnv::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)

  - `DB_EVENT_REP_AUTOTAKEOVER_FAILED`

    The current subordinate process attempted to take over as the replication process, but the attempt failed.

    The replication process is the main Replication Manager process which is responsible for sending and processing most Replication Manager messages. Normally this is the first process started in a replication group, but when that process shuts down cleanly, a subordinate process will take over if one is available.

    This event means that this Replication Manager subordinate process attempted to take over as the replication process, but it failed. Replication Manager is not running locally but may be restarted by invoking DbEnv::repmgr_start().

    The `DB_EVENT_REP_AUTOTAKEOVER_FAILED` event is provided only to applications configured for the Replication Manager.

  - `DB_EVENT_REP_CLIENT`

    The local site is now a replication client.

    This event is generated when the replication role changes to client, either from master or from being unset. The role is unset when an environment is first created and after an environment is recovered. This event is not generated when restarting replication in an environment that was previously a client and was opened without recovery.

  - `DB_EVENT_REP_CONNECT_BROKEN`

    A previously established Replication Manager message connection between the local site and a remote site has been broken. This event supplies the EID of the remote site, and an integer error code that identifies the reason the connection was broken.

    A non-zero error code indicates an unexpected condition such as a hardware failure or a protocol error. An application might respond by emitting an informational message or passing this information to other parts of the application using the `app_private` field. A zero error code indicates that the connection was cleanly closed by the other end. Replication Manager retries broken connections periodically until they are restored.

    The `DB_EVENT_REP_CONNECT_BROKEN` event is provided only to applications configured for the Replication Manager.

  - `DB_EVENT_REP_CONNECT_ESTD`

    A Replication Manager message connection has been established between the local site and a remote site. This event supplied the EID of the remote site.

    The `DB_EVENT_REP_CONNECT_ESTD` event is provided only to applications configured for the Replication Manager.

  - `DB_EVENT_REP_CONNECT_TRY_FAILED`

    A Replication Manager attempt to establish a connection between the local site and a remote site has failed. This event supplies the EID of the remote site, and an integer error code that identifies the reason the connection attempt failed.

    The `DB_EVENT_REP_CONNECT_TRY_FAILED` event is provided only to applications configured for the Replication Manager.

  - `DB_EVENT_REP_DUPMASTER`

    Replication Manager has detected a duplicate master situation, and has changed the local site to the client role as a result. If the DB_REPMGR_CONF_ELECTIONS configuration parameter has been turned off, the application should now choose and assign the correct master site. If `DB_REPMGR_CONF_ELECTIONS` is turned on, the application may ignore this event.

    The `DB_EVENT_REP_DUPMASTER` event is provided only to applications configured for the Replication Manager.

  - `DB_EVENT_REP_ELECTED`

    The local replication site has just won an election. A Base API application should call the DbEnv::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 DbEnv::rep_start() automatically on behalf of the application when appropriate (resulting in firing of the DB_EVENT_REP_MASTER event).

  - `DB_EVENT_REP_ELECTION_FAILED`

    Replication Manager tried to run an election to choose a master site, but the election failed due to lack of timely participation by a sufficient number of other sites. Replication Manager will automatically retry the election later. This event is for information only.

    The `DB_EVENT_REP_ELECTION_FAILED` event is provided only to applications configured for the Replication Manager.

  - `DB_EVENT_REP_INIT_DONE`

    The local client site has completed an internal initialization procedure.

  - `DB_EVENT_REP_INQUEUE_FULL`

    Incoming messages will be dropped because the Replication Mananger incoming queue has reached its maximum threshold.

  - `DB_EVENT_REP_JOIN_FAILURE`

    The local client site is unable to synchronize with a new master, possibly because the client has turned off automatic internal initialization by setting the DB_REP_CONF_AUTOINIT flag to `0`.

  - `DB_EVENT_REP_LOCAL_SITE_REMOVED`

    The local site has been removed from the replication group.

    The `DB_EVENT_REP_LOCAL_SITE_REMOVED` event is provided only to applications configured for the Replication Manager.

  - `DB_EVENT_REP_MASTER`

    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.

    This event is generated when the replication role changes to master, either from client or from being unset. The role is unset when an environment is first created and after an environment is recovered. This event is not generated when restarting replication in an environment that was previously a master and was opened without recovery.

  - `DB_EVENT_REP_MASTER_FAILURE`

    A Replication Manager client site has detected the loss of connection to the master site. If the DB_REPMGR_CONF_ELECTIONS configuration parameter is turned on, Replication Manager will automatically start an election in order to choose a new master. In this case, this event may be ignored.

    When `DB_REPMGR_CONF_ELECTIONS` is turned off, the application should choose and assign a new master. Failure to do so means that your replication group has no master, and so it cannot service write requests.

    The `DB_EVENT_REP_MASTER_FAILURE` event is provided only to applications configured for the Replication Manager.

  - `DB_EVENT_REP_NEWMASTER`

    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.

  - `DB_EVENT_REP_PERM_FAILED`

    The Replication Manager did not receive enough acknowledgements (based on the acknowledgement policy configured with DbEnv::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.

  - `DB_EVENT_REP_SITE_ADDED`

    A new site has joined the replication group. The event_info parameter points to an integer containing the environment ID of the new site.

    The `DB_EVENT_REP_SITE_ADDED` event is provided only to applications configured for the Replication Manager.

  - `DB_EVENT_REP_SITE_REMOVED`

    An existing remote site has been removed from the replication group. The event_info parameter points to an integer containing the environment ID of the site that was removed.

    The `DB_EVENT_REP_SITE_REOMVED` event is provided only to applications configured for the Replication Manager.

  - `DB_EVENT_REP_STARTUPDONE`

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

  - `DB_EVENT_WRITE_FAILED`

    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.

### Class

DbEnv

### See Also

Database Environments and Related Methods

Prev | Up | Next
DbEnv::set_encrypt() | Home | DbEnv::set_errcall()