2, // partitions per resource
n, // number of nodes
2, // replicas
"MasterSlave", true); // do rebalance
MockController controller =
new MockController(_zkaddr, clusterName, "controller_0");
controller.syncStart();
// start participants
MockParticipant[] participants = new MockParticipant[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
participants[i] = new MockParticipant(_zkaddr, clusterName, instanceName);
participants[i].syncStart();
}
boolean result =
ClusterStateVerifier
.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(_zkaddr,
clusterName));
Assert.assertTrue(result);
// disable controller
ZKHelixAdmin admin = new ZKHelixAdmin(_zkclient);
admin.enableCluster(clusterName, false);
// wait all pending zk-events being processed, otherwise remove current-state will cause
// controller send O->S message
ZkTestHelper.tryWaitZkEventsCleaned(controller.getZkClient());
// System.out.println("paused controller");
// drop resource
admin.dropResource(clusterName, "TestDB0");
// delete current-state manually, controller shall remove external-view when cluster is enabled
// again
ZKHelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, _baseAccessor);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
// System.out.println("remove current-state");
LiveInstance liveInstance = accessor.getProperty(keyBuilder.liveInstance("localhost_12918"));
accessor.removeProperty(keyBuilder.currentState("localhost_12918", liveInstance
.getTypedSessionId().stringify(), "TestDB0"));
liveInstance = accessor.getProperty(keyBuilder.liveInstance("localhost_12919"));
accessor.removeProperty(keyBuilder.currentState("localhost_12919", liveInstance
.getTypedSessionId().stringify(), "TestDB0"));
// re-enable controller shall remove orphan external-view
// System.out.println("re-enabling controller");
admin.enableCluster(clusterName, true);
ExternalView externalView = null;
for (int i = 0; i < 10; i++) {
Thread.sleep(100);
externalView = accessor.getProperty(keyBuilder.externalView("TestDB0"));
// System.out.println("externalView: " + externalView);
if (externalView == null) {
break;
}
}
Assert.assertNull(externalView, "external-view for TestDB0 should be removed, but was: "
+ externalView);
// clean up
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));