When trying to re-balance the ip assignment and shuffle ips from
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 3 Aug 2010 03:34:27 +0000 (13:34 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 6 Jul 2011 03:18:32 +0000 (13:18 +1000)
nodes with many addresses to nodes with few addresses,
loop up to num_ips+5 times instead of only 5 times.

When we have very many public ips per node, we might need to loop more than
5 times or else we will exit without reaching optimal balance.

server/ctdb_takeover.c

index c82443416192a8314db906b887f793e002eb63d7..ddbc77f2c4a6a3e475efc35dfa63923a3db9d557 100644 (file)
@@ -1260,7 +1260,7 @@ 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, *nodes;
@@ -1312,6 +1312,12 @@ int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap)
        */
        all_ips = create_merged_ip_list(ctdb);
 
+       /* Count how many ips we have */
+       num_ips = 0;
+       for (tmp_ip=all_ips;tmp_ip;tmp_ip=tmp_ip->next) {
+               num_ips++;
+       }
+
        /* If we want deterministic ip allocations, i.e. that the ip addresses
           will always be allocated the same way for a specific set of
           available/unavailable nodes.
@@ -1445,11 +1451,11 @@ try_again:
                /* if the spread between the smallest and largest coverage by
                   a node is >=2 we steal one of the ips from the node with
                   most coverage to even things out a bit.
-                  try to do this at most 5 times  since we dont want to spend
-                  too much time balancing the ip coverage.
+                  try to do this a limited number of times since we dont
+                  want to spend too much time balancing the ip coverage.
                */
                if ( (maxnum > minnum+1)
-                 && (retries < 5) ){
+                 && (retries < (num_ips + 5)) ){
                        struct ctdb_public_ip_list *tmp;
 
                        /* mark one of maxnode's vnn's as unassigned and try