use of org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier in project helix by apache.
the class TestStateTransitionThrottle method testTransitionThrottleOnErrorPartition.
@Test
public void testTransitionThrottleOnErrorPartition() throws Exception {
String clusterName = getShortClassName() + "testMaxErrorPartition";
MockParticipantManager[] participants = new MockParticipantManager[participantCount];
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
final ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
setupCluster(clusterName, accessor);
// Set throttle config to enable throttling
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
ClusterConfig clusterConfig = accessor.getProperty(accessor.keyBuilder().clusterConfig());
clusterConfig.setResourcePriorityField("Name");
List<StateTransitionThrottleConfig> throttleConfigs = new ArrayList<>();
throttleConfigs.add(new StateTransitionThrottleConfig(StateTransitionThrottleConfig.RebalanceType.LOAD_BALANCE, StateTransitionThrottleConfig.ThrottleScope.CLUSTER, 100));
throttleConfigs.add(new StateTransitionThrottleConfig(StateTransitionThrottleConfig.RebalanceType.RECOVERY_BALANCE, StateTransitionThrottleConfig.ThrottleScope.CLUSTER, 100));
clusterConfig.setStateTransitionThrottleConfigs(throttleConfigs);
accessor.setProperty(keyBuilder.clusterConfig(), clusterConfig);
// set one partition to be always Error, so load balance won't be triggered
Map<String, Set<String>> errPartitions = new HashMap<>();
errPartitions.put("OFFLINE-SLAVE", TestHelper.setOf(resourceName + "_0"));
// start part of participants
for (int i = 0; i < participantCount - 1; i++) {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_" + (12918 + i));
if (i == 0) {
participants[i].setTransition(new ErrTransition(errPartitions));
}
participants[i].syncStart();
}
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
BestPossibleExternalViewVerifier verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkClient(_gZkClient).build();
Assert.assertTrue(verifier.verify(3000));
// Adding one more participant.
participants[participantCount - 1] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_" + (12918 + participantCount - 1));
participants[participantCount - 1].syncStart();
// Since error partition exists, no load balance transition will be done
Assert.assertFalse(pollForPartitionAssignment(accessor, participants[participantCount - 1], resourceName, 5000));
// Update cluster config to tolerate error partition, so load balance transition will be done
clusterConfig = accessor.getProperty(accessor.keyBuilder().clusterConfig());
clusterConfig.setErrorPartitionThresholdForLoadBalance(1);
accessor.setProperty(keyBuilder.clusterConfig(), clusterConfig);
_gSetupTool.rebalanceResource(clusterName, resourceName, 3);
Assert.assertTrue(pollForPartitionAssignment(accessor, participants[participantCount - 1], resourceName, 3000));
// clean up
controller.syncStop();
for (int i = 0; i < participantCount; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier in project helix by apache.
the class TestStateTransitionThrottle method testTransitionThrottleOnRecoveryPartition.
@Test
public void testTransitionThrottleOnRecoveryPartition() throws Exception {
String clusterName = getShortClassName() + "testRecoveryPartition";
MockParticipantManager[] participants = new MockParticipantManager[participantCount];
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
final ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
setupCluster(clusterName, accessor);
// start partial participants
for (int i = 0; i < participantCount - 1; i++) {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_" + (12918 + i));
if (i == 0) {
// One participant 0, delay processing partition 0 transition
final String delayedPartitionName = resourceName + "_0";
participants[i].setTransition(new SleepTransition(99999999) {
@Override
public void doTransition(Message message, NotificationContext context) throws InterruptedException {
String partition = message.getPartitionName();
if (partition.equals(delayedPartitionName)) {
super.doTransition(message, context);
}
}
});
}
participants[i].syncStart();
}
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
BestPossibleExternalViewVerifier verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkClient(_gZkClient).build();
// Won't match, since there is pending transition
Assert.assertFalse(verifier.verify(3000));
participants[participantCount - 1] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_" + (12918 + participantCount - 1));
participants[participantCount - 1].syncStart();
// Load balance transition won't be scheduled since there is pending recovery balance transition
Assert.assertFalse(pollForPartitionAssignment(accessor, participants[participantCount - 1], resourceName, 5000));
// Stop participant, so blocking transition is removed.
participants[0].syncStop();
Assert.assertTrue(pollForPartitionAssignment(accessor, participants[participantCount - 1], resourceName, 5000));
// clean up
controller.syncStop();
for (int i = 0; i < participantCount; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier in project helix by apache.
the class TestResourceThreadpoolSize method testBatchMessageThreadPoolSize.
@Test
public void testBatchMessageThreadPoolSize() throws InterruptedException {
int customizedPoolSize = 5;
_participants[0].getStateMachineEngine().registerStateModelFactory("OnlineOffline", new TestOnlineOfflineStateModelFactory(customizedPoolSize, 2000), "TestFactory");
for (int i = 1; i < _participants.length; i++) {
_participants[i].syncStop();
}
Thread.sleep(2000L);
// Add 10 dbs with batch message enabled. Each db has 10 partitions.
// So it will have 10 batch messages and each batch message has 10 sub messages.
int numberOfDbs = 10;
for (int i = 0; i < numberOfDbs; i++) {
String dbName = "TestDBABatch" + i;
IdealState idealState = new FullAutoModeISBuilder(dbName).setStateModel("OnlineOffline").setStateModelFactoryName("TestFactory").setNumPartitions(10).setNumReplica(1).build();
idealState.setBatchMessageMode(true);
_setupTool.getClusterManagementTool().addResource(CLUSTER_NAME, dbName, idealState);
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, dbName, 1);
}
Thread.sleep(2000L);
DefaultMessagingService svc = (DefaultMessagingService) (_participants[0].getMessagingService());
HelixTaskExecutor helixExecutor = svc.getExecutor();
ThreadPoolExecutor executor = (ThreadPoolExecutor) (helixExecutor._batchMessageExecutorService);
Assert.assertNotNull(executor);
Assert.assertTrue(executor.getPoolSize() >= numberOfDbs);
BestPossibleExternalViewVerifier verifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).build();
Assert.assertTrue(verifier.verify());
}
Aggregations