Search in sources :

Example 1 with ReadClusterDataStage

use of org.apache.helix.controller.stages.ReadClusterDataStage in project helix by apache.

the class TestTopStateHandoffMetrics method runCurrentStage.

private void runCurrentStage(Map<String, Map<String, String>> initialCurrentStates, Map<String, Map<String, String>> handOffCurrentStates) {
    setupCurrentStates(generateCurrentStateMap(initialCurrentStates));
    runStage(event, new ReadClusterDataStage());
    runStage(event, new CurrentStateComputationStage());
    setupCurrentStates(generateCurrentStateMap(handOffCurrentStates));
    runStage(event, new ReadClusterDataStage());
    runStage(event, new CurrentStateComputationStage());
}
Also used : ReadClusterDataStage(org.apache.helix.controller.stages.ReadClusterDataStage) CurrentStateComputationStage(org.apache.helix.controller.stages.CurrentStateComputationStage)

Example 2 with ReadClusterDataStage

use of org.apache.helix.controller.stages.ReadClusterDataStage in project helix by apache.

the class TestP2PStateTransitionMessages method createPipeline.

private Pipeline createPipeline() {
    Pipeline pipeline = new Pipeline("test");
    pipeline.addStage(new ReadClusterDataStage());
    pipeline.addStage(new BestPossibleStateCalcStage());
    pipeline.addStage(new IntermediateStateCalcStage());
    pipeline.addStage(new MessageGenerationPhase());
    pipeline.addStage(new MessageSelectionStage());
    pipeline.addStage(new MessageThrottleStage());
    return pipeline;
}
Also used : ReadClusterDataStage(org.apache.helix.controller.stages.ReadClusterDataStage) BestPossibleStateCalcStage(org.apache.helix.controller.stages.BestPossibleStateCalcStage) IntermediateStateCalcStage(org.apache.helix.controller.stages.IntermediateStateCalcStage) MessageThrottleStage(org.apache.helix.controller.stages.MessageThrottleStage) MessageGenerationPhase(org.apache.helix.controller.stages.MessageGenerationPhase) MessageSelectionStage(org.apache.helix.controller.stages.MessageSelectionStage) Pipeline(org.apache.helix.controller.pipeline.Pipeline)

Example 3 with ReadClusterDataStage

use of org.apache.helix.controller.stages.ReadClusterDataStage in project helix by apache.

the class TestRebalancerMetrics method testLoadBalanceMetrics.

@Test
public void testLoadBalanceMetrics() {
    System.out.println("START testLoadBalanceMetrics at " + new Date(System.currentTimeMillis()));
    String resource = "testResourceName";
    int numPartition = 100;
    int numReplica = 3;
    int maxPending = 3;
    setupIdealState(5, new String[] { resource }, numPartition, numReplica, IdealState.RebalanceMode.FULL_AUTO, BuiltInStateModelDefinitions.MasterSlave.name());
    setupInstances(5);
    setupLiveInstances(4);
    setupStateModel();
    Map<String, Resource> resourceMap = getResourceMap(new String[] { resource }, numPartition, BuiltInStateModelDefinitions.MasterSlave.name());
    CurrentStateOutput currentStateOutput = new CurrentStateOutput();
    event.addAttribute(AttributeName.RESOURCES.name(), resourceMap);
    event.addAttribute(AttributeName.RESOURCES_TO_REBALANCE.name(), resourceMap);
    event.addAttribute(AttributeName.CURRENT_STATE.name(), currentStateOutput);
    ClusterStatusMonitor monitor = new ClusterStatusMonitor(_clusterName);
    monitor.active();
    event.addAttribute(AttributeName.clusterStatusMonitor.name(), monitor);
    runStage(event, new ReadClusterDataStage());
    runStage(event, new BestPossibleStateCalcStage());
    BestPossibleStateOutput bestPossibleStateOutput = event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.name());
    currentStateOutput = copyCurrentStateFromBestPossible(bestPossibleStateOutput, resource);
    event.addAttribute(AttributeName.CURRENT_STATE.name(), currentStateOutput);
    setupLiveInstances(4);
    runStage(event, new ReadClusterDataStage());
    ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());
    setupThrottleConfig(cache.getClusterConfig(), StateTransitionThrottleConfig.RebalanceType.LOAD_BALANCE, maxPending);
    runStage(event, new BestPossibleStateCalcStage());
    runStage(event, new IntermediateStateCalcStage());
    ClusterStatusMonitor clusterStatusMonitor = event.getAttribute(AttributeName.clusterStatusMonitor.name());
    ResourceMonitor resourceMonitor = clusterStatusMonitor.getResourceMonitor(resource);
    long numPendingLoadBalance = resourceMonitor.getPendingLoadRebalancePartitionGauge();
    Assert.assertTrue(numPendingLoadBalance > 0);
    Assert.assertEquals(resourceMonitor.getLoadRebalanceThrottledPartitionGauge(), numPendingLoadBalance - maxPending);
    System.out.println("END testLoadBalanceMetrics at " + new Date(System.currentTimeMillis()));
}
Also used : BestPossibleStateOutput(org.apache.helix.controller.stages.BestPossibleStateOutput) ClusterDataCache(org.apache.helix.controller.stages.ClusterDataCache) ReadClusterDataStage(org.apache.helix.controller.stages.ReadClusterDataStage) IntermediateStateCalcStage(org.apache.helix.controller.stages.IntermediateStateCalcStage) Resource(org.apache.helix.model.Resource) Date(java.util.Date) CurrentStateOutput(org.apache.helix.controller.stages.CurrentStateOutput) BestPossibleStateCalcStage(org.apache.helix.controller.stages.BestPossibleStateCalcStage) Test(org.testng.annotations.Test) BaseStageTest(org.apache.helix.controller.stages.BaseStageTest)

