Search in sources :

Example 1 with Transport

use of com.yahoo.jrt.Transport in project vespa by vespa-engine.

the class MasterElectionTest method testGetMaster.

/**
 * Ignored for unknown reasons
 */
@Test
@Ignore
public void testGetMaster() throws Exception {
    startingTest("MasterElectionTest::testGetMaster");
    FleetControllerOptions options = new FleetControllerOptions("mycluster");
    // An hour
    options.masterZooKeeperCooldownPeriod = 3600 * 1000;
    setUpFleetController(3, true, options);
    waitForMaster(0);
    supervisor = new Supervisor(new Transport());
    List<Target> connections = new ArrayList<Target>();
    for (FleetController fleetController : fleetControllers) {
        int rpcPort = fleetController.getRpcPort();
        Target connection = supervisor.connect(new Spec("localhost", rpcPort));
        assertTrue(connection.isValid());
        connections.add(connection);
    }
    // A day
    timer.advanceTime(24 * 3600 * 1000);
    waitForCompleteCycles();
    Request req = new Request("getMaster");
    for (int nodeIndex = 0; nodeIndex < 3; ++nodeIndex) {
        for (int retry = 0; retry < FleetControllerTest.timeoutS * 10; ++retry) {
            req = new Request("getMaster");
            connections.get(nodeIndex).invokeSync(req, FleetControllerTest.timeoutS);
            assertEquals(req.errorMessage(), false, req.isError());
            if (req.returnValues().get(0).asInt32() == 0 && req.returnValues().get(1).asString().equals("All 3 nodes agree that 0 is current master.")) {
                break;
            }
        }
        assertEquals(req.toString(), 0, req.returnValues().get(0).asInt32());
        assertEquals(req.toString(), "All 3 nodes agree that 0 is current master.", req.returnValues().get(1).asString());
    }
    log.log(LogLevel.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.
    // 5 minutes
    timer.advanceTime(300 * 1000);
    int[] remainingNodes = { 1, 2 };
    waitForMasterReason("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.", -1, 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.
    // 60 minutes
    timer.advanceTime(3600 * 1000);
    waitForMaster(1);
    req = new Request("getMaster");
    connections.get(0).invokeSync(req, FleetControllerTest.timeoutS);
    assertEquals(req.toString(), 104, req.errorCode());
    assertEquals(req.toString(), "Connection error", req.errorMessage());
    for (int i = 0; i < FleetControllerTest.timeoutS * 10; ++i) {
        req = new Request("getMaster");
        connections.get(1).invokeSync(req, FleetControllerTest.timeoutS);
        assertEquals(req.errorMessage(), false, req.isError());
        if (req.returnValues().get(0).asInt32() != -1)
            break;
    // We may have bad timing causing node not to have realized it is master yet
    }
    assertEquals(req.toString(), 1, req.returnValues().get(0).asInt32());
    assertEquals(req.toString(), "2 of 3 nodes agree 1 is master.", req.returnValues().get(1).asString());
    for (int i = 0; i < FleetControllerTest.timeoutS * 10; ++i) {
        req = new Request("getMaster");
        connections.get(2).invokeSync(req, FleetControllerTest.timeoutS);
        assertEquals(req.errorMessage(), false, req.isError());
        if (req.returnValues().get(0).asInt32() != -1)
            break;
    }
    assertEquals(req.toString(), 1, req.returnValues().get(0).asInt32());
    assertEquals(req.toString(), "2 of 3 nodes agree 1 is master.", req.returnValues().get(1).asString());
}
Also used : Supervisor(com.yahoo.jrt.Supervisor) Target(com.yahoo.jrt.Target) ArrayList(java.util.ArrayList) Request(com.yahoo.jrt.Request) Transport(com.yahoo.jrt.Transport) Spec(com.yahoo.jrt.Spec) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with Transport

use of com.yahoo.jrt.Transport in project vespa by vespa-engine.

the class RpcServerTest method testGetMaster.

@Test
public void testGetMaster() throws Exception {
    startingTest("RpcServerTest::testGetMaster");
    FleetControllerOptions options = new FleetControllerOptions("mycluster");
    options.setStorageDistribution(new Distribution(Distribution.getDefaultDistributionConfig(2, 10)));
    setUpFleetController(true, options);
    setUpVdsNodes(true, new DummyVdsNodeOptions());
    waitForStableSystem();
    int rpcPort = fleetController.getRpcPort();
    supervisor = new Supervisor(new Transport());
    Target connection = supervisor.connect(new Spec("localhost", rpcPort));
    assertTrue(connection.isValid());
    Request req = new Request("getMaster");
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), 0, req.returnValues().get(0).asInt32());
    assertEquals(req.toString(), "All 1 nodes agree that 0 is current master.", req.returnValues().get(1).asString());
// Note that this feature is tested better in MasterElectionTest.testGetMaster as it has multiple fleetcontrollers
}
Also used : Supervisor(com.yahoo.jrt.Supervisor) Target(com.yahoo.jrt.Target) Distribution(com.yahoo.vdslib.distribution.Distribution) Request(com.yahoo.jrt.Request) Transport(com.yahoo.jrt.Transport) Spec(com.yahoo.jrt.Spec) Test(org.junit.Test)

