From: Martin Schwenke Date: Mon, 13 Dec 2021 23:57:03 +0000 (+1100) Subject: ctdb-recoverd: Add and use function this_node_can_be_leader() X-Git-Tag: tdb-1.4.6~132 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7baadfe27eda40560753fb4a61e053ea357fd2d2;p=thirdparty%2Fsamba.git ctdb-recoverd: Add and use function this_node_can_be_leader() This makes the code self-documenting. In ctdb_election_data() there is a slight behaviour change. An inactive node will now try to lose an election. This case should not happen because: * An inactive node can't win an election round and then send a reply. * Any inactive node should never start an election. There are currently places where this happens and they will be fixed later. There is an instance where this could be used in validate_recovery_master() but this involves a more serious logic change. Overhaul this function later. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/server/ctdb_recoverd.c b/ctdb/server/ctdb_recoverd.c index d749cf06191..affa3b2bbd1 100644 --- a/ctdb/server/ctdb_recoverd.c +++ b/ctdb/server/ctdb_recoverd.c @@ -279,6 +279,12 @@ static bool this_node_is_leader(struct ctdb_recoverd *rec) return rec->leader == rec->pnn; } +static bool this_node_can_be_leader(struct ctdb_recoverd *rec) +{ + return (rec->node_flags & NODE_FLAGS_INACTIVE) == 0 && + (rec->ctdb->capabilities & CTDB_CAP_RECMASTER) != 0; +} + /* ban a node for a period of time */ @@ -1308,8 +1314,8 @@ static void ctdb_election_data(struct ctdb_recoverd *rec, struct election_messag } } - /* we shouldnt try to win this election if we cant be a recmaster */ - if ((ctdb->capabilities & CTDB_CAP_RECMASTER) == 0) { + if (!this_node_can_be_leader(rec)) { + /* Try to lose... */ em->num_connected = 0; em->priority_time = timeval_current(); } @@ -1327,18 +1333,7 @@ static bool ctdb_election_win(struct ctdb_recoverd *rec, struct election_message ctdb_election_data(rec, &myem); - /* we cant win if we don't have the recmaster capability */ - if ((rec->ctdb->capabilities & CTDB_CAP_RECMASTER) == 0) { - return false; - } - - /* we cant win if we are banned */ - if (rec->node_flags & NODE_FLAGS_BANNED) { - return false; - } - - /* we cant win if we are stopped */ - if (rec->node_flags & NODE_FLAGS_STOPPED) { + if (!this_node_can_be_leader(rec)) { return false; }