Package voldemort.server.rebalance

Examples of voldemort.server.rebalance.RebalancerState


                    } else if(metadataKey.compareTo(MetadataStore.REBALANCING_STEAL_INFO) == 0) {
                        if(!Utils.isReadableFile(metadataValue))
                            throw new VoldemortException("Rebalancing steal info file path incorrect");
                        String rebalancingStealInfoJsonString = FileUtils.readFileToString(new File(metadataValue));
                        RebalancerState state = RebalancerState.create(rebalancingStealInfoJsonString);
                        executeSetMetadata(nodeId,
                                           adminClient,
                                           MetadataStore.REBALANCING_STEAL_INFO,
                                           state.toJsonString());
                    } else {
                        throw new VoldemortException("Incorrect metadata key");
                    }
                }
            } else if(options.has("update-store-defs")) {
View Full Code Here


                           + MetadataStore.VoldemortState.NORMAL_SERVER);
        executeSetMetadata(nodeId,
                           adminClient,
                           MetadataStore.SERVER_STATE_KEY,
                           MetadataStore.VoldemortState.NORMAL_SERVER.toString());
        RebalancerState state = RebalancerState.create("[]");
        System.out.println("Cleaning up " + MetadataStore.REBALANCING_STEAL_INFO + " to "
                           + state.toJsonString());
        executeSetMetadata(nodeId,
                           adminClient,
                           MetadataStore.REBALANCING_STEAL_INFO,
                           state.toJsonString());
        System.out.println("Cleaning up " + MetadataStore.REBALANCING_SOURCE_CLUSTER_XML
                           + " to empty string");
        executeSetMetadata(nodeId, adminClient, MetadataStore.REBALANCING_SOURCE_CLUSTER_XML, "");
    }
View Full Code Here

            servers[partitionPlan.getStealerId()].getMetadataStore()
                                                 .put(MetadataStore.SERVER_STATE_KEY,
                                                      MetadataStore.VoldemortState.REBALANCING_MASTER_SERVER);
            servers[partitionPlan.getStealerId()].getMetadataStore()
                                                 .put(MetadataStore.REBALANCING_STEAL_INFO,
                                                      new RebalancerState(Lists.newArrayList(partitionPlan)));
            servers[partitionPlan.getStealerId()].getMetadataStore()
                                                 .put(MetadataStore.REBALANCING_SOURCE_CLUSTER_XML,
                                                      currentCluster);

            // update orginal storedefs
View Full Code Here

            List<Integer> partitionIds = partition;

            HashMap<String, List<Integer>> storeToReplicaToPartitionList = Maps.newHashMap();
            storeToReplicaToPartitionList.put("test", partitionIds);

            return ByteUtils.getBytes(new RebalancerState(Arrays.asList(new RebalanceTaskInfo(0,
                                                                                              (int) Math.random() * 5,
                                                                                              storeToReplicaToPartitionList,
                                                                                              ServerTestUtils.getLocalCluster(1)))).toJsonString(),
                                      "UTF-8");
        }
View Full Code Here

                               + MetadataStore.VoldemortState.NORMAL_SERVER);
            doMetaSet(adminClient,
                      nodeIds,
                      MetadataStore.SERVER_STATE_KEY,
                      MetadataStore.VoldemortState.NORMAL_SERVER.toString());
            RebalancerState state = RebalancerState.create("[]");
            System.out.println("Cleaning up " + MetadataStore.REBALANCING_STEAL_INFO + " to "
                               + state.toJsonString());
            doMetaSet(adminClient,
                      nodeIds,
                      MetadataStore.REBALANCING_STEAL_INFO,
                      state.toJsonString());
            System.out.println("Cleaning up " + MetadataStore.REBALANCING_SOURCE_CLUSTER_XML
                               + " to empty string");
            doMetaSet(adminClient, nodeIds, MetadataStore.REBALANCING_SOURCE_CLUSTER_XML, "");
        }
