From 3c810a80546353e7ef011a397bdb294e2bdd7888 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Tue, 30 Aug 2022 11:23:59 +0200 Subject: Add some convenience methods, reindent --- .../core/MasterElectionHandler.java | 24 ++++++++++++---------- .../core/status/LegacyIndexPageRequestHandler.java | 1 - 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'clustercontroller-core/src') 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 3c4959ea5d3..dfc328346bb 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 @@ -35,11 +35,9 @@ public class MasterElectionHandler implements MasterInterface { this.index = index; this.totalCount = totalCount; this.nextInLineCount = Integer.MAX_VALUE; - // Only a given set of nodes can ever become master - if (index > (totalCount - 1) / 2) { + if (cannotBecomeMaster()) context.log(logger, Level.FINE, () -> "We can never become master and will always stay a follower."); - } - // Tag current time as when we have not seen any other master. Make sure we're not taking over at once for master that is on the way down + // Tag current time as when we have not seen any other master. Make sure we're not taking over at once for master that is on the way down masterGoneFromZooKeeperTime = timer.getCurrentTimeInMillis(); } @@ -133,8 +131,8 @@ public class MasterElectionHandler implements MasterInterface { } return false; // Nothing have happened since last time. } - // Move next data to temporary, such that we don't need to keep lock, and such that we don't retry - // if we happen to fail processing the data. + // Move next data to temporary, such that we don't need to keep lock, and such that we don't retry + // if we happen to fail processing the data. Map state; context.log(logger, Level.INFO, "Handling new master election, as we have received " + nextMasterData.size() + " entries"); synchronized (monitor) { @@ -186,8 +184,7 @@ public class MasterElectionHandler implements MasterInterface { database.setMasterVote(dbContext, first.getKey()); } } - // Only a given set of nodes can ever become master - if (index <= (totalCount - 1) / 2) { + if (canBecomeMaster()) { int ourPosition = 0; for (Map.Entry entry : state.entrySet()) { if (entry.getKey() != index) { @@ -207,6 +204,11 @@ public class MasterElectionHandler implements MasterInterface { return true; } + // Only a given set of nodes can ever become master + private boolean canBecomeMaster() {return index <= (totalCount - 1) / 2;} + + private boolean cannotBecomeMaster() {return ! canBecomeMaster();} + private static String toString(Map data) { StringBuilder sb = new StringBuilder(); for (Map.Entry entry : data.entrySet()) { @@ -255,7 +257,7 @@ public class MasterElectionHandler implements MasterInterface { Integer master = getMaster(); if (master != null) { sb.append("

Current cluster controller master is node " + master + "."); - if (master.intValue() == index) sb.append(" (This node)"); + if (master == index) sb.append(" (This node)"); sb.append("

"); } else { if (tooFewFollowersToHaveAMaster()) { @@ -276,12 +278,12 @@ public class MasterElectionHandler implements MasterInterface { + " or wanted states, so some statistics below may be stale. Look at status page on master " + "for updated data.

"); } - if (index * 2 > totalCount) { + if (cannotBecomeMaster()) { sb.append("

As lowest index fleet controller is prioritized to become master, and more than half " + "of the fleet controllers need to be available to select a master, we can never become master.

"); } - // Debug data + // Debug data sb.append("

Master election handler internal state:") .append("
Index: " + index) .append("
Fleet controller count: " + totalCount) diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/status/LegacyIndexPageRequestHandler.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/status/LegacyIndexPageRequestHandler.java index d0aeb639ea2..0611d754b69 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/status/LegacyIndexPageRequestHandler.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/status/LegacyIndexPageRequestHandler.java @@ -75,7 +75,6 @@ public class LegacyIndexPageRequestHandler implements StatusPageServer.RequestHa .append(" | Event log") .append(" ]

\n"); content.append(""); - //content.append(""); content.append("
UTC time when creating this page:").append(RealTimer.printDateNoMilliSeconds(currentTime, tz)).append("
Fleetcontroller version:" + Vtag.V_TAG_PKG + "
Cluster controller uptime:" + RealTimer.printDuration(currentTime - startedTime) + "
"); if (masterElectionHandler.isAmongNthFirst(options.stateGatherCount)) { // Table overview of all the nodes -- cgit v1.2.3