summaryrefslogtreecommitdiffstats
path: root/clustercontroller-core
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2022-08-30 11:23:59 +0200
committerHarald Musum <musum@yahooinc.com>2022-08-30 11:23:59 +0200
commit3c810a80546353e7ef011a397bdb294e2bdd7888 (patch)
tree62cc5ca079dfc368e7fd66de75ed6ed60cbd79da /clustercontroller-core
parent302251d45e1dc4f63580dba7d55b455f4d86d5b1 (diff)
Add some convenience methods, reindent
Diffstat (limited to 'clustercontroller-core')
-rw-r--r--clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/MasterElectionHandler.java24
-rw-r--r--clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/status/LegacyIndexPageRequestHandler.java1
2 files changed, 13 insertions, 12 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 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<Integer, Integer> 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<Integer, Integer> 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<Integer, Integer> data) {
StringBuilder sb = new StringBuilder();
for (Map.Entry<Integer, Integer> entry : data.entrySet()) {
@@ -255,7 +257,7 @@ public class MasterElectionHandler implements MasterInterface {
Integer master = getMaster();
if (master != null) {
sb.append("<p>Current cluster controller master is node " + master + ".");
- if (master.intValue() == index) sb.append(" (This node)");
+ if (master == index) sb.append(" (This node)");
sb.append("</p>");
} 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.</font></p>");
}
- if (index * 2 > totalCount) {
+ if (cannotBecomeMaster()) {
sb.append("<p>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.</p>");
}
- // Debug data
+ // Debug data
sb.append("<p><font size=\"-1\" color=\"grey\">Master election handler internal state:")
.append("<br>Index: " + index)
.append("<br>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(" | <a href=\"#eventlog\">Event log</a>")
.append(" ]</font></p>\n");
content.append("<table><tr><td>UTC time when creating this page:</td><td align=\"right\">").append(RealTimer.printDateNoMilliSeconds(currentTime, tz)).append("</td></tr>");
- //content.append("<tr><td>Fleetcontroller version:</td><td align=\"right\">" + Vtag.V_TAG_PKG + "</td></tr/>");
content.append("<tr><td>Cluster controller uptime:</td><td align=\"right\">" + RealTimer.printDuration(currentTime - startedTime) + "</td></tr></table>");
if (masterElectionHandler.isAmongNthFirst(options.stateGatherCount)) {
// Table overview of all the nodes