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