recoverd: Optimise check for rebalance candidates in LCP2
authorMartin Schwenke <martin@meltin.net>
Fri, 7 Feb 2014 03:28:54 +0000 (14:28 +1100)
committerMartin Schwenke <martin@meltin.net>
Wed, 24 Feb 2016 05:57:06 +0000 (16:57 +1100)
Currently this can be checked many times.  However, there's no point
calling the rebalance/failback code at all if there are no rebalance
candidates.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
(Imported from commit 9e5ef44f32fad6606bd95e619f0720a72344e441)

server/ctdb_takeover.c

index 095ae417103ec8cb870deda90b72adf9b5c7e4aa..e02abe408bdbe61e7d9694dc9ed5d503265a3fa8 100644 (file)
@@ -1998,28 +1998,13 @@ static void lcp2_failback(struct ctdb_context *ctdb,
                          uint32_t *lcp2_imbalances,
                          bool *rebalance_candidates)
 {
-       int i, num_rebalance_candidates, numnodes;
+       int i, numnodes;
        struct lcp2_imbalance_pnn * lips;
        bool again;
 
        numnodes = talloc_array_length(ipflags);
 
 try_again:
-
-       /* It is only worth continuing if we have suitable target
-        * nodes to transfer IPs to.  This check is much cheaper than
-        * continuing on...
-        */
-       num_rebalance_candidates = 0;
-       for (i=0; i<numnodes; i++) {
-               if (rebalance_candidates[i]) {
-                       num_rebalance_candidates++;
-               }
-       }
-       if (num_rebalance_candidates == 0) {
-               return;
-       }
-
        /* Put the imbalances and nodes into an array, sort them and
         * iterate through candidates.  Usually the 1st one will be
         * used, so this doesn't cost much...
@@ -2153,6 +2138,7 @@ static void ip_alloc_lcp2(struct ctdb_context *ctdb,
 {
        uint32_t *lcp2_imbalances;
        bool *rebalance_candidates;
+       int numnodes, num_rebalance_candidates, i;
 
        TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
 
@@ -2168,6 +2154,21 @@ static void ip_alloc_lcp2(struct ctdb_context *ctdb,
                goto finished;
        }
 
+       /* It is only worth continuing if we have suitable target
+        * nodes to transfer IPs to.  This check is much cheaper than
+        * continuing on...
+        */
+       numnodes = talloc_array_length(ipflags);
+       num_rebalance_candidates = 0;
+       for (i=0; i<numnodes; i++) {
+               if (rebalance_candidates[i]) {
+                       num_rebalance_candidates++;
+               }
+       }
+       if (num_rebalance_candidates == 0) {
+               goto finished;
+       }
+
        /* Now, try to make sure the ip adresses are evenly distributed
           across the nodes.
        */