ctdb-takeover: Only fetch available IPs from nodes with known IPs
authorMartin Schwenke <martin@meltin.net>
Fri, 3 Feb 2017 04:31:00 +0000 (15:31 +1100)
committerMartin Schwenke <martins@samba.org>
Fri, 24 Feb 2017 06:47:12 +0000 (07:47 +0100)
A simple optimisation to avoid unnecessary communication.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/server/ctdb_takeover_helper.c
ctdb/tests/takeover_helper/031.sh [new file with mode: 0755]

index d359cf913ba6dd28258279e48ccbc1bf8d6dcf6e..e56c94ac9a2ac0d1700a94701200ed0b2b0c3836 100644 (file)
@@ -866,6 +866,8 @@ static void takeover_known_ips_done(struct tevent_req *subreq)
                req, struct takeover_state);
        int ret;
        bool status;
+       uint32_t *pnns = NULL;
+       int count, i;
 
        status = get_public_ips_recv(subreq, &ret, state, &state->known_ips);
        TALLOC_FREE(subreq);
@@ -876,8 +878,26 @@ static void takeover_known_ips_done(struct tevent_req *subreq)
                return;
        }
 
+       /* Get available IPs from active nodes that actually have known IPs */
+
+       pnns = talloc_zero_array(state, uint32_t, state->num_active);
+       if (tevent_req_nomem(pnns, req)) {
+               return;
+       }
+
+       count = 0;
+       for (i = 0; i < state->num_active; i++) {
+               uint32_t pnn = state->pnns_active[i];
+
+               /* If pnn has IPs then fetch available IPs from it */
+               if (state->known_ips[pnn].num > 0) {
+                       pnns[count] = pnn;
+                       count++;
+               }
+       }
+
        subreq = get_public_ips_send(state, state->ev, state->client,
-                                    state->pnns_active, state->num_active,
+                                    pnns, count,
                                     state->num_nodes, true);
        if (tevent_req_nomem(subreq, req)) {
                return;
diff --git a/ctdb/tests/takeover_helper/031.sh b/ctdb/tests/takeover_helper/031.sh
new file mode 100755 (executable)
index 0000000..435cd49
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "3 nodes, all ok, IPs defined on 2, IPs all unassigned"
+
+setup_ctdbd <<EOF
+NODEMAP
+0       192.168.20.41   0x0     CURRENT RECMASTER
+1       192.168.20.42   0x0
+2       192.168.20.43   0x0
+
+IFACES
+:Name:LinkStatus:References:
+:eth2:1:2:
+:eth1:1:4:
+
+PUBLICIPS
+10.0.0.31  -1 0,2
+10.0.0.32  -1 0,2
+10.0.0.33  -1 0,2
+10.0.0.34  -1 0,2
+EOF
+
+HELPER_DEBUGLEVEL=INFO
+ok <<EOF
+Fetched public IPs from node 0
+Fetched public IPs from node 1
+Fetched public IPs from node 2
+Fetched public IPs from node 0
+Fetched public IPs from node 2
+ 10.0.0.34 -> 0 [+0]
+ 10.0.0.33 -> 2 [+0]
+ 10.0.0.31 -> 0 [+14884]
+ 10.0.0.32 -> 2 [+16129]
+RELEASE_IP 10.0.0.34 succeeded on 2 nodes
+RELEASE_IP 10.0.0.33 succeeded on 2 nodes
+RELEASE_IP 10.0.0.32 succeeded on 2 nodes
+RELEASE_IP 10.0.0.31 succeeded on 2 nodes
+TAKEOVER_IP 10.0.0.34 succeeded on node 0
+TAKEOVER_IP 10.0.0.33 succeeded on node 2
+TAKEOVER_IP 10.0.0.32 succeeded on node 2
+TAKEOVER_IP 10.0.0.31 succeeded on node 0
+IPREALLOCATED succeeded on 3 nodes
+EOF
+test_takeover_helper
+
+required_result 0 <<EOF
+Public IPs on ALL nodes
+10.0.0.31 0
+10.0.0.32 2
+10.0.0.33 2
+10.0.0.34 0
+EOF
+test_ctdb_ip_all