diff options
author | Tor Brede Vekterli <vekterli@verizonmedia.com> | 2021-03-18 17:45:06 +0100 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@verizonmedia.com> | 2021-03-19 13:30:31 +0100 |
commit | ba9d67c7e644347265c99d912f13b352bc2603a0 (patch) | |
tree | f9e1abfd6f2f6255844a3dc79e9bf40f15e19203 /clustercontroller-core | |
parent | a831f99cb087121e74e4ed6adb496db78909d2c3 (diff) |
Don't allow short-circuiting election phase if only one node configured if using ZK
Diffstat (limited to 'clustercontroller-core')
2 files changed, 10 insertions, 2 deletions
diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/FleetController.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/FleetController.java index 898ebe243b0..43a4209981e 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/FleetController.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/FleetController.java @@ -521,6 +521,7 @@ public class FleetController implements NodeStateOrHostInfoChangeHandler, NodeAd masterElectionHandler.setFleetControllerCount(options.fleetControllerCount); masterElectionHandler.setMasterZooKeeperCooldownPeriod(options.masterZooKeeperCooldownPeriod); + masterElectionHandler.setUsingZooKeeper(options.zooKeeperServerAddress != null && !options.zooKeeperServerAddress.isEmpty()); if (rpcServer != null) { rpcServer.setMasterElectionHandler(masterElectionHandler); 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 5f391b7b8e7..eeddf2fab75 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 @@ -25,6 +25,7 @@ public class MasterElectionHandler implements MasterInterface { private Map<Integer, Integer> nextMasterData; private long masterGoneFromZooKeeperTime; // Set to time master fleet controller disappears from zookeeper private long masterZooKeeperCooldownPeriod; // The period in ms that we won't take over unless master come back. + private boolean usingZooKeeper = false; // Unit tests may not use ZooKeeper at all. public MasterElectionHandler(int index, int totalCount, Object monitor, Timer timer) { this.monitor = monitor; @@ -42,7 +43,7 @@ public class MasterElectionHandler implements MasterInterface { public void setFleetControllerCount(int count) { totalCount = count; - if (count == 1) { + if (count == 1 && !usingZooKeeper) { masterCandidate = 0; followers = 1; nextInLineCount = 0; @@ -53,6 +54,10 @@ public class MasterElectionHandler implements MasterInterface { masterZooKeeperCooldownPeriod = period; } + public void setUsingZooKeeper(boolean usingZK) { + usingZooKeeper = usingZK; + } + @Override public boolean isMaster() { Integer master = getMaster(); @@ -106,7 +111,9 @@ public class MasterElectionHandler implements MasterInterface { public boolean watchMasterElection(DatabaseHandler database, DatabaseHandler.Context dbContext) throws InterruptedException { - if (totalCount == 1) return false; // No point in doing master election with only one node configured to be cluster controller + if (totalCount == 1 && !usingZooKeeper) { + return false; // Allow single configured node to become master implicitly if no ZK configured + } if (nextMasterData == null) { if (masterCandidate == null) { log.log(Level.FINEST, "Cluster controller " + index + ": No current master candidate. Waiting for data to do master election."); |