From: Ronnie Sahlberg Date: Mon, 30 Aug 2010 08:08:38 +0000 (+1000) Subject: Add a new event "ipreallocated" X-Git-Url: http://git.samba.org/?p=metze%2Fctdb%2Fwip.git;a=commitdiff_plain;h=7f4c591388adae20e98984001385cba26598ec67 Add a new event "ipreallocated" This is called everytime a reallocation is performed. While STARTRECOVERY/RECOVERED events are only called when we do ipreallocation as part of a full database/cluster recovery, this new event can be used to trigger on when we just do a light failover due to a node becomming unhealthy. I.e. situations where we do a failover but we do not perform a full cluster recovery. Use this to trigger for natgw so we select a new natgw master node when failover happens and not just when cluster rebuilds happen. --- diff --git a/common/ctdb_util.c b/common/ctdb_util.c index add2c3a9..4244a046 100644 --- a/common/ctdb_util.c +++ b/common/ctdb_util.c @@ -685,5 +685,6 @@ const char *ctdb_eventscript_call_names[] = { "status", "shutdown", "reload", + "ipreallocated", "updateip" }; diff --git a/config/events.d/11.natgw b/config/events.d/11.natgw index 46de7fa6..61c09e93 100755 --- a/config/events.d/11.natgw +++ b/config/events.d/11.natgw @@ -46,7 +46,7 @@ case "$1" in ctdb setnatgwstate on ;; - recovered|updatenatgw) + recovered|updatenatgw|ipreallocated) MYPNN=`ctdb pnn | cut -d: -f2` NATGWMASTER=`ctdb natgwlist | head -1 | sed -e "s/ .*//"` NATGWIP=`ctdb natgwlist | head -1 | sed -e "s/^[^ ]* *//"` diff --git a/include/ctdb_protocol.h b/include/ctdb_protocol.h index 99765d40..df6e90c2 100644 --- a/include/ctdb_protocol.h +++ b/include/ctdb_protocol.h @@ -183,6 +183,7 @@ enum ctdb_eventscript_call { CTDB_EVENT_SHUTDOWN, /* CTDB shutting down: no args. */ CTDB_EVENT_RELOAD, /* magic */ CTDB_EVENT_UPDATE_IP, /* IP updating: old interface, new interface, IP address, netmask bits. */ + CTDB_EVENT_IPREALLOCATED, /* when a takeover_run() completes */ CTDB_EVENT_MAX }; diff --git a/server/ctdb_takeover.c b/server/ctdb_takeover.c index 44a68eeb..06494c85 100644 --- a/server/ctdb_takeover.c +++ b/server/ctdb_takeover.c @@ -1215,10 +1215,10 @@ create_merged_ip_list(struct ctdb_context *ctdb) */ int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap) { - int i, num_healthy, retries; + int i, num_healthy, retries, num_ips; struct ctdb_public_ip ip; struct ctdb_public_ipv4 ipv4; - uint32_t mask; + uint32_t mask, *nodes; struct ctdb_public_ip_list *all_ips, *tmp_ip; int maxnode, maxnum=0, minnode, minnum=0, num; TDB_DATA data; @@ -1529,6 +1529,19 @@ finished: return -1; } + /* tell all nodes to update natwg */ + /* send the flags update natgw on all connected nodes */ + data.dptr = discard_const("ipreallocated"); + data.dsize = strlen((char *)data.dptr) + 1; + nodes = list_of_connected_nodes(ctdb, nodemap, tmp_ctx, true); + if (ctdb_client_async_control(ctdb, CTDB_CONTROL_RUN_EVENTSCRIPTS, + nodes, 0, TAKEOVER_TIMEOUT(), + false, data, + NULL, NULL, + NULL) != 0) { + DEBUG(DEBUG_ERR, (__location__ " ctdb_control to updatenatgw failed\n")); + } + talloc_free(tmp_ctx); return 0; } diff --git a/server/eventscript.c b/server/eventscript.c index 139f59f2..ce2fd89e 100644 --- a/server/eventscript.c +++ b/server/eventscript.c @@ -633,6 +633,7 @@ static bool check_options(enum ctdb_eventscript_call call, const char *options) case CTDB_EVENT_STATUS: case CTDB_EVENT_SHUTDOWN: case CTDB_EVENT_RELOAD: + case CTDB_EVENT_IPREALLOCATED: return count_words(options) == 0; case CTDB_EVENT_TAKE_IP: /* interface, IP address, netmask bits. */