View Full Code Here

                } else if(metaKey.equals(MetadataStore.REBALANCING_STEAL_INFO)) {
                    if(!Utils.isReadableFile(metaFile)) {
                        throw new VoldemortException("Rebalancing steal info file path incorrect");
                    }
                    String rebalancingStealInfoJsonString = FileUtils.readFileToString(new File(metaFile));
                    RebalancerState state = RebalancerState.create(rebalancingStealInfoJsonString);
                    doMetaSet(adminClient, nodeIds, metaKey, state.toJsonString());
                } else {
                    throw new VoldemortException("Incorrect metadata key");
                }
            } else if(meta.size() == 4) {
                // set metadata pair cluster.xml, stores.xml
View Full Code Here

            // Put a plan different from the plan that we actually want to
            // execute
            int incorrectStealerId = (plans.get(0).getStealerId() + 1) % 3;
            getServer(plans.get(0).getStealerId()).getMetadataStore()
                                                  .put(MetadataStore.REBALANCING_STEAL_INFO,
                                                       new RebalancerState(Lists.newArrayList(new RebalanceTaskInfo(incorrectStealerId,
                                                                                                                    plans.get(0)
                                                                                                                         .getDonorId(),
                                                                                                                    plans.get(0)
                                                                                                                         .getStoreToPartitionIds(),
                                                                                                                    plans.get(0)
                                                                                                                         .getInitialCluster()))));

            try {
                adminClient.rebalanceOps.rebalanceNode(plans.get(0));
                fail("Should have thrown an exception since the two plans eventhough have the same donor are different");
            } catch(VoldemortException e) {

            }

            // Set the rebalance info on the stealer node
            for(RebalanceTaskInfo partitionPlan: plans) {
                getServer(partitionPlan.getStealerId()).getMetadataStore()
                                                       .put(MetadataStore.REBALANCING_STEAL_INFO,
                                                            new RebalancerState(Lists.newArrayList(RebalanceTaskInfo.create(partitionPlan.toJsonString()))));
            }

            // Update the cluster metadata on all three nodes
            for(VoldemortServer server: servers) {
                server.getMetadataStore().put(MetadataStore.CLUSTER_KEY, finalCluster);
            }

            // Actually run it
            try {
                for(RebalanceTaskInfo currentPlan: plans) {
                    int asyncId = adminClient.rebalanceOps.rebalanceNode(currentPlan);

                    // Try submitting the same job again, should throw
                    // AlreadyRebalancingException
                    try {
                        adminClient.rebalanceOps.rebalanceNode(currentPlan);
                        fail("Should have thrown an exception since it is already rebalancing");
                    } catch(AlreadyRebalancingException e) {}

                    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");
            }

            Store<ByteArray, byte[], byte[]> storeTest0 = getStore(0, "test2");
            Store<ByteArray, byte[], byte[]> storeTest2 = getStore(2, "test2");

            Store<ByteArray, byte[], byte[]> storeTest20 = getStore(2, "test");

            // Primary is on Node 0 and not on Node 1
            for(Entry<ByteArray, byte[]> entry: primaryEntriesMoved.entrySet()) {
                assertSame("entry should be present at store", 1, storeTest0.get(entry.getKey(),
                                                                                 null).size());
                assertEquals("entry value should match",
                             new String(entry.getValue()),
                             new String(storeTest0.get(entry.getKey(), null).get(0).getValue()));

                // Check in other store
                assertSame("entry should be present in store test2 ",
                           1,
                           storeTest20.get(entry.getKey(), null).size());
                assertEquals("entry value should match",
                             new String(entry.getValue()),
                             new String(storeTest20.get(entry.getKey(), null).get(0).getValue()));
            }

            // Secondary is on Node 2 and not on Node 0
            for(Entry<ByteArray, byte[]> entry: secondaryEntriesMoved.entrySet()) {
                assertSame("entry should be present at store", 1, storeTest2.get(entry.getKey(),
                                                                                 null).size());
                assertEquals("entry value should match",
                             new String(entry.getValue()),
                             new String(storeTest2.get(entry.getKey(), null).get(0).getValue()));
            }

            // All servers should be back to normal state
            for(VoldemortServer server: servers) {
                assertEquals(server.getMetadataStore().getRebalancerState(),
                             new RebalancerState(new ArrayList<RebalanceTaskInfo>()));
                assertEquals(server.getMetadataStore().getServerStateUnlocked(),
                             MetadataStore.VoldemortState.NORMAL_SERVER);
            }
        } finally {
            shutDown();
View Full Code Here

                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());
            }

            // Update the cluster metadata on all three nodes
            for(VoldemortServer server: servers) {
                server.getMetadataStore().put(MetadataStore.CLUSTER_KEY, finalCluster);
            }

            // 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");
            }

            Store<ByteArray, byte[], byte[]> storeTest0 = getStore(0, "test2");
            Store<ByteArray, byte[], byte[]> storeTest1 = getStore(1, "test2");
            Store<ByteArray, byte[], byte[]> storeTest3 = getStore(3, "test2");

            Store<ByteArray, byte[], byte[]> storeTest00 = getStore(0, "test");
            Store<ByteArray, byte[], byte[]> storeTest30 = getStore(3, "test");

            // Primary
            for(Entry<ByteArray, byte[]> entry: primaryEntriesMoved.entrySet()) {

                // Test 2
                // Present on Node 0
                assertSame("entry should be present at store", 1, storeTest0.get(entry.getKey(),
                                                                                 null).size());
                assertEquals("entry value should match",
                             new String(entry.getValue()),
                             new String(storeTest0.get(entry.getKey(), null).get(0).getValue()));

                // Present on Node 1
                assertSame("entry should be present at store", 1, storeTest1.get(entry.getKey(),
                                                                                 null).size());
                assertEquals("entry value should match",
                             new String(entry.getValue()),
                             new String(storeTest1.get(entry.getKey(), null).get(0).getValue()));

                // Present on Node 3
                assertSame("entry should be present at store", 1, storeTest3.get(entry.getKey(),
                                                                                 null).size());
                assertEquals("entry value should match",
                             new String(entry.getValue()),
                             new String(storeTest3.get(entry.getKey(), null).get(0).getValue()));

                // Test
                // Present on Node 0
                assertSame("entry should be present at store", 1, storeTest00.get(entry.getKey(),
                                                                                  null).size());
                assertEquals("entry value should match",
                             new String(entry.getValue()),
                             new String(storeTest00.get(entry.getKey(), null).get(0).getValue()));

                // Present on Node 3
                assertSame("entry should be present at store", 1, storeTest30.get(entry.getKey(),
                                                                                  null).size());
                assertEquals("entry value should match",
                             new String(entry.getValue()),
                             new String(storeTest30.get(entry.getKey(), null).get(0).getValue()));

            }

            // Secondary
            for(Entry<ByteArray, byte[]> entry: secondaryEntriesMoved.entrySet()) {

                // Test 2
                // Present on Node 0
                assertSame("entry should be present at store", 1, storeTest0.get(entry.getKey(),
                                                                                 null).size());
                assertEquals("entry value should match",
                             new String(entry.getValue()),
                             new String(storeTest0.get(entry.getKey(), null).get(0).getValue()));

                // Present on Node 3
                assertSame("entry should be present at store", 1, storeTest3.get(entry.getKey(),
                                                                                 null).size());
                assertEquals("entry value should match",
                             new String(entry.getValue()),
                             new String(storeTest3.get(entry.getKey(), null).get(0).getValue()));

                // Test
                // Present on Node 3
                assertSame("entry should be present at store", 1, storeTest30.get(entry.getKey(),
                                                                                  null).size());
                assertEquals("entry value should match",
                             new String(entry.getValue()),
                             new String(storeTest30.get(entry.getKey(), null).get(0).getValue()));

            }

            // Tertiary
            for(Entry<ByteArray, byte[]> entry: tertiaryEntriesMoved.entrySet()) {

                // Test 2
                // Present on Node 3
                assertSame("entry should be present at store", 1, storeTest3.get(entry.getKey(),
                                                                                 null).size());
                assertEquals("entry value should match",
                             new String(entry.getValue()),
                             new String(storeTest3.get(entry.getKey(), null).get(0).getValue()));
            }

            // All servers should be back to normal state
            for(VoldemortServer server: servers) {
                assertEquals(server.getMetadataStore().getRebalancerState(),
                             new RebalancerState(new ArrayList<RebalanceTaskInfo>()));
                assertEquals(server.getMetadataStore().getServerStateUnlocked(),
                             MetadataStore.VoldemortState.NORMAL_SERVER);
            }
        } finally {
            shutDown();
View Full Code Here

                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");
            }

            // Check if files have been copied
            for (StoreDefinition storeDef: Lists.newArrayList(storeDef1, storeDef2)) {
                String storeName = storeDef.getName();
               
                for (RebalanceTaskInfo currentPlan: plans) {
                    MetadataStore metadataStore = getServer(currentPlan.getStealerId()).getMetadataStore();
                    int nodeId = metadataStore.getNodeId();
                    int zoneId = metadataStore.getCluster().getNodeById(nodeId).getZoneId();
                    StoreRoutingPlan storeRoutingPlan = new StoreRoutingPlan(metadataStore.getCluster(),
                                                                             storeDef);
                    File currentDir = new File(((ReadOnlyStorageEngine) getStore(currentPlan.getStealerId(),
                                                                                 storeName)).getCurrentDirPath());
                    if (currentPlan.getPartitionStores().contains(storeDef.getName())) {
                        for (Integer partitionId: currentPlan.getStoreToPartitionIds().get(storeName)) {
                            int zoneNary = -1;
                            // If computing zoneNary for a partition throws an exception
                            // it means we don't want to consider that partition.
                            try {
                                zoneNary = storeRoutingPlan.getZoneNaryForNodesPartition(zoneId,
                                                                                         nodeId,
                                                                                         partitionId);
                            } catch (VoldemortException ve) {
                                continue;
                            }
                            if (zoneNary < storeDef.getReplicationFactor()) {
                                for (int chunkId = 0; chunkId < numChunks; chunkId++) {
                                    assertTrue(new File(currentDir, partitionId + "_" + zoneNary + "_"
                                                                    + chunkId + ".data").exists());
                                    assertTrue(new File(currentDir, partitionId + "_" + zoneNary + "_"
                                                                    + chunkId + ".index").exists());
                                }
                            }
                        }
                    }
                }
            }

            // All servers should be back to normal state
            for(VoldemortServer server: servers) {
                assertEquals(server.getMetadataStore().getRebalancerState(),
                             new RebalancerState(new ArrayList<RebalanceTaskInfo>()));
                assertEquals(server.getMetadataStore().getServerStateUnlocked(),
                             MetadataStore.VoldemortState.NORMAL_SERVER);
            }

            // Test the "cluster + swap" changes
            // Test 1) Fail some swap by adding a dummy store
            servers[2].getMetadataStore()
                      .put(MetadataStore.STORES_KEY,
                           Lists.newArrayList(storeDef1,
                                              storeDef2,
                                              new StoreDefinitionBuilder()
                                                                          .setName("test3")
                                                                          .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,
                                                              false,
                                                              true,
                                                              true);
                fail("Should have thrown an exception since one node doesn't have the store");
            } catch(VoldemortException e) {}

            servers[2].getMetadataStore().put(MetadataStore.STORES_KEY,
                                              Lists.newArrayList(storeDef1, storeDef2));

            // Test that all servers are still using the old cluster and have
            // swapped successfully
            checkRO(currentCluster);

            // Test 2) All passes scenario
            adminClient.rebalanceOps.rebalanceStateChange(currentCluster,
                                                          finalCluster,
                                                          servers[2].getMetadataStore()
                                                                    .getStoreDefList(),
                                                          servers[2].getMetadataStore()
                                                                    .getStoreDefList(),
                                                          plans,
                                                          true,
                                                          true,
                                                          false,
                                                          true,
                                                          true);

            checkRO(finalCluster);

            // Test 3) Now try fetching files again even though they are
            // mmap-ed. Should fail...
            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()))));
            }

            // Actually run it
            try {
                int asyncId = adminClient.rebalanceOps.rebalanceNode(plans.get(0));
View Full Code Here

                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) {}

            // All nodes should have nothing in their rebalancing state
            // 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);
            }
View Full Code Here

TOP

Related Classes of voldemort.server.rebalance.RebalancerState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.