summaryrefslogtreecommitdiffstats
path: root/clustercontroller-core
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2023-06-05 17:11:55 +0200
committerHarald Musum <musum@yahooinc.com>2023-06-05 17:11:55 +0200
commitaa21f8b53457c94144a969fb60ce1075b80fcecb (patch)
tree701e39c9ef8324346fd62be1cc5d9c08dbfe64e7 /clustercontroller-core
parentabf620e10fb21a1295a2f6ca69b4c592d824a385 (diff)
Remove support for RPC method getMaster, only used in tests
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/rpc/RpcServer.java18
-rw-r--r--clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MasterElectionTest.java116
-rw-r--r--clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/RpcServerTest.java20
4 files changed, 2 insertions, 176 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 01240da2fc8..68b132e34b4 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
@@ -77,30 +77,6 @@ public class MasterElectionHandler implements MasterInterface {
return masterCandidate;
}
- public String getMasterReason() {
- if (masterCandidate == null) {
- return "There is currently no master candidate.";
- }
- if (tooFewFollowersToHaveAMaster()) {
- return "More than half of the nodes must agree for there to be a master. Only " + followers + " of "
- + totalCount + " nodes agree on current master candidate (" + masterCandidate + ").";
- }
- // If all are following master candidate, it is master if it exists.
- if (followers == totalCount) {
- return "All " + totalCount + " nodes agree that " + masterCandidate + " is current master.";
- }
-
- // If not all are following we only accept master candidate if old master
- // disappeared sufficient time ago
- if (masterGoneFromZooKeeperTime + masterZooKeeperCooldownPeriod > timer.getCurrentTimeInMillis()) {
- return followers + " of " + totalCount + " nodes agree " + masterCandidate + " should be master, "
- + "but old master cooldown period of " + masterZooKeeperCooldownPeriod + " ms has not passed yet. "
- + "To ensure it has got time to realize it is no longer master before we elect a new one, "
- + "currently there is no master.";
- }
- return followers + " of " + totalCount + " nodes agree " + masterCandidate + " is master.";
- }
-
private boolean tooFewFollowersToHaveAMaster() {
return 2 * followers <= totalCount;
}
diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/rpc/RpcServer.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/rpc/RpcServer.java
index f1ff52816a3..fa8550efb93 100644
--- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/rpc/RpcServer.java
+++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/rpc/RpcServer.java
@@ -3,7 +3,6 @@ package com.yahoo.vespa.clustercontroller.core.rpc;
import com.yahoo.jrt.Acceptor;
import com.yahoo.jrt.ErrorCode;
-import com.yahoo.jrt.Int32Value;
import com.yahoo.jrt.ListenFailedException;
import com.yahoo.jrt.Method;
import com.yahoo.jrt.Request;
@@ -121,13 +120,7 @@ public class RpcServer {
}
public void addMethods() {
- Method m = new Method("getMaster", "", "is", this::queueRpcRequest);
- m.methodDesc("Get index of current fleetcontroller master");
- m.returnDesc(0, "masterindex", "The index of the current master according to this node, or -1 if there is none.");
- m.returnDesc(1, "description", "A textual field, used for additional information, such as why there is no master.");
- supervisor.addMethod(m);
-
- m = new Method("getSystemState", "", "ss", this::queueRpcRequest);
+ Method m = new Method("getSystemState", "", "ss", this::queueRpcRequest);
m.methodDesc("Get nodeState of all nodes and the system itself");
m.returnDesc(0, "systemstate", "nodeState string of system");
m.returnDesc(1, "nodestate", "nodeState-string for distributor and storage-nodes");
@@ -175,15 +168,6 @@ public class RpcServer {
handledAnyRequests = true;
}
try{
- if (req.methodName().equals("getMaster")) {
- log.log(Level.FINE, "Resolving RPC getMaster request");
- Integer master = masterHandler.getMaster();
- String masterReason = masterHandler.getMasterReason();
- req.returnValues().add(new Int32Value(master == null ? -1 : master));
- req.returnValues().add(new StringValue(masterReason == null ? "No reason given" : masterReason));
- req.returnRequest();
- continue;
- }
if (!masterHandler.isMaster()) {
throw new IllegalStateException("Refusing to answer RPC calls as we are not the master fleetcontroller.");
}
diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MasterElectionTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MasterElectionTest.java
index 93a96be71a0..af7a0a4b92c 100644
--- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MasterElectionTest.java
+++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MasterElectionTest.java
@@ -1,10 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.core;
-import com.yahoo.jrt.Request;
-import com.yahoo.jrt.Spec;
import com.yahoo.jrt.Supervisor;
-import com.yahoo.jrt.Target;
import com.yahoo.jrt.Transport;
import com.yahoo.vdslib.state.ClusterState;
import com.yahoo.vdslib.state.NodeState;
@@ -16,16 +13,13 @@ import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.extension.ExtendWith;
+
import java.time.Instant;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
-import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -281,114 +275,6 @@ public class MasterElectionTest extends FleetControllerTest {
waitForMaster(1);
}
- private void waitForNoMasterWithExpectedReason(String reason, List<Target> connections, int[] nodes) {
- Objects.requireNonNull(reason, "reason cannot be null");
- Instant endTime = Instant.now().plus(timeout());
- while (Instant.now().isBefore(endTime)) {
- boolean allOk = true;
- for (int node : nodes) {
- Request req = new Request("getMaster");
- connections.get(node).invokeSync(req, timeout());
- if (req.isError()) {
- allOk = false;
- break;
- }
- if (req.returnValues().get(0).asInt32() != -1) { // -1 means no master, which we are waiting for
- allOk = false;
- break;
- }
- if ( ! reason.equals(req.returnValues().get(1).asString())) {
- allOk = false;
- break;
- }
- }
- if (allOk) return;
- try { Thread.sleep(100); } catch (InterruptedException e) { /* ignore */ }
- }
- throw new IllegalStateException("Did not get master reason '" + reason + "' within timeout of " + timeout());
- }
-
- @Test
- void testGetMaster() throws Exception {
- FleetControllerOptions.Builder options = defaultOptions();
- options.setMasterZooKeeperCooldownPeriod(3600 * 1000); // An hour
- FakeTimer timer = new FakeTimer();
- setUpFleetControllers(3, timer, options);
- waitForMaster(0);
-
- List<Target> connections = new ArrayList<>();
- for (FleetController fleetController : fleetControllers) {
- int rpcPort = fleetController.getRpcPort();
- Target connection = supervisor.connect(new Spec("localhost", rpcPort));
- assertTrue(connection.isValid());
- connections.add(connection);
- }
-
- timer.advanceTime(24 * 3600 * 1000); // A day
- waitForCompleteCycles();
-
- Request req = new Request("getMaster");
-
- long maxRetries = timeout().toMillis() / 100;
- for (int nodeIndex = 0; nodeIndex < 3; ++nodeIndex) {
- for (int retry = 0; retry < maxRetries; ++retry) {
- req = new Request("getMaster");
- connections.get(nodeIndex).invokeSync(req, timeout());
- assertFalse(req.isError(), req.errorMessage());
- if (req.returnValues().get(0).asInt32() == 0 &&
- req.returnValues().get(1).asString().equals("All 3 nodes agree that 0 is current master.")) {
- break;
- }
- }
- assertEquals(0, req.returnValues().get(0).asInt32(), req.toString());
- assertEquals("All 3 nodes agree that 0 is current master.", req.returnValues().get(1).asString(), req.toString());
- }
-
- log.log(Level.INFO, "SHUTTING DOWN FLEET CONTROLLER 0");
- fleetControllers.get(0).shutdown();
- // Wait until fc 1 & 2 votes for node 1
- waitForCompleteCycle(1);
- waitForCompleteCycle(2);
- // 5 minutes is not long enough period to wait before letting this node be master.
- timer.advanceTime(300 * 1000); // 5 minutes
-
- int[] remainingNodes = {1, 2};
- waitForNoMasterWithExpectedReason(
- "2 of 3 nodes agree 1 should be master, but old master cooldown period of 3600000 ms has not passed yet. To ensure it has got time to realize it is no longer master before we elect a new one, currently there is no master.",
- connections,
- remainingNodes);
- // Verify that fc 1 is not master, and the correct reasons for why not
- assertFalse(fleetControllers.get(1).isMaster());
-
- // But after an hour it should become one.
- timer.advanceTime(3600 * 1000); // 60 minutes
- waitForMaster(1);
-
- req = new Request("getMaster");
- connections.get(0).invokeSync(req, timeout());
- assertEquals(104, req.errorCode(), req.toString());
- assertEquals("Connection error", req.errorMessage(), req.toString());
-
- for (int i = 0; i < maxRetries; ++i) {
- req = new Request("getMaster");
- connections.get(1).invokeSync(req, timeout());
- assertFalse(req.isError(), req.errorMessage());
- if (req.returnValues().get(0).asInt32() != -1) break;
- // We may have bad timing causing node not to have realized it is master yet
- }
- assertEquals(1, req.returnValues().get(0).asInt32(), req.toString());
- assertEquals("2 of 3 nodes agree 1 is master.", req.returnValues().get(1).asString(), req.toString());
-
- for (int i = 0; i < maxRetries; ++i) {
- req = new Request("getMaster");
- connections.get(2).invokeSync(req, timeout());
- assertFalse(req.isError(), req.errorMessage());
- if (req.returnValues().get(0).asInt32() != -1) break;
- }
- assertEquals(1, req.returnValues().get(0).asInt32(), req.toString());
- assertEquals("2 of 3 nodes agree 1 is master.", req.returnValues().get(1).asString(), req.toString());
- }
-
@Test
void testReconfigure() throws Exception {
FleetControllerOptions.Builder options = defaultOptions();
diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/RpcServerTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/RpcServerTest.java
index e75ade7309c..82422762e88 100644
--- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/RpcServerTest.java
+++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/RpcServerTest.java
@@ -462,26 +462,6 @@ public class RpcServerTest extends FleetControllerTest {
waitForState("version:\\d+ distributor:10 storage:10 .9.s:m");
}
- @Test
- void testGetMaster() throws Exception {
- FleetControllerOptions.Builder options = defaultOptions();
- options.setStorageDistribution(new Distribution(Distribution.getDefaultDistributionConfig(2, 10)));
- setUpFleetController(timer, options);
- setUpVdsNodes(timer);
- waitForStableSystem();
-
- int rpcPort = fleetController().getRpcPort();
- Target connection = supervisor.connect(new Spec("localhost", rpcPort));
- assertTrue(connection.isValid());
-
- Request req = new Request("getMaster");
- connection.invokeSync(req, timeout());
- assertEquals(0, req.returnValues().get(0).asInt32(), req.toString());
- assertEquals("All 1 nodes agree that 0 is current master.", req.returnValues().get(1).asString(), req.toString());
-
- // Note that this feature is tested better in MasterElectionTest.testGetMaster as it has multiple fleetcontrollers
- }
-
private Request setNodeState(String node, NodeState newNodeState, Target connection) {
return setNodeState(node, newNodeState.serialize(true), connection);
}