mirror of
https://github.com/samba-team/samba.git
synced 2025-03-11 16:58:40 +03:00
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 <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
parent
94b546c268
commit
7baadfe27e
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user