diff options
author | Håkon Hallingstad <hakon@yahooinc.com> | 2022-04-19 14:54:28 +0200 |
---|---|---|
committer | Håkon Hallingstad <hakon@yahooinc.com> | 2022-04-19 14:54:28 +0200 |
commit | 7bc9a2f5b32f7bb240f91bfec165266c4f98724f (patch) | |
tree | 072caeec85af16df16d8bce442a847cff82ebd7f /clustercontroller-core | |
parent | 1254d92bd6254a70754da2f5487574add350ccb1 (diff) |
Remove redundant parameters from ZooKeeperDatabase constructor
Diffstat (limited to 'clustercontroller-core')
7 files changed, 23 insertions, 32 deletions
diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/DatabaseFactory.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/DatabaseFactory.java index 45a416fade4..31f6bbfe932 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/DatabaseFactory.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/DatabaseFactory.java @@ -1,8 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.core.database; -import com.yahoo.vespa.clustercontroller.core.ContentCluster; - /** * Database factory to enable test mocking of DB features. In practice, this * will always be {@link ZooKeeperDatabase} due to rather heavy ZK feature @@ -11,14 +9,10 @@ import com.yahoo.vespa.clustercontroller.core.ContentCluster; public interface DatabaseFactory { class Params { - ContentCluster cluster; - int nodeIndex; String dbAddress; int dbSessionTimeout; Database.DatabaseListener listener; - Params cluster(ContentCluster c) { this.cluster = c; return this; } - Params nodeIndex(int i) { this.nodeIndex = i; return this; } Params databaseAddress(String address) { this.dbAddress = address; return this; } Params databaseSessionTimeout(int timeout) { this.dbSessionTimeout = timeout; return this; } Params databaseListener(Database.DatabaseListener listener) { this.listener = listener; return this; } diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/DatabaseHandler.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/DatabaseHandler.java index 6db3c640a61..9a528baf875 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/DatabaseHandler.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/DatabaseHandler.java @@ -191,9 +191,8 @@ public class DatabaseHandler { // being called, but after receiving a database loss event. clearSessionMetaData(false); fleetControllerContext.log(logger, Level.INFO, "Setting up new ZooKeeper session at " + zooKeeperAddress); - DatabaseFactory.Params params = new DatabaseFactory.Params() - .cluster(cluster) - .nodeIndex(fleetControllerContext.id().index()) + DatabaseFactory.Params params = new DatabaseFactory + .Params() .databaseAddress(zooKeeperAddress) .databaseSessionTimeout(zooKeeperSessionTimeout) .databaseListener(dbListener); diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/MasterDataGatherer.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/MasterDataGatherer.java index 7852ab2e031..0c32d8ef6c2 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/MasterDataGatherer.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/MasterDataGatherer.java @@ -54,7 +54,7 @@ public class MasterDataGatherer { synchronized (nextMasterData) { nextMasterData.put(index, null); } - session.getData(paths.indexesOf(index), this, nodeListener, null); + session.getData(paths.indexOf(index), this, nodeListener, null); break; case NodeCreated: // How can this happen? Can one leave watches on non-existing nodes? log.log(Level.WARNING, "Fleetcontroller " + nodeIndex + ": Got unexpected ZooKeeper event NodeCreated"); @@ -85,8 +85,8 @@ public class MasterDataGatherer { int index = Integer.parseInt(node); nextMasterData.put(index, null); log.log(Level.FINE, () -> "Fleetcontroller " + nodeIndex + ": Attempting to fetch data in node '" - + paths.indexesOf(index) + "' to see vote"); - session.getData(paths.indexesOf(index), changeWatcher, nodeListener, null); + + paths.indexOf(index) + "' to see vote"); + session.getData(paths.indexOf(index), changeWatcher, nodeListener, null); // Invocation of cycleCompleted() for fully accumulated election state will happen // as soon as all getData calls have been processed. } diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/ZooKeeperDatabase.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/ZooKeeperDatabase.java index b7b4ef14117..f4b5ae2e214 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/ZooKeeperDatabase.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/ZooKeeperDatabase.java @@ -6,7 +6,6 @@ import com.yahoo.vdslib.state.NodeState; import com.yahoo.vdslib.state.State; import com.yahoo.vespa.clustercontroller.core.AnnotatedClusterState; import com.yahoo.vespa.clustercontroller.core.ClusterStateBundle; -import com.yahoo.vespa.clustercontroller.core.ContentCluster; import com.yahoo.vespa.clustercontroller.core.FleetControllerContext; import com.yahoo.vespa.clustercontroller.core.rpc.EnvelopedClusterStateBundleCodec; import com.yahoo.vespa.clustercontroller.core.rpc.SlimeClusterStateBundleCodec; @@ -44,7 +43,6 @@ public class ZooKeeperDatabase extends Database { private final ZooKeeper session; private boolean sessionOpen = true; private final FleetControllerContext context; - private final int nodeIndex; private final MasterDataGatherer masterDataGatherer; // Expected ZK znode versions. Note: these are _not_ -1 as that would match anything. // We expect the caller to invoke the load methods prior to calling any store methods. @@ -102,17 +100,16 @@ public class ZooKeeperDatabase extends Database { } } - public ZooKeeperDatabase(FleetControllerContext context, ContentCluster cluster, int nodeIndex, String address, int timeout, DatabaseListener zksl) throws IOException, KeeperException, InterruptedException { + public ZooKeeperDatabase(FleetControllerContext context, String address, int timeout, DatabaseListener zksl) throws IOException, KeeperException, InterruptedException { this.context = context; - this.nodeIndex = nodeIndex; - this.paths = new ZooKeeperPaths(cluster.getName(), nodeIndex); + this.paths = new ZooKeeperPaths(context.id()); session = new ZooKeeper(address, timeout, watcher, new ZkClientConfigBuilder().toConfig()); boolean completedOk = false; try{ this.listener = zksl; setupRoot(); context.log(log, Level.FINEST, "Asking for initial data on master election"); - masterDataGatherer = new MasterDataGatherer(session, paths, listener, nodeIndex); + masterDataGatherer = new MasterDataGatherer(session, paths, listener, context.id().index()); completedOk = true; } finally { if (!completedOk) session.close(); @@ -145,10 +142,10 @@ public class ZooKeeperDatabase extends Database { createNode(paths.startTimestamps(), new byte[0]); createNode(paths.latestVersion(), Integer.valueOf(0).toString().getBytes(utf8)); createNode(paths.publishedStateBundle(), new byte[0]); // TODO dedupe string constants - byte[] val = String.valueOf(nodeIndex).getBytes(utf8); - deleteNodeIfExists(paths.indexesOfMe()); + byte[] val = String.valueOf(context.id().index()).getBytes(utf8); + deleteNodeIfExists(paths.indexOfMe()); context.log(log, Level.INFO, "Creating ephemeral master vote node with vote to self."); - session.create(paths.indexesOfMe(), val, acl, CreateMode.EPHEMERAL); + session.create(paths.indexOfMe(), val, acl, CreateMode.EPHEMERAL); } private void deleteNodeIfExists(String path) throws KeeperException, InterruptedException { @@ -188,8 +185,8 @@ public class ZooKeeperDatabase extends Database { public boolean storeMasterVote(int wantedMasterIndex) { byte[] val = String.valueOf(wantedMasterIndex).getBytes(utf8); try{ - session.setData(paths.indexesOfMe(), val, -1); - context.log(log, Level.INFO, "Stored new vote in ephemeral node. " + nodeIndex + " -> " + wantedMasterIndex); + session.setData(paths.indexOfMe(), val, -1); + context.log(log, Level.INFO, "Stored new vote in ephemeral node. " + context.id().index() + " -> " + wantedMasterIndex); return true; } catch (InterruptedException e) { throw new RuntimeException(e); diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/ZooKeeperDatabaseFactory.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/ZooKeeperDatabaseFactory.java index 71f39135609..3263c06a95c 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/ZooKeeperDatabaseFactory.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/ZooKeeperDatabaseFactory.java @@ -13,8 +13,7 @@ public class ZooKeeperDatabaseFactory implements DatabaseFactory { @Override public Database create(Params params) throws Exception { - return new ZooKeeperDatabase(context, params.cluster, params.nodeIndex, params.dbAddress, - params.dbSessionTimeout, params.listener); + return new ZooKeeperDatabase(context, params.dbAddress, params.dbSessionTimeout, params.listener); } } diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/ZooKeeperPaths.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/ZooKeeperPaths.java index b3b6718a7bc..06a9b240175 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/ZooKeeperPaths.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/ZooKeeperPaths.java @@ -1,22 +1,24 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.core.database; +import com.yahoo.vespa.clustercontroller.core.FleetControllerId; + /** * @author hakonhall */ public class ZooKeeperPaths { private final String root; - private final int nodeIndex; + private final int myIndex; - public ZooKeeperPaths(String clusterName, int nodeIndex) { - this.root = "/vespa/fleetcontroller/" + clusterName; - this.nodeIndex = nodeIndex; + public ZooKeeperPaths(FleetControllerId id) { + this.root = "/vespa/fleetcontroller/" + id.clusterName(); + this.myIndex = id.index(); } public String root() { return root; } public String indexesRoot() { return root + "/indexes"; } - public String indexesOf(int index) { return indexesRoot() + "/" + index; } - public String indexesOfMe() { return indexesOf(nodeIndex); } + public String indexOf(int index) { return indexesRoot() + "/" + index; } + public String indexOfMe() { return indexOf(myIndex); } public String wantedStates() { return root + "/wantedstates"; } public String publishedStateBundle() { return root + "/published_state_bundle"; } public String latestVersion() { return root + "/latestversion"; } diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ZooKeeperDatabaseTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ZooKeeperDatabaseTest.java index 7d64a8f8878..1ce7586adea 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ZooKeeperDatabaseTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ZooKeeperDatabaseTest.java @@ -37,7 +37,7 @@ public class ZooKeeperDatabaseTest { closeDatabaseIfOpen(); var id = new FleetControllerId(clusterFixture.cluster.getName(), nodeIndex); var context = new TestFleetControllerContext(id); - zkDatabase = new ZooKeeperDatabase(context, clusterFixture.cluster(), nodeIndex, zkServer.getAddress(), + zkDatabase = new ZooKeeperDatabase(context, zkServer.getAddress(), (int)sessionTimeout.toMillis(), mockListener); } |