use of org.apache.helix.api.config.StateTransitionThrottleConfig 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.api.config.StateTransitionThrottleConfig in project helix by apache.
the class ClusterConfig method getStateTransitionThrottleConfigs.
/**
* Get a list StateTransitionThrottleConfig set for this cluster.
*
* @return
*/
public List<StateTransitionThrottleConfig> getStateTransitionThrottleConfigs() {
List<String> configs = _record.getListField(ClusterConfigProperty.STATE_TRANSITION_THROTTLE_CONFIGS.name());
if (configs == null || configs.isEmpty()) {
return Collections.emptyList();
}
List<StateTransitionThrottleConfig> throttleConfigs = new ArrayList<StateTransitionThrottleConfig>();
for (String configstr : configs) {
StateTransitionThrottleConfig throttleConfig = StateTransitionThrottleConfig.fromJSON(configstr);
if (throttleConfig != null) {
throttleConfigs.add(throttleConfig);
}
}
return throttleConfigs;
}
use of org.apache.helix.api.config.StateTransitionThrottleConfig in project helix by apache.
the class TestIntermediateStateCalcStage method preSetup.
private void preSetup(StateTransitionThrottleConfig.RebalanceType rebalanceType, Set<String> resourceSet, int numOfLiveInstances, int numOfReplicas) {
setupIdealState(numOfLiveInstances, resourceSet.toArray(new String[resourceSet.size()]), numOfLiveInstances, numOfReplicas, IdealState.RebalanceMode.FULL_AUTO, "OnlineOffline");
setupStateModel();
setupLiveInstances(numOfLiveInstances);
// Set up cluster configs
ClusterConfig clusterConfig = accessor.getProperty(accessor.keyBuilder().clusterConfig());
StateTransitionThrottleConfig throttleConfig = new StateTransitionThrottleConfig(rebalanceType, StateTransitionThrottleConfig.ThrottleScope.CLUSTER, Integer.MAX_VALUE);
clusterConfig.setStateTransitionThrottleConfigs(Collections.singletonList(throttleConfig));
setClusterConfig(clusterConfig);
}
use of org.apache.helix.api.config.StateTransitionThrottleConfig in project helix by apache.
the class TestStateTransitionPrirority method testPartitionLevelPriority.
@Test(dataProvider = "PartitionLevelPriority")
public void testPartitionLevelPriority(String resourceName, Map<String, Map<String, String>> bestPossibleMap, Map<String, Map<String, String>> currentStateMap, List<String> preferenceList, List<String> expectedPriority) {
preSetup(StateTransitionThrottleConfig.RebalanceType.RECOVERY_BALANCE, new HashSet<String>(Arrays.asList(resourceName)), "no_field", 3, 3);
// Add load rebalance throttle config
ClusterConfig clusterConfig = accessor.getProperty(accessor.keyBuilder().clusterConfig());
StateTransitionThrottleConfig throttleConfigForLoadRebalance = new StateTransitionThrottleConfig(StateTransitionThrottleConfig.RebalanceType.LOAD_BALANCE, StateTransitionThrottleConfig.ThrottleScope.CLUSTER, 1);
List<StateTransitionThrottleConfig> currentThrottleConfig = clusterConfig.getStateTransitionThrottleConfigs();
currentThrottleConfig.add(throttleConfigForLoadRebalance);
clusterConfig.setStateTransitionThrottleConfigs(currentThrottleConfig);
setClusterConfig(clusterConfig);
// Initialize best possible state, current state and resource map.
Resource resource = new Resource(resourceName);
BestPossibleStateOutput bestPossibleStateOutput = new BestPossibleStateOutput();
CurrentStateOutput currentStateOutput = new CurrentStateOutput();
for (String partitionName : bestPossibleMap.keySet()) {
Partition partition = new Partition(partitionName);
bestPossibleStateOutput.setPreferenceList(resourceName, partitionName, preferenceList);
for (String instanceName : bestPossibleMap.get(partitionName).keySet()) {
bestPossibleStateOutput.setState(resourceName, partition, instanceName, bestPossibleMap.get(partitionName).get(instanceName));
currentStateOutput.setCurrentState(resourceName, partition, instanceName, currentStateMap.get(partitionName).get(instanceName));
}
resource.addPartition(partitionName);
}
resource.setStateModelDefRef("MasterSlave");
event.addAttribute(AttributeName.RESOURCES.name(), Collections.singletonMap(resourceName, resource));
event.addAttribute(AttributeName.RESOURCES_TO_REBALANCE.name(), resource);
event.addAttribute(AttributeName.BEST_POSSIBLE_STATE.name(), bestPossibleStateOutput);
event.addAttribute(AttributeName.CURRENT_STATE.name(), currentStateOutput);
runStage(event, new ReadClusterDataStage());
// Keep update the current state.
List<String> partitionPriority = new ArrayList<String>();
for (int i = 0; i < bestPossibleMap.size(); i++) {
runStage(event, new IntermediateStateCalcStage());
updateCurrentStateForPartitionLevelPriority(partitionPriority, currentStateOutput, resourceName, bestPossibleMap);
}
Assert.assertEquals(partitionPriority, expectedPriority);
}
use of org.apache.helix.api.config.StateTransitionThrottleConfig in project helix by apache.
the class TestStateTransitionPrirority method preSetup.
private void preSetup(StateTransitionThrottleConfig.RebalanceType rebalanceType, Set<String> resourceSet, String priorityField, int numOfLiveInstances, int numOfReplicas) {
setupIdealState(numOfLiveInstances, resourceSet.toArray(new String[resourceSet.size()]), numOfLiveInstances, numOfReplicas, IdealState.RebalanceMode.FULL_AUTO, "MasterSlave");
setupStateModel();
setupLiveInstances(numOfLiveInstances);
// Set up cluster configs
ClusterConfig clusterConfig = accessor.getProperty(accessor.keyBuilder().clusterConfig());
StateTransitionThrottleConfig throttleConfig = new StateTransitionThrottleConfig(rebalanceType, StateTransitionThrottleConfig.ThrottleScope.CLUSTER, 1);
clusterConfig.setStateTransitionThrottleConfigs(Collections.singletonList(throttleConfig));
clusterConfig.setResourcePriorityField(priorityField);
setClusterConfig(clusterConfig);
}
Aggregations