Search in sources :

Example 1 with StateTransitionThrottleConfig

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()));
}
Also used : MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ErrTransition(org.apache.helix.mock.participant.ErrTransition) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) StateTransitionThrottleConfig(org.apache.helix.api.config.StateTransitionThrottleConfig) BestPossibleExternalViewVerifier(org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) ClusterConfig(org.apache.helix.model.ClusterConfig) Test(org.testng.annotations.Test)

Example 2 with StateTransitionThrottleConfig

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;
}
Also used : StateTransitionThrottleConfig(org.apache.helix.api.config.StateTransitionThrottleConfig) ArrayList(java.util.ArrayList)

Example 3 with StateTransitionThrottleConfig

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);
}
Also used : StateTransitionThrottleConfig(org.apache.helix.api.config.StateTransitionThrottleConfig) ClusterConfig(org.apache.helix.model.ClusterConfig)

Example 4 with StateTransitionThrottleConfig

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);
}
Also used : Partition(org.apache.helix.model.Partition) Resource(org.apache.helix.model.Resource) ArrayList(java.util.ArrayList) StateTransitionThrottleConfig(org.apache.helix.api.config.StateTransitionThrottleConfig) ClusterConfig(org.apache.helix.model.ClusterConfig) Test(org.testng.annotations.Test)

Example 5 with StateTransitionThrottleConfig

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);
}
Also used : StateTransitionThrottleConfig(org.apache.helix.api.config.StateTransitionThrottleConfig) ClusterConfig(org.apache.helix.model.ClusterConfig)

Aggregations

StateTransitionThrottleConfig (org.apache.helix.api.config.StateTransitionThrottleConfig)9 ClusterConfig (org.apache.helix.model.ClusterConfig)7 ArrayList (java.util.ArrayList)2 Test (org.testng.annotations.Test)2 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)1 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)1 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)1 ErrTransition (org.apache.helix.mock.participant.ErrTransition)1 Partition (org.apache.helix.model.Partition)1 Resource (org.apache.helix.model.Resource)1 BestPossibleExternalViewVerifier (org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier)1