From: Amitay Isaacs Date: Thu, 19 Dec 2013 02:01:25 +0000 (+1100) Subject: ctdb-daemon: Do not run monitor event if any other event is already running X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=cbffbb7c2f406fc1d8ebad3c531cc2757232690e;p=metze%2Fsamba%2Fwip.git ctdb-daemon: Do not run monitor event if any other event is already running Any currently running monitor events are cancelled if any other events are scheduled. However, this does not stop monitor events to be run when other events are already running. Keep track of the number of active events and schedule monitor event only if there are no active events. Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index eba4045083f0..b95b2c7b84ff 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -526,6 +526,7 @@ struct ctdb_context { TALLOC_CTX *release_ips_ctx; /* a context used to automatically drop all IPs if we fail to recover the node */ TALLOC_CTX *event_script_ctx; + int active_events; struct ctdb_event_script_state *current_monitor; struct ctdb_scripts_wire *last_status[CTDB_EVENT_MAX]; diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index 0feb32b44c5d..e40405eac529 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -645,6 +645,11 @@ static int event_script_destructor(struct ctdb_event_script_state *state) status = 0; } + state->ctdb->active_events--; + if (state->ctdb->active_events < 0) { + ctdb_fatal(state->ctdb, "Active events < 0"); + } + /* This is allowed to free us; talloc will prevent double free anyway, * but beware if you call this outside the destructor! * the callback hangs off a different context so we walk the list @@ -750,6 +755,14 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb, } } + /* Do not run new monitor events if some event is already running */ + if (call == CTDB_EVENT_MONITOR && ctdb->active_events > 0) { + if (callback != NULL) { + callback(ctdb, -ECANCELED, private_data); + } + return 0; + } + /* Kill off any running monitor events to run this event. */ if (ctdb->current_monitor) { struct ctdb_event_script_state *ms = talloc_get_type(ctdb->current_monitor, struct ctdb_event_script_state); @@ -816,6 +829,8 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb, talloc_set_destructor(state, event_script_destructor); + ctdb->active_events++; + /* Nothing to do? */ if (state->scripts->num_scripts == 0) { talloc_free(state);