ctdb-ipalloc: Move IP list creation out to ctdb_takeover_run()
authorMartin Schwenke <martin@meltin.net>
Wed, 28 Oct 2015 10:17:47 +0000 (21:17 +1100)
committerAmitay Isaacs <amitay@samba.org>
Fri, 20 Nov 2015 00:36:31 +0000 (01:36 +0100)
For various reasons create_merged_ip_list() needs a CTDB context.
This is difficult to resolve now for a few reasons, including:

* The ip_tree needs somewhere to live.

  It isn't very useful in its current form.  However, in the future
  real remote IP monitoring will probably be added back, so leave it
  around.

* It uses node flags from the ctdb_node structure.

  This could be changed by putting a node map into ipalloc_state
  and referencing that.

For now, it is easier to move it out to where there will be a CTDB
context available for the forseeable future.  ctdb_takeover_run() will
need one as long as the current client interface is used.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/server/ctdb_takeover.c
ctdb/tests/src/ctdb_takeover_tests.c

index 26303855e7329c27ed37fcf7ab7f28e095e6fb0c..f263fce296c7b0970a29829481802d6286bcf064 100644 (file)
@@ -2210,28 +2210,18 @@ static bool all_nodes_are_disabled(struct ctdb_node_map_old *nodemap)
 /* The calculation part of the IP allocation algorithm. */
 static void ctdb_takeover_run_core(struct ctdb_context *ctdb,
                                   struct ctdb_ipflags *ipflags,
-                                  struct public_ip_list **all_ips_p,
+                                  struct public_ip_list *all_ips,
                                   uint32_t *force_rebalance_nodes)
 {
-       /* since nodes only know about those public addresses that
-          can be served by that particular node, no single node has
-          a full list of all public addresses that exist in the cluster.
-          Walk over all node structures and create a merged list of
-          all public addresses that exist in the cluster.
-
-          keep the tree of ips around as ctdb->ip_tree
-       */
-       *all_ips_p = create_merged_ip_list(ctdb);
-
        switch (ctdb->ipalloc_state->algorithm) {
        case IPALLOC_LCP2:
-               ip_alloc_lcp2(ctdb, ipflags, *all_ips_p, force_rebalance_nodes);
+               ip_alloc_lcp2(ctdb, ipflags, all_ips, force_rebalance_nodes);
                break;
        case IPALLOC_DETERMINISTIC:
-               ip_alloc_deterministic_ips(ctdb, ipflags, *all_ips_p);
+               ip_alloc_deterministic_ips(ctdb, ipflags, all_ips);
                break;
        case IPALLOC_NONDETERMINISTIC:
-               ip_alloc_nondeterministic_ips(ctdb, ipflags, *all_ips_p);
+               ip_alloc_nondeterministic_ips(ctdb, ipflags, all_ips);
                break;
        }
 
@@ -2648,8 +2638,18 @@ int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map_old *nodem
                return 0;
        }
 
+       /* since nodes only know about those public addresses that
+          can be served by that particular node, no single node has
+          a full list of all public addresses that exist in the cluster.
+          Walk over all node structures and create a merged list of
+          all public addresses that exist in the cluster.
+
+          keep the tree of ips around as ctdb->ip_tree
+       */
+       all_ips = create_merged_ip_list(ctdb);
+
        /* Do the IP reassignment calculations */
-       ctdb_takeover_run_core(ctdb, ipflags, &all_ips, force_rebalance_nodes);
+       ctdb_takeover_run_core(ctdb, ipflags, all_ips, force_rebalance_nodes);
 
        /* Now tell all nodes to release any public IPs should not
         * host.  This will be a NOOP on nodes that don't currently
index 8a9938280db846405afd9e7fac1b417edc42dd39..936f641aaee2e0c685e9f249e6d428374f3aee95 100644 (file)
@@ -603,7 +603,9 @@ static void ctdb_test_ctdb_takeover_run_core(const char nodestates[],
        ctdb_test_init(nodestates, &ctdb, &all_ips, &ipflags,
                       read_ips_for_multiple_nodes);
 
-       ctdb_takeover_run_core(ctdb, ipflags, &all_ips, NULL);
+       all_ips = create_merged_ip_list(ctdb);
+
+       ctdb_takeover_run_core(ctdb, ipflags, all_ips, NULL);
 
        print_ctdb_public_ip_list(all_ips);