use of voldemort.server.rebalance.AlreadyRebalancingException in project voldemort by voldemort.
the class StealerBasedRebalanceTask method startNodeRebalancing.
private int startNodeRebalancing() {
try {
taskLog("Trying to start async rebalance task on stealer node " + stealerNodeId);
int asyncOperationId = adminClient.rebalanceOps.rebalanceNode(stealInfos.get(0));
taskLog("Started async rebalance task on stealer node " + stealerNodeId);
return asyncOperationId;
} catch (AlreadyRebalancingException e) {
String errorMessage = "Node " + stealerNodeId + " is currently rebalancing. Should not have tried to start new task on stealer node!";
taskLog(errorMessage);
throw new VoldemortException(errorMessage + " Failed to start rebalancing with plan: " + getStealInfos(), e);
}
}
use of voldemort.server.rebalance.AlreadyRebalancingException in project voldemort by voldemort.
the class AdminRebalanceTest method testRebalanceNodeRW.
@Test(timeout = 60000)
public void testRebalanceNodeRW() throws IOException {
try {
startThreeNodeRW();
// Start another node for only this unit test
HashMap<ByteArray, byte[]> entrySet = ServerTestUtils.createRandomKeyValuePairs(TEST_SIZE);
SocketStoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(Lists.newArrayList("tcp://" + currentCluster.getNodeById(0).getHost() + ":" + currentCluster.getNodeById(0).getSocketPort())));
StoreClient<Object, Object> storeClient1 = factory.getStoreClient("test"), storeClient2 = factory.getStoreClient("test2");
List<Integer> primaryPartitionsMoved = Lists.newArrayList(0);
List<Integer> secondaryPartitionsMoved = Lists.newArrayList(4, 5, 6, 7);
HashMap<ByteArray, byte[]> primaryEntriesMoved = Maps.newHashMap();
HashMap<ByteArray, byte[]> secondaryEntriesMoved = Maps.newHashMap();
RoutingStrategy strategy = new RoutingStrategyFactory().updateRoutingStrategy(storeDef2, currentCluster);
for (Entry<ByteArray, byte[]> entry : entrySet.entrySet()) {
storeClient1.put(new String(entry.getKey().get()), new String(entry.getValue()));
storeClient2.put(new String(entry.getKey().get()), new String(entry.getValue()));
List<Integer> pList = strategy.getPartitionList(entry.getKey().get());
if (primaryPartitionsMoved.contains(pList.get(0))) {
primaryEntriesMoved.put(entry.getKey(), entry.getValue());
} else if (secondaryPartitionsMoved.contains(pList.get(0))) {
secondaryEntriesMoved.put(entry.getKey(), entry.getValue());
}
}
try {
adminClient.rebalanceOps.rebalanceNode(plans.get(0));
fail("Should have thrown an exception since not in rebalancing state");
} catch (VoldemortException e) {
}
// 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_SOURCE_CLUSTER_XML, partitionPlan.getInitialCluster());
}
try {
adminClient.rebalanceOps.rebalanceNode(plans.get(0));
fail("Should have thrown an exception since no steal info");
} catch (VoldemortException e) {
}
// 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);
// 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();
}
}
Aggregations