Add a new event :ipreallocated"
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 11 Aug 2010 02:37:51 +0000 (12:37 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 11 Aug 2010 02:37:51 +0000 (12:37 +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.h
server/ctdb_takeover.c
server/eventscript.c

index 9dc6d7ada945a509f527dcfe47c5e57f9060a975..835bbfd5e2388a248de6d2b34c975ba72d838796 100644 (file)
@@ -664,5 +664,6 @@ const char *ctdb_eventscript_call_names[] = {
        "monitor",
        "status",
        "shutdown",
-       "reload"
+       "reload",
+       "ipreallocated"
 };
index c872837dac2b39aab4808f177d1500cd60781922..2fc232a78514daa5d2d9ec639d23a2f34e090511 100755 (executable)
@@ -45,7 +45,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 cc83495acdc283877bfdbbef85d01cc921c084cb..294fe012d5a75a35db9e53c8a8ea6d5a6b4e491f 100644 (file)
@@ -695,6 +695,7 @@ enum ctdb_eventscript_call {
        CTDB_EVENT_STATUS,              /* Report service status: no args. */
        CTDB_EVENT_SHUTDOWN,            /* CTDB shutting down: no args. */
        CTDB_EVENT_RELOAD,              /* magic */
+       CTDB_EVENT_IPREALLOCATED,       /* when a takeover_run() completes */
        CTDB_EVENT_MAX
 };
 
index cb65f29d751b7c94ab0b2b64cb0a51296ea04d27..208a6c615e60ef6d16dfafefa5aec589e00610e0 100644 (file)
@@ -737,10 +737,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, num_ips;
+       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;
@@ -749,7 +749,6 @@ int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap)
        struct ctdb_client_control_state *state;
        TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
 
-
        ZERO_STRUCT(ip);
 
        /* Count how many completely healthy nodes we have */
@@ -1057,6 +1056,20 @@ 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 712733c63cab35703b77c9a4f23db0d0ee0750f8..c403772454cb50ef53839d16ffcd8ac1a8279a34 100644 (file)
@@ -608,6 +608,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. */