For standard master failover (with voting), it is necessary that the majority of nodes is still reachable and can answer questions about which node is master. Add a predicate verifying that this is still true.
Signed-off-by: Klaus Aehlig <[email protected]> --- lib/bootstrap.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/bootstrap.py b/lib/bootstrap.py index 51924e1..4f0aecf 100644 --- a/lib/bootstrap.py +++ b/lib/bootstrap.py @@ -1290,3 +1290,24 @@ def GatherMasterVotes(node_names): vote_list.sort(key=lambda x: (x[1], x[0]), reverse=True) return vote_list + + +def MajorityHealthy(): + """Check if the majority of nodes is healthy + + Gather master votes from all nodes known to this node; + return True if a strict majority of nodes is reachable and + has some opinion on which node is master. Note that this will + not guarantee any node to win an election but it ensures that + a standard master-failover is still possible. + + """ + node_names = ssconf.SimpleStore().GetNodeList() + node_count = len(node_names) + vote_list = GatherMasterVotes(node_names) + if vote_list is None: + return False + total_votes = sum([count for (node, count) in vote_list if node is not None]) + logging.info("Total %d nodes, %d votes: %s", node_count, total_votes, + vote_list) + return 2 * total_votes > node_count -- 2.6.0.rc2.230.g3dd15c0
