Transmit BDB event notifications into Erlang port driver.

This commit is contained in:
Gregory Burd 2011-12-03 10:23:40 -05:00
parent 9021359752
commit 12e3012a05
2 changed files with 54 additions and 0 deletions

View file

@ -137,6 +137,7 @@ static void* checkpointer(void* arg);
static void bdb_errcall(const DB_ENV* dbenv, const char* errpfx, const char* msg);
static void bdb_msgcall(const DB_ENV* dbenv, const char* msg);
static void bdb_eventcall(DB_ENV* dbenv, u_int32_t type, void* msg);
static void send_log_message(ErlDrvTermData* msg, int elements);
/**
@ -501,6 +502,7 @@ static void bdberl_drv_stop(ErlDrvData handle)
// Unregister with BDB -- MUST DO THIS WITH WRITE LOCK HELD!
G_DB_ENV->set_msgcall(G_DB_ENV, 0);
G_DB_ENV->set_errcall(G_DB_ENV, 0);
G_DB_ENV->set_event_notify(G_DB_ENV, 0);
WRITE_UNLOCK(G_LOG_RWLOCK);
}
@ -934,6 +936,7 @@ static int bdberl_drv_control(ErlDrvData handle, unsigned int cmd,
G_DB_ENV->set_msgcall(G_DB_ENV, &bdb_msgcall);
G_DB_ENV->set_errcall(G_DB_ENV, &bdb_errcall);
G_DB_ENV->set_event_notify(G_DB_ENV, &bdb_eventcall);
WRITE_UNLOCK(G_LOG_RWLOCK);
}
@ -2452,6 +2455,32 @@ static void bdb_msgcall(const DB_ENV* dbenv, const char* msg)
send_log_message(response, sizeof(response));
}
static void bdb_eventcall(DB_ENV* dbenv, u_int32_t type, void* info)
{
switch(type)
{
case DB_EVENT_PANIC:
{
const char *msg = "panic";
ErlDrvTermData response[] = { ERL_DRV_ATOM, driver_mk_atom("bdb_event_notify"),
ERL_DRV_STRING, (ErlDrvTermData)msg, (ErlDrvUInt)strlen(msg),
ERL_DRV_TUPLE, 2};
// TODO clearly something should be done to shut things down cleanly and restart (how?)
send_log_message(response, sizeof(response));
break;
}
case DB_EVENT_WRITE_FAILED:
{
const char *msg = "write failed";
ErlDrvTermData response[] = { ERL_DRV_ATOM, driver_mk_atom("bdb_event_notify"),
ERL_DRV_STRING, (ErlDrvTermData)msg, (ErlDrvUInt)strlen(msg),
ERL_DRV_TUPLE, 2};
send_log_message(response, sizeof(response));
break;
}
}
}
static void send_log_message(ErlDrvTermData* msg, int elements)
{
if (G_LOG_PORT)

View file

@ -385,3 +385,28 @@
-define(DB_UPDATE_SECONDARY, 29).
-define(DB_SET_LTE, 30).
-define(DB_GET_BOTH_LTE, 31).
%% DB Event notification types.
-define(DB_EVENT_PANIC, 0).
-define(DB_EVENT_REG_ALIVE, 1).
-define(DB_EVENT_REG_PANIC, 2).
-define(DB_EVENT_REP_CLIENT, 3).
-define(DB_EVENT_REP_CONNECT_BROKEN, 4).
-define(DB_EVENT_REP_CONNECT_ESTD, 5).
-define(DB_EVENT_REP_CONNECT_TRY_FAILED, 6).
-define(DB_EVENT_REP_DUPMASTER, 7).
-define(DB_EVENT_REP_ELECTED, 8).
-define(DB_EVENT_REP_ELECTION_FAILED, 9).
-define(DB_EVENT_REP_INIT_DONE, 10).
-define(DB_EVENT_REP_JOIN_FAILURE, 11).
-define(DB_EVENT_REP_LOCAL_SITE_REMOVED, 12).
-define(DB_EVENT_REP_MASTER, 13).
-define(DB_EVENT_REP_MASTER_FAILURE, 14).
-define(DB_EVENT_REP_NEWMASTER, 15).
-define(DB_EVENT_REP_PERM_FAILED, 16).
-define(DB_EVENT_REP_SITE_ADDED, 17).
-define(DB_EVENT_REP_SITE_REMOVED, 18).
-define(DB_EVENT_REP_STARTUPDONE, 19).
-define(DB_EVENT_REP_WOULD_ROLLBACK, 20).
-define(DB_EVENT_WRITE_FAILED, 21).
-define(DB_EVENT_NO_SUCH_EVENT, 0xffffffff).