Example 3 with Transport

use of com.yahoo.jrt.Transport in project vespa by vespa-engine.

the class RpcServerTest method testGetNodeState.

@Test
public void testGetNodeState() throws Exception {
    startingTest("RpcServerTest::testGetNodeState");
    Set<ConfiguredNode> configuredNodes = new TreeSet<>();
    for (int i = 0; i < 10; i++) configuredNodes.add(new ConfiguredNode(i, false));
    FleetControllerOptions options = new FleetControllerOptions("mycluster", configuredNodes);
    options.minRatioOfStorageNodesUp = 0;
    options.maxInitProgressTime = 30000;
    options.stableStateTimePeriod = 60000;
    setUpFleetController(true, options);
    setUpVdsNodes(true, new DummyVdsNodeOptions());
    waitForStableSystem();
    setWantedNodeState(State.DOWN, NodeType.DISTRIBUTOR, 2);
    setWantedNodeState(State.RETIRED, NodeType.STORAGE, 2);
    setWantedNodeState(State.MAINTENANCE, NodeType.STORAGE, 7);
    waitForCompleteCycle();
    timer.advanceTime(1000000);
    // Make fleet controller notice that time has changed before any disconnects
    waitForCompleteCycle();
    nodes.get(0).disconnect();
    nodes.get(3).disconnect();
    nodes.get(5).disconnect();
    waitForState("version:\\d+ distributor:10 .0.s:d .2.s:d storage:10 .1.s:m .2.s:m .7.s:m");
    timer.advanceTime(1000000);
    waitForState("version:\\d+ distributor:10 .0.s:d .2.s:d storage:10 .1.s:d .2.s:d .7.s:m");
    timer.advanceTime(1000000);
    // Make fleet controller notice that time has changed before any disconnects
    waitForCompleteCycle();
    nodes.get(3).setNodeState(new NodeState(nodes.get(3).getType(), State.INITIALIZING).setInitProgress(0.2));
    nodes.get(3).connect();
    waitForState("version:\\d+ distributor:10 .0.s:d .2.s:d storage:10 .1.s:i .1.i:0.2 .2.s:d .7.s:m");
    int rpcPort = fleetController.getRpcPort();
    supervisor = new Supervisor(new Transport());
    Target connection = supervisor.connect(new Spec("localhost", rpcPort));
    assertTrue(connection.isValid());
    Request req = new Request("getNodeState");
    req.parameters().add(new StringValue("distributor"));
    req.parameters().add(new Int32Value(0));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals(State.DOWN, NodeState.deserialize(NodeType.DISTRIBUTOR, req.returnValues().get(0).asString()).getState());
    NodeState reported = NodeState.deserialize(NodeType.DISTRIBUTOR, req.returnValues().get(1).asString());
    assertTrue(req.returnValues().get(1).asString(), reported.getState().oneOf("d-"));
    assertEquals("", req.returnValues().get(2).asString());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("distributor"));
    req.parameters().add(new Int32Value(2));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals(State.DOWN, NodeState.deserialize(NodeType.DISTRIBUTOR, req.returnValues().get(0).asString()).getState());
    assertEquals("t:946080000", req.returnValues().get(1).asString());
    assertEquals(State.DOWN, NodeState.deserialize(NodeType.DISTRIBUTOR, req.returnValues().get(2).asString()).getState());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("distributor"));
    req.parameters().add(new Int32Value(4));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals("", req.returnValues().get(0).asString());
    assertEquals("t:946080000", req.returnValues().get(1).asString());
    assertEquals("", req.returnValues().get(2).asString());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("distributor"));
    req.parameters().add(new Int32Value(15));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.METHOD_FAILED, req.errorCode());
    assertEquals("No node distributor.15 exists in cluster mycluster", req.errorMessage());
    assertFalse(req.toString(), req.checkReturnTypes("ssss"));
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("storage"));
    req.parameters().add(new Int32Value(1));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals("s:i i:0.2", req.returnValues().get(0).asString());
    assertEquals("s:i i:0.2", req.returnValues().get(1).asString());
    assertEquals("", req.returnValues().get(2).asString());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("storage"));
    req.parameters().add(new Int32Value(2));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals(State.DOWN, NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(0).asString()).getState());
    reported = NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(1).asString());
    assertTrue(req.returnValues().get(1).asString(), reported.getState().oneOf("d-"));
    assertEquals(State.RETIRED, NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(2).asString()).getState());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("storage"));
    req.parameters().add(new Int32Value(5));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals("", req.returnValues().get(0).asString());
    assertEquals("t:946080000", req.returnValues().get(1).asString());
    assertEquals("", req.returnValues().get(2).asString());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("storage"));
    req.parameters().add(new Int32Value(7));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals(State.MAINTENANCE, NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(0).asString()).getState());
    assertEquals("t:946080000", req.returnValues().get(1).asString());
    assertEquals(State.MAINTENANCE, NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(2).asString()).getState());
}
Also used : Supervisor(com.yahoo.jrt.Supervisor) NodeState(com.yahoo.vdslib.state.NodeState) ConfiguredNode(com.yahoo.vdslib.distribution.ConfiguredNode) Request(com.yahoo.jrt.Request) Target(com.yahoo.jrt.Target) TreeSet(java.util.TreeSet) Int32Value(com.yahoo.jrt.Int32Value) Transport(com.yahoo.jrt.Transport) Spec(com.yahoo.jrt.Spec) StringValue(com.yahoo.jrt.StringValue) Test(org.junit.Test)

