Search in sources :

Example 16 with VoldemortServer

use of voldemort.server.VoldemortServer in project voldemort by voldemort.

the class AdminRebalanceTest method testRebalanceStateChange.

@Test(timeout = 60000)
public void testRebalanceStateChange() throws IOException {
    try {
        startFourNodeRW();
        // Test 1) Normal case where-in all are up
        adminClient.rebalanceOps.rebalanceStateChange(currentCluster, finalCluster, servers[2].getMetadataStore().getStoreDefList(), servers[2].getMetadataStore().getStoreDefList(), plans, false, false, true, true, true);
        List<Integer> nodesChecked = Lists.newArrayList();
        for (RebalanceTaskInfo plan : plans) {
            nodesChecked.add(plan.getStealerId());
            assertEquals(servers[plan.getStealerId()].getMetadataStore().getRebalancerState(), new RebalancerState(Lists.newArrayList(plan)));
        }
        List<Integer> allNodes = Lists.newArrayList(Utils.nodeListToNodeIdList(Lists.newArrayList(currentCluster.getNodes())));
        allNodes.removeAll(nodesChecked);
        // Check all other nodes
        for (int nodeId : allNodes) {
            assertEquals(servers[nodeId].getMetadataStore().getRebalancerState(), new RebalancerState(new ArrayList<RebalanceTaskInfo>()));
        }
        // Clean-up everything
        cleanUpAllState();
        // Test 2) Add a plan before hand on one of them which should
        // trigger a rollback
        servers[3].getMetadataStore().getRebalancerState().update(new RebalanceTaskInfo(3, 0, new HashMap<String, List<Integer>>(), currentCluster));
        try {
            adminClient.rebalanceOps.rebalanceStateChange(currentCluster, finalCluster, servers[2].getMetadataStore().getStoreDefList(), servers[2].getMetadataStore().getStoreDefList(), plans, false, false, true, true, true);
            fail("Should have thrown an exception since we added state before hand");
        } catch (VoldemortRebalancingException e) {
        }
        // except node 3
        for (VoldemortServer server : servers) {
            if (server.getMetadataStore().getNodeId() != 3) {
                assertEquals(server.getMetadataStore().getRebalancerState(), new RebalancerState(new ArrayList<RebalanceTaskInfo>()));
            }
        }
        // Clean-up everything
        cleanUpAllState();
        // Test 3) Shut one node down
        ServerTestUtils.stopVoldemortServer(servers[3]);
        servers[3] = null;
        try {
            adminClient.rebalanceOps.rebalanceStateChange(currentCluster, finalCluster, servers[2].getMetadataStore().getStoreDefList(), servers[2].getMetadataStore().getStoreDefList(), plans, false, false, true, true, true);
            fail("Should have thrown an exception since we added state before hand");
        } catch (VoldemortRebalancingException e) {
        }
        // exception node 3
        for (VoldemortServer server : servers) {
            if (server != null) {
                assertEquals(server.getMetadataStore().getRebalancerState(), new RebalancerState(new ArrayList<RebalanceTaskInfo>()));
            }
        }
    } finally {
        shutDown();
    }
}
Also used : VoldemortRebalancingException(voldemort.server.rebalance.VoldemortRebalancingException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RebalancerState(voldemort.server.rebalance.RebalancerState) VoldemortServer(voldemort.server.VoldemortServer) Test(org.junit.Test)

Example 17 with VoldemortServer

use of voldemort.server.VoldemortServer in project voldemort by voldemort.

the class AdminRebalanceTest method testRebalanceNodeRORW.

@Test(timeout = 60000)
public void testRebalanceNodeRORW() throws IOException, InterruptedException {
    try {
        startFourNodeRORW();
        int numChunks = 5;
        for (StoreDefinition storeDef : Lists.newArrayList(storeDef1, storeDef2)) {
            buildROStore(storeDef, numChunks);
        }
        // Set into rebalancing state
        for (RebalanceTaskInfo partitionPlan : plans) {
            getServer(partitionPlan.getStealerId()).getMetadataStore().put(MetadataStore.SERVER_STATE_KEY, MetadataStore.VoldemortState.REBALANCING_MASTER_SERVER);
            getServer(partitionPlan.getStealerId()).getMetadataStore().put(MetadataStore.REBALANCING_STEAL_INFO, new RebalancerState(Lists.newArrayList(RebalanceTaskInfo.create(partitionPlan.toJsonString()))));
            getServer(partitionPlan.getStealerId()).getMetadataStore().put(MetadataStore.REBALANCING_SOURCE_CLUSTER_XML, partitionPlan.getInitialCluster());
        }
        // Actually run it
        try {
            for (RebalanceTaskInfo currentPlan : plans) {
                int asyncId = adminClient.rebalanceOps.rebalanceNode(currentPlan);
                assertNotSame("Got a valid rebalanceAsyncId", -1, asyncId);
                getAdminClient().rpcOps.waitForCompletion(currentPlan.getStealerId(), asyncId, 300, TimeUnit.SECONDS);
                // Test that plan has been removed from the list
                assertFalse(getServer(currentPlan.getStealerId()).getMetadataStore().getRebalancerState().getAll().contains(currentPlan));
            }
        } catch (Exception e) {
            e.printStackTrace();
            fail("Should not throw any exceptions");
        }
        // Test 1) Change one of the rebalance partitions info to force a
        // failure
        servers[3].getMetadataStore().getRebalancerState().update(new RebalanceTaskInfo(3, 0, new HashMap<String, List<Integer>>(), currentCluster));
        try {
            adminClient.rebalanceOps.rebalanceStateChange(currentCluster, finalCluster, servers[2].getMetadataStore().getStoreDefList(), servers[2].getMetadataStore().getStoreDefList(), plans, true, true, true, true, true);
            fail("Should have thrown an exception since we added state before hand");
        } catch (VoldemortRebalancingException e) {
        }
        // except node 3
        for (VoldemortServer server : servers) {
            if (server.getMetadataStore().getNodeId() != 3) {
                assertEquals(server.getMetadataStore().getRebalancerState(), new RebalancerState(new ArrayList<RebalanceTaskInfo>()));
                assertEquals(server.getMetadataStore().getServerStateUnlocked(), MetadataStore.VoldemortState.NORMAL_SERVER);
            }
            assertEquals(server.getMetadataStore().getCluster(), currentCluster);
        }
        checkRO(currentCluster);
        // Clean-up everything
        cleanUpAllState();
        // Test 2 ) Add another store to trigger a failure
        servers[2].getMetadataStore().put(MetadataStore.STORES_KEY, Lists.newArrayList(storeDef1, storeDef2, storeDef3, storeDef4, new StoreDefinitionBuilder().setName("test5").setType(ReadOnlyStorageConfiguration.TYPE_NAME).setKeySerializer(new SerializerDefinition("string")).setValueSerializer(new SerializerDefinition("string")).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(2).setPreferredReads(1).setRequiredReads(1).setPreferredWrites(1).setRequiredWrites(1).build()));
        try {
            adminClient.rebalanceOps.rebalanceStateChange(currentCluster, finalCluster, servers[2].getMetadataStore().getStoreDefList(), servers[2].getMetadataStore().getStoreDefList(), plans, true, true, true, true, true);
            fail("Should have thrown an exception since we added state before hand");
        } catch (VoldemortRebalancingException e) {
        }
        Thread.sleep(1000);
        for (VoldemortServer server : servers) {
            assertEquals(server.getMetadataStore().getRebalancerState(), new RebalancerState(new ArrayList<RebalanceTaskInfo>()));
            assertEquals(server.getMetadataStore().getServerStateUnlocked(), MetadataStore.VoldemortState.NORMAL_SERVER);
            assertEquals(server.getMetadataStore().getCluster(), currentCluster);
        }
        checkRO(currentCluster);
        // Clean-up everything
        cleanUpAllState();
        // Put back server 2 back to normal state
        servers[2].getMetadataStore().put(MetadataStore.STORES_KEY, Lists.newArrayList(storeDef1, storeDef2, storeDef3, storeDef4));
        // Test 3) Everything should work
        adminClient.rebalanceOps.rebalanceStateChange(currentCluster, finalCluster, servers[2].getMetadataStore().getStoreDefList(), servers[2].getMetadataStore().getStoreDefList(), plans, true, true, true, true, true);
        List<Integer> nodesChecked = Lists.newArrayList();
        for (RebalanceTaskInfo plan : plans) {
            nodesChecked.add(plan.getStealerId());
            assertEquals(servers[plan.getStealerId()].getMetadataStore().getRebalancerState(), new RebalancerState(Lists.newArrayList(plan)));
            assertEquals(servers[plan.getStealerId()].getMetadataStore().getServerStateUnlocked(), MetadataStore.VoldemortState.REBALANCING_MASTER_SERVER);
            assertEquals(servers[plan.getStealerId()].getMetadataStore().getCluster(), finalCluster);
        }
        List<Integer> allNodes = Lists.newArrayList(Utils.nodeListToNodeIdList(Lists.newArrayList(currentCluster.getNodes())));
        allNodes.removeAll(nodesChecked);
        // Check all other nodes
        for (int nodeId : allNodes) {
            assertEquals(servers[nodeId].getMetadataStore().getRebalancerState(), new RebalancerState(new ArrayList<RebalanceTaskInfo>()));
            assertEquals(servers[nodeId].getMetadataStore().getServerStateUnlocked(), MetadataStore.VoldemortState.NORMAL_SERVER);
            assertEquals(servers[nodeId].getMetadataStore().getCluster(), finalCluster);
        }
        checkRO(finalCluster);
    } finally {
        shutDown();
    }
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) VoldemortRebalancingException(voldemort.server.rebalance.VoldemortRebalancingException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VoldemortServer(voldemort.server.VoldemortServer) AlreadyRebalancingException(voldemort.server.rebalance.AlreadyRebalancingException) VoldemortRebalancingException(voldemort.server.rebalance.VoldemortRebalancingException) VoldemortException(voldemort.VoldemortException) IOException(java.io.IOException) StoreDefinition(voldemort.store.StoreDefinition) RebalancerState(voldemort.server.rebalance.RebalancerState) SerializerDefinition(voldemort.serialization.SerializerDefinition) Test(org.junit.Test)

Example 18 with VoldemortServer

use of voldemort.server.VoldemortServer in project voldemort by voldemort.

the class AdminRebalanceTest method cleanUpAllState.

private void cleanUpAllState() {
    for (VoldemortServer server : servers) {
        if (server != null) {
            // Put back the old cluster metadata
            server.getMetadataStore().put(MetadataStore.CLUSTER_KEY, currentCluster);
            // Clear all the rebalancing state
            server.getMetadataStore().cleanAllRebalancingState();
        }
    }
}
Also used : VoldemortServer(voldemort.server.VoldemortServer)

Example 19 with VoldemortServer

use of voldemort.server.VoldemortServer in project voldemort by voldemort.

the class OfflineStateTest method tearDown.

@After
public void tearDown() throws IOException {
    adminClient.close();
    for (VoldemortServer server : servers) {
        ServerTestUtils.stopVoldemortServer(server);
    }
    socketStoreFactory.close();
}
Also used : VoldemortServer(voldemort.server.VoldemortServer) After(org.junit.After)

Example 20 with VoldemortServer

use of voldemort.server.VoldemortServer in project voldemort by voldemort.

the class OfflineStateTest method testStartingOfflineServeresManually.

/**
     * This test simulates the situation when Voldemort server is turn off accidentally.
     * We manually modify local metadata config files in order to boot up server in offline mode.
     */
@Test
public void testStartingOfflineServeresManually() throws Exception {
    VoldemortServer server = getVoldemortServer(0);
    server.stop();
    String[] metadatafileNames = { "partition.streaming.enabled", "readonly.fetch.enabled", "server.state", "slop.streaming.enabled" };
    PrintWriter writer = null;
    for (String fileName : metadatafileNames) {
        //modify .temp files
        writer = new PrintWriter(new File(server.getVoldemortConfig().getVoldemortHome() + "/config/.temp/" + fileName));
        if (fileName != "server.state")
            writer.print("false");
        else
            writer.print("OFFLINE_SERVER");
        writer.close();
        //delete .version files
        Files.delete(Paths.get(server.getVoldemortConfig().getVoldemortHome() + "/config/.version/" + fileName));
    }
    verifyNewServer(server);
}
Also used : VoldemortServer(voldemort.server.VoldemortServer) File(java.io.File) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

VoldemortServer (voldemort.server.VoldemortServer)86 Properties (java.util.Properties)36 VoldemortConfig (voldemort.server.VoldemortConfig)24 Test (org.junit.Test)23 Node (voldemort.cluster.Node)23 Before (org.junit.Before)21 SocketStoreFactory (voldemort.store.socket.SocketStoreFactory)20 ClientRequestExecutorPool (voldemort.store.socket.clientrequest.ClientRequestExecutorPool)18 ClientConfig (voldemort.client.ClientConfig)17 ByteArray (voldemort.utils.ByteArray)17 ArrayList (java.util.ArrayList)16 After (org.junit.After)15 StoreDefinition (voldemort.store.StoreDefinition)15 SocketStoreClientFactory (voldemort.client.SocketStoreClientFactory)14 Cluster (voldemort.cluster.Cluster)14 IOException (java.io.IOException)11 HashMap (java.util.HashMap)11 AdminClient (voldemort.client.protocol.admin.AdminClient)11 VectorClock (voldemort.versioning.VectorClock)10 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)9