diff options
author | Harald Musum <musum@yahooinc.com> | 2022-08-30 10:04:13 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2022-08-30 10:04:13 +0200 |
commit | 2d3deea19851a168c19046b74517a82ef1859449 (patch) | |
tree | 930179cfdcbe2b37b6064a8b77f9c045eb4195f9 /clustercontroller-core | |
parent | 95b8488c614ac13cac912cedce6af6c239126b11 (diff) |
Split out method
Diffstat (limited to 'clustercontroller-core')
-rw-r--r-- | clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/MasterElectionHandler.java | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/MasterElectionHandler.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/MasterElectionHandler.java index 637aca16ee7..3c4959ea5d3 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/MasterElectionHandler.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/MasterElectionHandler.java @@ -77,16 +77,15 @@ public class MasterElectionHandler implements MasterInterface { @Override public Integer getMaster() { - // If too few followers there can be no master - if (2 * followers <= totalCount) { + if (tooFewFollowersToHaveAMaster()) { return null; } - // If all are following master candidate, it is master if it exists. + // If all are following master candidate, it is master if it exists. if (followers == totalCount) { return masterCandidate; } - // If not all are following we only accept master candidate if old master - // disappeared sufficient time ago + // If not all are following we only accept master candidate if old master + // disappeared sufficient time ago if (masterGoneFromZooKeeperTime + masterZooKeeperCooldownPeriod > timer.getCurrentTimeInMillis()) { return null; } @@ -97,8 +96,7 @@ public class MasterElectionHandler implements MasterInterface { if (masterCandidate == null) { return "There is currently no master candidate."; } - // If too few followers there can be no master - if (2 * followers <= totalCount) { + if (tooFewFollowersToHaveAMaster()) { return "More than half of the nodes must agree for there to be a master. Only " + followers + " of " + totalCount + " nodes agree on current master candidate (" + masterCandidate + ")."; } @@ -118,6 +116,10 @@ public class MasterElectionHandler implements MasterInterface { return followers + " of " + totalCount + " nodes agree " + masterCandidate + " is master."; } + private boolean tooFewFollowersToHaveAMaster() { + return 2 * followers <= totalCount; + } + public boolean isAmongNthFirst(int first) { return (nextInLineCount < first); } public boolean watchMasterElection(DatabaseHandler database, @@ -256,7 +258,7 @@ public class MasterElectionHandler implements MasterInterface { if (master.intValue() == index) sb.append(" (This node)"); sb.append("</p>"); } else { - if (2 * followers <= totalCount) { + if (tooFewFollowersToHaveAMaster()) { sb.append("<p>There is currently no master. Less than half the fleet controllers (") .append(followers).append(") are following master candidate ").append(masterCandidate) .append(".</p>"); @@ -267,7 +269,7 @@ public class MasterElectionHandler implements MasterInterface { .append(" before electing new master unless all possible master candidates are online.</p>"); } } - if ((master == null || master.intValue() != index) && nextInLineCount < stateGatherCount) { + if ((master == null || master != index) && nextInLineCount < stateGatherCount) { sb.append("<p>As we are number ").append(nextInLineCount) .append(" in line for taking over as master, we're gathering state from nodes.</p>"); sb.append("<p><font color=\"red\">As we are not the master, we don't know about nodes current system state" |