diff options
author | Harald Musum <musum@verizonmedia.com> | 2021-02-08 22:44:59 +0100 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2021-02-08 22:44:59 +0100 |
commit | 414568759416e98f41b248660b78465e67c8268a (patch) | |
tree | e11d7e0ad3a1ce02bd8a6bedcf590a6270f5fc20 /clustercontroller-core | |
parent | b2092944431231d010f33fbffb5f29b5f8623610 (diff) |
Minor cleanup, no functional changes
Diffstat (limited to 'clustercontroller-core')
9 files changed, 44 insertions, 62 deletions
diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/CasWriteFailed.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/CasWriteFailed.java index c62d8d4bcd5..92db85a80ad 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/CasWriteFailed.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/CasWriteFailed.java @@ -1,4 +1,4 @@ -// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.core.database; /** @@ -8,7 +8,7 @@ package com.yahoo.vespa.clustercontroller.core.database; * we last read it, and that the information we hold may be stale. * * Upon receiving such an exception, the caller should no longer assume it holds - * up-to-date information and should drop and roles that build on top of such an + * up-to-date information and should drop any roles that build on top of such an * assumption (such as leadership sessions). */ public class CasWriteFailed extends RuntimeException { diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/Database.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/Database.java index 4b0461200a4..06aa9547f4e 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/Database.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/Database.java @@ -1,4 +1,4 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. 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.vdslib.state.Node; @@ -8,22 +8,17 @@ import com.yahoo.vespa.clustercontroller.core.ClusterStateBundle; import java.util.Map; /** - * This is an abstract class defining the functions needed by a database back end for the fleetcontroller. + * Abstract class defining the functions needed by a database back end for the fleetcontroller. */ public abstract class Database { /** Interface used for database to send events of stuff happening during requests. */ public interface DatabaseListener { - public void handleZooKeeperSessionDown(); - public void handleMasterData(Map<Integer, Integer> data); + void handleZooKeeperSessionDown(); + void handleMasterData(Map<Integer, Integer> data); } /** - * Used when initiating shutdown to avoid zookeeper layer reporting errors afterwards. - */ - public abstract void stopErrorReporting(); - - /** * Close this session, and release all resources it has used. */ public abstract void close(); 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 3e7b98fe3fb..c32f2fe71cd 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,4 +1,4 @@ -// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. 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; @@ -18,15 +18,10 @@ public interface DatabaseFactory { Database.DatabaseListener listener; Params cluster(ContentCluster c) { this.cluster = c; return this; } - ContentCluster cluster() { return cluster; } Params nodeIndex(int i) { this.nodeIndex = i; return this; } - int nodeIndex() { return nodeIndex; } Params databaseAddress(String address) { this.dbAddress = address; return this; } - String databaseAddress() { return dbAddress; } Params databaseSessionTimeout(int timeout) { this.dbSessionTimeout = timeout; return this; } - int databaseSessionTimeout() { return dbSessionTimeout; } Params databaseListener(Database.DatabaseListener listener) { this.listener = listener; return this; } - Database.DatabaseListener databaseListener() { return listener; } } Database create(Params params) throws Exception; 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 bb0692c2e24..5bad5716eb9 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 @@ -1,7 +1,6 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.core.database; -import java.util.logging.Level; import com.yahoo.vdslib.state.Node; import com.yahoo.vdslib.state.NodeState; import com.yahoo.vdslib.state.State; @@ -18,6 +17,7 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.util.Map; import java.util.TreeMap; +import java.util.logging.Level; import java.util.logging.Logger; /** @@ -26,7 +26,7 @@ import java.util.logging.Logger; */ public class DatabaseHandler { - private static Logger log = Logger.getLogger(DatabaseHandler.class.getName()); + private static final Logger log = Logger.getLogger(DatabaseHandler.class.getName()); public interface Context { ContentCluster getCluster(); @@ -35,7 +35,7 @@ public class DatabaseHandler { NodeStateOrHostInfoChangeHandler getNodeStateUpdateListener(); } - private class Data { + private static class Data { Integer masterVote; Integer lastSystemStateVersion; Map<Node, NodeState> wantedStates; @@ -80,7 +80,7 @@ public class DatabaseHandler { private final Object databaseMonitor = new Object(); private Database database; - private DatabaseListener dbListener = new DatabaseListener(); + private final DatabaseListener dbListener = new DatabaseListener(); private final Data currentlyStored = new Data(); private final Data pendingStore = new Data(); private long lastZooKeeperConnectionAttempt = 0; @@ -95,12 +95,13 @@ public class DatabaseHandler { this.nodeIndex = ourIndex; pendingStore.masterVote = ourIndex; // To begin with we'll vote for ourselves. this.monitor = monitor; + // TODO: Require non-null, not possible now since at least ClusterFeedBlockTest usese null address this.zooKeeperAddress = zooKeeperAddress; } private boolean isDatabaseClosedSafe() { synchronized (databaseMonitor) { - return database == null || database.isClosed(); + return isClosed(); } } @@ -133,13 +134,12 @@ public class DatabaseHandler { currentlyStored.clear(); pendingStore.clear(); pendingStore.masterVote = currentVote; - log.log(Level.FINE, "Cleared session metadata. Pending master vote is now " - + pendingStore.masterVote); + log.log(Level.FINE, "Cleared session metadata. Pending master vote is now " + pendingStore.masterVote); } public void setZooKeeperAddress(String address) { if (address == null && zooKeeperAddress == null) return; - if (address != null && zooKeeperAddress != null && address.equals(zooKeeperAddress)) return; + if (address != null && address.equals(zooKeeperAddress)) return; if (zooKeeperAddress != null) { log.log(Level.INFO, "Fleetcontroller " + nodeIndex + ": " + (address == null ? "Stopped using ZooKeeper." : "Got new ZooKeeper address to use: " + address)); } @@ -200,7 +200,6 @@ public class DatabaseHandler { public boolean doNextZooKeeperTask(Context context) throws InterruptedException { boolean didWork = false; synchronized (monitor) { - if (zooKeeperAddress == null) return false; // If not using zookeeper no work to be done if (lostZooKeeperConnectionEvent) { log.log(Level.FINE, "Fleetcontroller " + nodeIndex + ": doNextZooKeeperTask(): lost connection"); context.getFleetController().lostDatabaseConnection(); 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 fef93aede1a..0f16ffbaf76 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 @@ -1,34 +1,32 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.core.database; import org.apache.zookeeper.data.Stat; import org.apache.zookeeper.*; +import java.nio.charset.StandardCharsets; import java.util.logging.Logger; import java.util.*; -import java.nio.charset.Charset; import java.util.logging.Level; public class MasterDataGatherer { - private static Logger log = Logger.getLogger(MasterDataGatherer.class.getName()); - private static Charset utf8 = Charset.forName("UTF8"); + private static final Logger log = Logger.getLogger(MasterDataGatherer.class.getName()); /** Utility function for getting node index from path name of the ephemeral nodes. */ private static int getIndex(String nodeName) { assert(nodeName != null); int lastSlash = nodeName.lastIndexOf('/'); if (lastSlash <= 1) { - System.err.println("Unexpected path to nodename: '" + nodeName + "'."); - assert(lastSlash > 1); + throw new IllegalArgumentException("Unexpected path to nodename: '" + nodeName + "'."); } return Integer.parseInt(nodeName.substring(lastSlash + 1)); } private final String zooKeeperRoot; // The root path in zookeeper, typically /vespa/fleetcontroller/<clustername>/ - private Map<Integer, Integer> masterData = new TreeMap<Integer, Integer>(); // The master state last reported to the fleetcontroller - private final Map<Integer, Integer> nextMasterData = new TreeMap<Integer, Integer>(); // Temporary master state while gathering new info from zookeeper + private Map<Integer, Integer> masterData = new TreeMap<>(); // The master state last reported to the fleetcontroller + private final Map<Integer, Integer> nextMasterData = new TreeMap<>(); // Temporary master state while gathering new info from zookeeper private final AsyncCallback.ChildrenCallback childListener = new DirCallback(); // Dir change listener private final NodeDataCallback nodeListener = new NodeDataCallback(); // Ephemeral node data change listener @@ -36,11 +34,7 @@ public class MasterDataGatherer { private final ZooKeeper session; private final int nodeIndex; - /* - private boolean seenDirChangeDuringRun = false; // Set to true if we got a dir event while a refetch is happening - private final Set<Integer> seenDataChangeDuringRun = new TreeSet<Integer>(); // Sets the indexes that got a data change event while fetching is already running - */ - private Watcher changeWatcher = new ChangeWatcher(); + private final Watcher changeWatcher = new ChangeWatcher(); /** * This class is used to handle node children changed and node data changed events from the zookeeper server. @@ -83,7 +77,7 @@ public class MasterDataGatherer { */ private class DirCallback implements AsyncCallback.ChildrenCallback { public void processResult(int version, String path, Object context, List<String> nodes) { - if (nodes == null) nodes = new LinkedList<String>(); + if (nodes == null) nodes = new LinkedList<>(); log.log(Level.INFO, "Fleetcontroller " + nodeIndex + ": Got node list response from " + path + " version " + version + " with " + nodes.size() + " nodes"); synchronized (nextMasterData) { nextMasterData.clear(); @@ -103,8 +97,8 @@ public class MasterDataGatherer { /** The node data callback class is responsible for fetching new votes from fleetcontrollers that have altered their vote. */ private class NodeDataCallback implements AsyncCallback.DataCallback { - public void processResult(int code, String path, Object context, byte[] rawdata, Stat stat) { - String data = rawdata == null ? null : new String(rawdata, utf8); + public void processResult(int code, String path, Object context, byte[] rawData, Stat stat) { + String data = rawData == null ? null : new String(rawData, StandardCharsets.UTF_8); log.log(Level.INFO, "Fleetcontroller " + nodeIndex + ": Got vote data from path " + path + " with code " + code + " and data " + data); @@ -165,7 +159,7 @@ public class MasterDataGatherer { /** Calling restart, ignores what we currently know and starts another cycle. Typically called after reconnecting to ZooKeeperServer. */ public void restart() { synchronized (nextMasterData) { - masterData = new TreeMap<Integer, Integer>(); + masterData = new TreeMap<>(); nextMasterData.clear(); session.getChildren(zooKeeperRoot + "indexes", changeWatcher, childListener, null); } @@ -180,7 +174,7 @@ public class MasterDataGatherer { // for(Integer i : nextMasterData.keySet()) { System.err.println(i + " -> " + nextMasterData.get(i)); } return; } - masterData = new TreeMap<Integer, Integer>(nextMasterData); + masterData = new TreeMap<>(nextMasterData); copy = masterData; } log.log(Level.FINE, "Fleetcontroller " + nodeIndex + ": Got new master data, sending it on"); 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 bba417b1333..f1e0b6d1239 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 @@ -1,4 +1,4 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. 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.AnnotatedClusterState; @@ -9,6 +9,8 @@ import com.yahoo.vespa.clustercontroller.core.rpc.SlimeClusterStateBundleCodec; import org.apache.zookeeper.*; import org.apache.zookeeper.data.Stat; import org.apache.zookeeper.data.ACL; + +import java.nio.charset.StandardCharsets; import java.util.logging.Level; import com.yahoo.vdslib.state.NodeState; import com.yahoo.vdslib.state.State; @@ -23,8 +25,8 @@ import java.nio.charset.Charset; public class ZooKeeperDatabase extends Database { - private static Logger log = Logger.getLogger(ZooKeeperDatabase.class.getName()); - private static Charset utf8 = Charset.forName("UTF8"); + private static final Logger log = Logger.getLogger(ZooKeeperDatabase.class.getName()); + private static final Charset utf8 = StandardCharsets.UTF_8; private static final List<ACL> acl = ZooDefs.Ids.OPEN_ACL_UNSAFE; private final String zooKeeperRoot; @@ -93,7 +95,7 @@ public class ZooKeeperDatabase extends Database { } state = watchedEvent.getState(); } - }; + } public ZooKeeperDatabase(ContentCluster cluster, int nodeIndex, String address, int timeout, Database.DatabaseListener zksl) throws IOException, KeeperException, InterruptedException { this.nodeIndex = nodeIndex; @@ -111,7 +113,7 @@ public class ZooKeeperDatabase extends Database { } } - private void createNode(String prefix, String nodename, byte value[]) throws KeeperException, InterruptedException { + private void createNode(String prefix, String nodename, byte[] value) throws KeeperException, InterruptedException { try{ if (session.exists(prefix + nodename, false) != null) { log.log(Level.FINE, "Fleetcontroller " + nodeIndex + ": Zookeeper node '" + prefix + nodename + "' already exists. Not creating it"); @@ -126,7 +128,7 @@ public class ZooKeeperDatabase extends Database { } private void setupRoot() throws KeeperException, InterruptedException { - String pathElements[] = zooKeeperRoot.substring(1).split("/"); + String[] pathElements = zooKeeperRoot.substring(1).split("/"); String path = ""; for (String elem : pathElements) { path += "/" + elem; @@ -137,7 +139,7 @@ public class ZooKeeperDatabase extends Database { createNode(zooKeeperRoot, "starttimestamps", new byte[0]); createNode(zooKeeperRoot, "latestversion", Integer.valueOf(0).toString().getBytes(utf8)); createNode(zooKeeperRoot, "published_state_bundle", new byte[0]); // TODO dedupe string constants - byte val[] = String.valueOf(nodeIndex).getBytes(utf8); + byte[] val = String.valueOf(nodeIndex).getBytes(utf8); deleteNodeIfExists(getMyIndexPath()); log.log(Level.INFO, "Fleetcontroller " + nodeIndex + ": Creating ephemeral master vote node with vote to self."); @@ -184,7 +186,7 @@ public class ZooKeeperDatabase extends Database { } public boolean storeMasterVote(int wantedMasterIndex) throws InterruptedException { - byte val[] = String.valueOf(wantedMasterIndex).getBytes(utf8); + byte[] val = String.valueOf(wantedMasterIndex).getBytes(utf8); try{ session.setData(getMyIndexPath(), val, -1); log.log(Level.INFO, "Fleetcontroller " + nodeIndex + ": Stored new vote in ephemeral node. " + nodeIndex + " -> " + wantedMasterIndex); @@ -197,7 +199,7 @@ public class ZooKeeperDatabase extends Database { return false; } public boolean storeLatestSystemStateVersion(int version) throws InterruptedException { - byte data[] = Integer.toString(version).getBytes(utf8); + byte[] data = Integer.toString(version).getBytes(utf8); try{ log.log(Level.INFO, String.format("Fleetcontroller %d: Storing new cluster state version in ZooKeeper: %d", nodeIndex, version)); var stat = session.setData(zooKeeperRoot + "latestversion", data, lastKnownStateVersionZNodeVersion); @@ -247,7 +249,7 @@ public class ZooKeeperDatabase extends Database { sb.append(node.toString()).append(':').append(toStore.serialize(true)).append('\n'); } } - byte val[] = sb.toString().getBytes(utf8); + byte[] val = sb.toString().getBytes(utf8); try{ log.log(Level.FINE, "Fleetcontroller " + nodeIndex + ": Storing wanted states at '" + zooKeeperRoot + "wantedstates'"); session.setData(zooKeeperRoot + "wantedstates", val, -1); 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 64dfcccebc9..41e72806270 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 @@ -1,8 +1,6 @@ -// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. 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; - public class ZooKeeperDatabaseFactory implements DatabaseFactory { @Override diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ClusterFeedBlockTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ClusterFeedBlockTest.java index e7477e2289c..75a197ec77a 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ClusterFeedBlockTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ClusterFeedBlockTest.java @@ -35,8 +35,6 @@ public class ClusterFeedBlockTest extends FleetControllerTest { private Supervisor supervisor; private FleetController ctrl; private DummyCommunicator communicator; - private EventLog eventLog; - private int dummyConfigGeneration = 2; @Before public void setUp() { @@ -52,7 +50,7 @@ public class ClusterFeedBlockTest extends FleetControllerTest { communicator = new DummyCommunicator(nodes, timer); MetricUpdater metricUpdater = new MetricUpdater(new NoMetricReporter(), options.fleetControllerIndex); - eventLog = new EventLog(timer, metricUpdater); + EventLog eventLog = new EventLog(timer, metricUpdater); ContentCluster cluster = new ContentCluster(options.clusterName, options.nodes, options.storageDistribution, options.minStorageNodesUp, options.minRatioOfStorageNodesUp); NodeStateGatherer stateGatherer = new NodeStateGatherer(timer, timer, eventLog); @@ -128,6 +126,7 @@ public class ClusterFeedBlockTest extends FleetControllerTest { assertTrue(ctrl.getClusterStateBundle().clusterFeedIsBlocked()); // Increase cheese allowance. Should now automatically unblock since reported usage is lower. + int dummyConfigGeneration = 2; ctrl.updateOptions(createOptions(mapOf(usage("cheese", 0.9), usage("wine", 0.4))), dummyConfigGeneration); ctrl.tick(); // Options propagation ctrl.tick(); // State recomputation diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DatabaseTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DatabaseTest.java index 327a0e229fc..850484188a2 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DatabaseTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DatabaseTest.java @@ -24,7 +24,7 @@ import static org.junit.Assert.assertTrue; public class DatabaseTest extends FleetControllerTest { - private static Logger log = Logger.getLogger(DatabaseTest.class.getName()); + private static final Logger log = Logger.getLogger(DatabaseTest.class.getName()); // Note: different semantics than FleetControllerTest.setWantedState private void setWantedState(Node n, NodeState ns, Map<Node, NodeState> wantedStates) { |