]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
change the way we pick/find a new node to takeover for a failed node
authorRonnie Sahlberg <sahlberg@ronnie>
Sun, 15 Jul 2007 22:28:44 +0000 (08:28 +1000)
committerRonnie Sahlberg <sahlberg@ronnie>
Sun, 15 Jul 2007 22:28:44 +0000 (08:28 +1000)
to keep a static that controls at which noide to start searching the
list for takeover candidates next time we need to find a node.

each time we find a node to takeover, reset the start variable to point
to the next node in the list

this makes the distribution of takeover nodes much more even

(This used to be ctdb commit e9800df5a21079ea478d16f7dd2fd4707de85650)

ctdb/server/ctdb_takeover.c

index 0bd8034674e1e3c2f114477ddb4c1068c1239266..56589d90ea5c826467c07d130e7859b54d37e3a0 100644 (file)
@@ -452,20 +452,39 @@ static bool ctdb_same_subnet(const char *ip1, const char *ip2, uint8_t netmask_b
   criterion given by the flags
  */
 static void ctdb_takeover_find_node(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap,
-                                   int start_node, uint32_t mask_flags)
+                                   int node, uint32_t mask_flags)
 {
+       static int start_node=0;
        int j;
-       for (j=(start_node+1)%nodemap->num;
-            j != start_node;
-            j=(j+1)%nodemap->num) {
+
+       j=start_node;
+       while (1) {
                if (!(nodemap->nodes[j].flags & mask_flags) &&
                    ctdb_same_subnet(ctdb->nodes[j]->public_address, 
-                                    ctdb->nodes[start_node]->public_address, 
+                                    ctdb->nodes[node]->public_address, 
                                     ctdb->nodes[j]->public_netmask_bits)) {
-                       ctdb->nodes[start_node]->takeover_vnn = nodemap->nodes[j].vnn;
+                       ctdb->nodes[node]->takeover_vnn = nodemap->nodes[j].vnn;
+                       /* We found a node to take over
+                          also update the startnode so that we start at a 
+                          different node next time we are called.
+                        */
+                       start_node = (j+1)%nodemap->num;;
+                       return;
+               }
+
+               /* Try the next node */
+               j=(j+1)%nodemap->num;
+
+               /* We tried all the nodes and got back to where we started,
+                  there is no node that can take over
+                */
+               if (j == start_node) {
                        break;
                }
        }
+
+       /* No takeover node found */
+       return;
 }