use of voldemort.server.NodeIdHostMatcher in project voldemort by voldemort.
the class ReplaceNodeTest method testNodeDownReplacement.
@Test
public void testNodeDownReplacement() throws Exception {
final int REPLACEMENT_NODE = 0;
// This is to simulate the case where a machine failed but hard disk was intact
// In this case we will move the hard disk to another machine, edit the cluster.xml
// to point to this host and start this machine.
// The case is simulated by remembering the cluster of node A.
// Replace this node with node B. Now create a new server with cluster of
// node A ( this is to simulate the cluster.xml edit) and data directory of B
// ( this is to simulate the hard disk move). Now try replacing the node B with
// newly created node after shutting down the node B.
Cluster cluster = originalServers[nodeToBeReplaced].getMetadataStore().getCluster();
List<StoreDefinition> storeDefs = originalServers[nodeToBeReplaced].getMetadataStore().getStoreDefList();
Node node = originalServers[nodeToBeReplaced].getIdentityNode();
//Verify the node down scenario first
final boolean DO_RESTORE = false;
final boolean STOP_OLD_NODE = true;
verifyNodeReplacement(nodeToBeReplaced, otherServers, REPLACEMENT_NODE, STOP_OLD_NODE, DO_RESTORE);
// Now the replacement node is part of the original cluster.
// Stop the replacement node, assume you moved the hard disk
// to a new node ( This is done by starting another node)
// that points to the data directory of the replacement node.
String baseDirPath = otherServers[REPLACEMENT_NODE].getVoldemortConfig().getVoldemortHome();
// Using ServerTestUtils stopVoldemortServer also deletes the data
// directory so using the stop, to simulate the hard disk move.
otherServers[REPLACEMENT_NODE].stop();
VoldemortConfig config = ServerTestUtils.createServerConfigWithDefs(true, node.getId(), baseDirPath, cluster, storeDefs, new Properties());
Assert.assertTrue(config.isSlopEnabled());
Assert.assertTrue(config.isSlopPusherJobEnabled());
Assert.assertTrue(config.getAutoPurgeDeadSlops());
config.setSlopFrequencyMs(8000L);
config.setEnableNodeIdDetection(this.autoDetectNodeId);
if (this.autoDetectNodeId) {
config.setNodeIdImplementation(new NodeIdHostMatcher(nodeToBeReplaced));
}
// Though baseDir is used as part of Config, TestUtils, always appends
// it with node- (nodeId). So forcefully overwriting it here to point to
// the old directory.
config.setVoldemortHome(baseDirPath);
SocketStoreFactory ssf = new TestSocketStoreFactory();
VoldemortServer hardDiskMovedServer = ServerTestUtils.startVoldemortServer(ssf, config, cluster);
ssf.close();
otherServers[REPLACEMENT_NODE] = hardDiskMovedServer;
final boolean SKIP_RESTORE = true;
final boolean DONOT_STOP_OLD_NODE = true;
verifyNodeReplacement(nodeToBeReplaced, otherServers, REPLACEMENT_NODE, DONOT_STOP_OLD_NODE, SKIP_RESTORE);
}
Aggregations