diff --git a/ctdb/server/ctdb_takeover.c b/ctdb/server/ctdb_takeover.c index 0bd8034674e..56589d90ea5 100644 --- a/ctdb/server/ctdb_takeover.c +++ b/ctdb/server/ctdb_takeover.c @@ -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; }