Example 4 with Transport

use of com.yahoo.jrt.Transport in project vespa by vespa-engine.

the class RpcServerTest method setWantedNodeState.

private void setWantedNodeState(State newState, NodeType nodeType, int nodeIndex) {
    int rpcPort = fleetController.getRpcPort();
    if (supervisor == null) {
        supervisor = new Supervisor(new Transport());
    }
    Target connection = supervisor.connect(new Spec("localhost", rpcPort));
    assertTrue(connection.isValid());
    Node node = new Node(nodeType, nodeIndex);
    NodeState newNodeState = new NodeState(nodeType, newState);
    Request req = new Request("setNodeState");
    req.parameters().add(new StringValue("storage/cluster.mycluster/" + node.getType().toString() + "/" + node.getIndex()));
    req.parameters().add(new StringValue(newNodeState.serialize(true)));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("s"));
}
Also used : Supervisor(com.yahoo.jrt.Supervisor) Target(com.yahoo.jrt.Target) NodeState(com.yahoo.vdslib.state.NodeState) Node(com.yahoo.vdslib.state.Node) ConfiguredNode(com.yahoo.vdslib.distribution.ConfiguredNode) Request(com.yahoo.jrt.Request) Transport(com.yahoo.jrt.Transport) Spec(com.yahoo.jrt.Spec) StringValue(com.yahoo.jrt.StringValue)

Example 5 with Transport

use of com.yahoo.jrt.Transport in project vespa by vespa-engine.

the class ConfigProxyRpcServerTest method setup.

@Before
public void setup() {
    proxyServer = ProxyServer.createTestServer(new ConfigSourceSet(address));
    rpcServer = new ConfigProxyRpcServer(proxyServer, new Supervisor(new Transport()), null);
}
Also used : Supervisor(com.yahoo.jrt.Supervisor) ConfigSourceSet(com.yahoo.config.subscription.ConfigSourceSet) Transport(com.yahoo.jrt.Transport) Before(org.junit.Before)

Aggregations

Supervisor (com.yahoo.jrt.Supervisor)18 Transport (com.yahoo.jrt.Transport)18 Spec (com.yahoo.jrt.Spec)13 Target (com.yahoo.jrt.Target)11 Request (com.yahoo.jrt.Request)10 Test (org.junit.Test)8 StringValue (com.yahoo.jrt.StringValue)7 ConfiguredNode (com.yahoo.vdslib.distribution.ConfiguredNode)4 NodeState (com.yahoo.vdslib.state.NodeState)4 Distribution (com.yahoo.vdslib.distribution.Distribution)3 Node (com.yahoo.vdslib.state.Node)3 ConfigSourceSet (com.yahoo.config.subscription.ConfigSourceSet)2 Mirror (com.yahoo.jrt.slobrok.api.Mirror)2 SlobrokList (com.yahoo.jrt.slobrok.api.SlobrokList)2 ClusterState (com.yahoo.vdslib.state.ClusterState)2 TreeSet (java.util.TreeSet)2 ConfigserverConfig (com.yahoo.cloud.config.ConfigserverConfig)1 Int32Value (com.yahoo.jrt.Int32Value)1 IMirror (com.yahoo.jrt.slobrok.api.IMirror)1 Register (com.yahoo.jrt.slobrok.api.Register)1