Example 4 with ReadClusterDataStage

use of org.apache.helix.controller.stages.ReadClusterDataStage in project helix by apache.

the class TaskTestUtil method calculateBestPossibleState.

public static BestPossibleStateOutput calculateBestPossibleState(ClusterDataCache cache, HelixManager manager) throws Exception {
    ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
    event.addAttribute(AttributeName.ClusterDataCache.name(), cache);
    event.addAttribute(AttributeName.helixmanager.name(), manager);
    List<Stage> stages = new ArrayList<Stage>();
    stages.add(new ReadClusterDataStage());
    stages.add(new ResourceComputationStage());
    stages.add(new CurrentStateComputationStage());
    stages.add(new BestPossibleStateCalcStage());
    for (Stage stage : stages) {
        runStage(event, stage);
    }
    return event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.name());
}
Also used : ClusterEvent(org.apache.helix.controller.stages.ClusterEvent) ResourceComputationStage(org.apache.helix.controller.stages.ResourceComputationStage) ReadClusterDataStage(org.apache.helix.controller.stages.ReadClusterDataStage) BestPossibleStateCalcStage(org.apache.helix.controller.stages.BestPossibleStateCalcStage) ArrayList(java.util.ArrayList) BestPossibleStateCalcStage(org.apache.helix.controller.stages.BestPossibleStateCalcStage) Stage(org.apache.helix.controller.pipeline.Stage) ReadClusterDataStage(org.apache.helix.controller.stages.ReadClusterDataStage) ResourceComputationStage(org.apache.helix.controller.stages.ResourceComputationStage) CurrentStateComputationStage(org.apache.helix.controller.stages.CurrentStateComputationStage) CurrentStateComputationStage(org.apache.helix.controller.stages.CurrentStateComputationStage)

Example 5 with ReadClusterDataStage

use of org.apache.helix.controller.stages.ReadClusterDataStage in project helix by apache.

the class TestPersistAssignmentStage method testSimple.

/**
 * Case where we have one resource in IdealState
 * @throws Exception
 */
