use of org.apache.helix.manager.zk.ZKHelixDataAccessor in project helix by apache.
the class TestAlertingRebalancerFailure method beforeClass.
@Override
@BeforeClass
public void beforeClass() throws Exception {
System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
String namespace = "/" + CLUSTER_NAME;
if (_gZkClient.exists(namespace)) {
_gZkClient.deleteRecursively(namespace);
}
_setupTool = new ClusterSetup(ZK_ADDR);
// setup storage cluster
_setupTool.addCluster(CLUSTER_NAME, true);
for (int i = 0; i < NODE_NR; i++) {
String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
_setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
}
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
// start dummy participants
for (int i = 0; i < NODE_NR; i++) {
String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
_instanceNames.add(instanceName);
_participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
_participants[i].syncStart();
}
enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
accessor = new ZKHelixDataAccessor(CLUSTER_NAME, _baseAccessor);
errorNodeKey = accessor.keyBuilder().controllerTaskError(RebalanceResourceFailure.name());
}
use of org.apache.helix.manager.zk.ZKHelixDataAccessor in project helix by apache.
the class TestBucketizedResource method setupCluster.
private void setupCluster(String clusterName, List<String> instanceNames, String dbName, int replica, int partitions, int bucketSize) {
_gSetupTool.addCluster(clusterName, true);
_gSetupTool.addInstancesToCluster(clusterName, instanceNames.toArray(new String[instanceNames.size()]));
// add a bucketized resource
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
ZNRecord idealStateRec = DefaultIdealStateCalculator.calculateIdealState(instanceNames, partitions, replica - 1, dbName, "MASTER", "SLAVE");
IdealState idealState = new IdealState(idealStateRec);
idealState.setBucketSize(bucketSize);
idealState.setStateModelDefRef("MasterSlave");
idealState.setRebalanceMode(IdealState.RebalanceMode.CUSTOMIZED);
idealState.setReplicas(Integer.toString(replica));
accessor.setProperty(keyBuilder.idealStates(dbName), idealState);
}
use of org.apache.helix.manager.zk.ZKHelixDataAccessor in project helix by apache.
the class TestDrop method testDropErrorPartitionFailedAutoIS.
@Test
public void testDropErrorPartitionFailedAutoIS() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
final int n = 5;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
MockParticipantManager[] participants = new MockParticipantManager[n];
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
8, // number of nodes
n, // replicas
3, "MasterSlave", // do rebalance
true);
// start controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
Map<String, Set<String>> errTransitions = new HashMap<String, Set<String>>();
errTransitions.put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
errTransitions.put("ERROR-DROPPED", TestHelper.setOf("TestDB0_4"));
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
if (i == 0) {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].setTransition(new ErrTransition(errTransitions));
} else {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
}
Map<String, Map<String, String>> errStateMap = new HashMap<>();
errStateMap.put("TestDB0", new HashMap<String, String>());
errStateMap.get("TestDB0").put("TestDB0_4", "localhost_12918");
HelixClusterVerifier verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).setErrStates(errStateMap).build();
Assert.assertTrue(verifier.verify());
// drop resource containing error partitions should invoke error->dropped transition
// if error happens during error->dropped transition, partition should be disabled
ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--dropResource", clusterName, "TestDB0" });
Thread.sleep(100);
// make sure TestDB0_4 stay in ERROR state and is disabled
Assert.assertTrue(verifier.verify());
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig("localhost_12918"));
List<String> disabledPartitions = config.getDisabledPartitions();
// System.out.println("disabledPartitions: " + disabledPartitions);
Assert.assertEquals(disabledPartitions.size(), 1, "TestDB0_4 should be disabled");
Assert.assertEquals(disabledPartitions.get(0), "TestDB0_4");
// ExteranlView should have TestDB0_4->localhost_12918_>ERROR
Thread.sleep(2000);
ExternalView ev = accessor.getProperty(keyBuilder.externalView("TestDB0"));
Set<String> partitions = ev.getPartitionSet();
Assert.assertEquals(partitions.size(), 1, "Should have TestDB0_4->localhost_12918->ERROR");
String errPartition = partitions.iterator().next();
Assert.assertEquals(errPartition, "TestDB0_4");
Map<String, String> stateMap = ev.getStateMap(errPartition);
Assert.assertEquals(stateMap.size(), 1);
Assert.assertEquals(stateMap.keySet().iterator().next(), "localhost_12918");
Assert.assertEquals(stateMap.get("localhost_12918"), HelixDefinedState.ERROR.name());
// localhost_12918 should have TestDB0_4 in ERROR state
CurrentState cs = accessor.getProperty(keyBuilder.currentState(participants[0].getInstanceName(), participants[0].getSessionId(), "TestDB0"));
Map<String, String> partitionStateMap = cs.getPartitionStateMap();
Assert.assertEquals(partitionStateMap.size(), 1);
Assert.assertEquals(partitionStateMap.keySet().iterator().next(), "TestDB0_4");
Assert.assertEquals(partitionStateMap.get("TestDB0_4"), HelixDefinedState.ERROR.name());
// all other participants should have cleaned up empty current state
for (int i = 1; i < n; i++) {
String instanceName = participants[i].getInstanceName();
String sessionId = participants[i].getSessionId();
Assert.assertNull(accessor.getProperty(keyBuilder.currentState(instanceName, sessionId, "TestDB0")));
}
// clean up
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.manager.zk.ZKHelixDataAccessor in project helix by apache.
the class TestEntropyFreeNodeBounce method testBounceAll.
@Test
public void testBounceAll() throws Exception {
// pick numbers that don't divide evenly
final int NUM_PARTICIPANTS = 5;
final int NUM_PARTITIONS = 123;
final int NUM_REPLICAS = 1;
final String RESOURCE_PREFIX = "TestDB";
final String RESOURCE_NAME = RESOURCE_PREFIX + "0";
// create a cluster name based on this test name
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// Set up cluster
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
NUM_PARTITIONS, // number of nodes
NUM_PARTICIPANTS, // replicas
NUM_REPLICAS, // use FULL_AUTO mode to test node tagging
"OnlineOffline", // use FULL_AUTO mode to test node tagging
RebalanceMode.FULL_AUTO, // do rebalance
true);
// Start the participants
HelixManager[] participants = new HelixManager[NUM_PARTICIPANTS];
for (int i = 0; i < NUM_PARTICIPANTS; i++) {
final String instanceName = "localhost_" + (12918 + i);
participants[i] = createParticipant(clusterName, instanceName);
participants[i].connect();
}
// Start the controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
controller.syncStart();
// get an admin and accessor
HelixAdmin helixAdmin = new ZKHelixAdmin(_gZkClient);
BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
// do the test
try {
Thread.sleep(1000);
// ensure that the external view coalesces
boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
ExternalView stableExternalView = accessor.getProperty(keyBuilder.externalView(RESOURCE_NAME));
for (HelixManager participant : participants) {
// disable the controller, bounce the node, re-enable the controller, verify assignments
// remained the same
helixAdmin.enableCluster(clusterName, false);
participant.disconnect();
Thread.sleep(1000);
participant = createParticipant(clusterName, participant.getInstanceName());
participant.connect();
Thread.sleep(1000);
helixAdmin.enableCluster(clusterName, true);
Thread.sleep(1000);
result = ClusterStateVerifier.verifyByZkCallback(new MatchingExternalViewVerifier(stableExternalView, clusterName));
Assert.assertTrue(result);
}
} finally {
// clean up
controller.syncStop();
for (HelixManager participant : participants) {
participant.disconnect();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
}
use of org.apache.helix.manager.zk.ZKHelixDataAccessor in project helix by apache.
the class TestExternalViewStage method testCachedExternalViews.
@Test
public void testCachedExternalViews() throws Exception {
String clusterName = "CLUSTER_" + TestHelper.getTestMethodName();
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
HelixManager manager = new DummyClusterManager(clusterName, accessor);
// ideal state: node0 is MASTER, node1 is SLAVE
// replica=2 means 1 master and 1 slave
setupIdealState(clusterName, new int[] { 0, 1 }, new String[] { "TestDB" }, 1, 2);
setupLiveInstances(clusterName, new int[] { 0, 1 });
setupStateModel(clusterName);
ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
ClusterDataCache cache = new ClusterDataCache(clusterName);
event.addAttribute(AttributeName.helixmanager.name(), manager);
event.addAttribute(AttributeName.ClusterDataCache.name(), cache);
ExternalViewComputeStage externalViewComputeStage = new ExternalViewComputeStage();
Pipeline dataRefresh = new Pipeline();
dataRefresh.addStage(new ReadClusterDataStage());
runPipeline(event, dataRefresh);
runStage(event, new ResourceComputationStage());
runStage(event, new CurrentStateComputationStage());
runStage(event, externalViewComputeStage);
Assert.assertEquals(cache.getExternalViews().values(), accessor.getChildValues(accessor.keyBuilder().externalViews()));
// Assure there is no external got updated
List<ExternalView> oldExternalViews = accessor.getChildValues(accessor.keyBuilder().externalViews());
runStage(event, externalViewComputeStage);
List<ExternalView> newExternalViews = accessor.getChildValues(accessor.keyBuilder().externalViews());
Assert.assertEquals(oldExternalViews, newExternalViews);
for (int i = 0; i < oldExternalViews.size(); i++) {
Assert.assertEquals(oldExternalViews.get(i).getStat().getVersion(), newExternalViews.get(i).getStat().getVersion());
}
}
Aggregations