Add a new event "ipreallocated"
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 30 Aug 2010 08:08:38 +0000 (18:08 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 30 Aug 2010 08:09:30 +0000 (18:09 +1000)
    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.

common/ctdb_util.c
config/events.d/11.natgw
include/ctdb_protocol.h
server/ctdb_takeover.c
server/eventscript.c

index add2c3a95bd721f708301ae8b6cc16a11dea7972..4244a046e6131a12d4bb5dbfb437a0dd5db4cfe5 100644 (file)
@@ -685,5 +685,6 @@ const char *ctdb_eventscript_call_names[] = {
        "status",
        "shutdown",
        "reload",
+       "ipreallocated",
        "updateip"
 };
index 46de7fa617f07d651043eb3e89e55eae0b631581..61c09e93465c874fb3c2513039cb27a6c7838024 100755 (executable)
@@ -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/^[^ ]* *//"`
index 99765d40937855ab26670646ff9898fef306195c..df6e90c292c05c0c493aec713ab749e85b2757bc 100644 (file)
@@ -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
 };
 
index 44a68eeb86ed939a9f13832ede822f63629ed934..06494c85e0d3a5ba2dead6e8372270448410e2b7 100644 (file)
@@ -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;
 }
index 139f59f2f86ce2c238e2ce4afb9485b1a981d4d4..ce2fd89eca5a61fc8dda0dc65d3e06751ed1540b 100644 (file)
@@ -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. */