@Test
public void testSimple() throws Exception {
    int nodes = 2;
    List<String> instances = new ArrayList<String>();
    for (int i = 0; i < nodes; i++) {
        instances.add("localhost_" + i);
    }
    int partitions = 10;
    int replicas = 1;
    String resourceName = "testResource";
    ZNRecord record = DefaultIdealStateCalculator.calculateIdealState(instances, partitions, replicas, resourceName, "ONLINE", "OFFLINE");
    IdealState idealState = new IdealState(record);
    idealState.setStateModelDefRef("OnlineOffline");
    // Read and load current state into event
    HelixDataAccessor accessor = _manager.getHelixDataAccessor();
    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
    accessor.setProperty(keyBuilder.idealStates(resourceName), idealState);
    runStage(_manager, event, new ReadClusterDataStage());
    runStage(_manager, event, new ResourceComputationStage());
    // Ensure persist best possible assignment is true
    ClusterConfig clusterConfig = new ClusterConfig(CLUSTER_NAME);
    clusterConfig.setPersistBestPossibleAssignment(true);
    ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());
    cache.setClusterConfig(clusterConfig);
    // 1. Change best possible state (simulate a new rebalancer run)
    BestPossibleStateOutput bestPossibleStateOutput = new BestPossibleStateOutput();
    for (String partition : idealState.getPartitionSet()) {
        bestPossibleStateOutput.setState(resourceName, new Partition(partition), "localhost_3", "OFFLINE");
    }
    // 2. At the same time, set DelayRebalanceEnabled = true (simulate a Admin operation at the same time)
    idealState.setDelayRebalanceEnabled(true);
    accessor.setProperty(keyBuilder.idealStates(resourceName), idealState);
    // Persist new assignment
    PersistAssignmentStage stage = new PersistAssignmentStage();
    event.addAttribute(AttributeName.BEST_POSSIBLE_STATE.name(), bestPossibleStateOutput);
    runStage(_manager, event, stage);
    IdealState newIdealState = accessor.getProperty(keyBuilder.idealStates(resourceName));
    // 1. New assignment should be set
    Assert.assertEquals(newIdealState.getPartitionSet().size(), idealState.getPartitionSet().size());
    for (String partition : idealState.getPartitionSet()) {
        Map<String, String> assignment = newIdealState.getInstanceStateMap(partition);
        Assert.assertNotNull(assignment);
        Assert.assertEquals(assignment.size(), 1);
        Assert.assertTrue(assignment.containsKey("localhost_3") && assignment.get("localhost_3").equals("OFFLINE"));
    }
    // 2. Admin config should be set
    Assert.assertTrue(newIdealState.isDelayRebalanceEnabled());
}
Also used : Partition(org.apache.helix.model.Partition) PersistAssignmentStage(org.apache.helix.controller.stages.PersistAssignmentStage) BestPossibleStateOutput(org.apache.helix.controller.stages.BestPossibleStateOutput) ResourceComputationStage(org.apache.helix.controller.stages.ResourceComputationStage) ClusterDataCache(org.apache.helix.controller.stages.ClusterDataCache) ReadClusterDataStage(org.apache.helix.controller.stages.ReadClusterDataStage) ArrayList(java.util.ArrayList) IdealState(org.apache.helix.model.IdealState) HelixDataAccessor(org.apache.helix.HelixDataAccessor) ZNRecord(org.apache.helix.ZNRecord) PropertyKey(org.apache.helix.PropertyKey) ClusterConfig(org.apache.helix.model.ClusterConfig) Test(org.testng.annotations.Test)

Aggregations

ReadClusterDataStage (org.apache.helix.controller.stages.ReadClusterDataStage)6 BestPossibleStateCalcStage (org.apache.helix.controller.stages.BestPossibleStateCalcStage)4 ClusterDataCache (org.apache.helix.controller.stages.ClusterDataCache)3 IntermediateStateCalcStage (org.apache.helix.controller.stages.IntermediateStateCalcStage)3 Test (org.testng.annotations.Test)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 BaseStageTest (org.apache.helix.controller.stages.BaseStageTest)2 BestPossibleStateOutput (org.apache.helix.controller.stages.BestPossibleStateOutput)2 CurrentStateComputationStage (org.apache.helix.controller.stages.CurrentStateComputationStage)2 CurrentStateOutput (org.apache.helix.controller.stages.CurrentStateOutput)2 ResourceComputationStage (org.apache.helix.controller.stages.ResourceComputationStage)2 Resource (org.apache.helix.model.Resource)2 HelixDataAccessor (org.apache.helix.HelixDataAccessor)1 PropertyKey (org.apache.helix.PropertyKey)1 ZNRecord (org.apache.helix.ZNRecord)1 Pipeline (org.apache.helix.controller.pipeline.Pipeline)1 Stage (org.apache.helix.controller.pipeline.Stage)1 ClusterEvent (org.apache.helix.controller.stages.ClusterEvent)1 MessageGenerationPhase (org.apache.helix.controller.stages.MessageGenerationPhase)1