Search in sources :

Example 91 with IdealState

use of org.apache.helix.model.IdealState in project helix by apache.

the class TestRebalancerPersistAssignments method testDisablePersist.

@Test(dataProvider = "rebalanceModes")
public void testDisablePersist(RebalanceMode rebalanceMode) throws Exception {
    String testDb = "TestDB2-" + rebalanceMode.name();
    _setupTool.addResourceToCluster(CLUSTER_NAME, testDb, 5, BuiltInStateModelDefinitions.LeaderStandby.name(), rebalanceMode.name());
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, testDb, 3);
    BestPossibleExternalViewVerifier.Builder verifierBuilder = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).setResources(new HashSet<String>(Collections.singleton(testDb)));
    Assert.assertTrue(verifierBuilder.build().verify());
    // kill 1 node
    _participants[0].syncStop();
    Set<String> liveInstances = new HashSet<String>(_instanceNames);
    liveInstances.remove(_participants[0].getInstanceName());
    verifierBuilder.setExpectLiveInstances(liveInstances);
    Assert.assertTrue(verifierBuilder.build().verify());
    IdealState idealState = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, testDb);
    Set<String> excludedInstances = new HashSet<String>();
    excludedInstances.add(_participants[0].getInstanceName());
    verifyAssignmentInIdealStateWithPersistDisabled(idealState, excludedInstances);
    // clean up
    _setupTool.getClusterManagementTool().dropResource(CLUSTER_NAME, testDb);
    _participants[0] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, _participants[0].getInstanceName());
    _participants[0].syncStart();
}
Also used : MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) BestPossibleExternalViewVerifier(org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier) IdealState(org.apache.helix.model.IdealState) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 92 with IdealState

use of org.apache.helix.model.IdealState in project helix by apache.

the class TestRebalancerPersistAssignments method testEnablePersist.

@Test(dataProvider = "rebalanceModes", dependsOnMethods = { "testDisablePersist" })
public void testEnablePersist(RebalanceMode rebalanceMode) throws Exception {
    String testDb = "TestDB1-" + rebalanceMode.name();
    enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
    _setupTool.addResourceToCluster(CLUSTER_NAME, testDb, 5, BuiltInStateModelDefinitions.LeaderStandby.name(), rebalanceMode.name());
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, testDb, 3);
    BestPossibleExternalViewVerifier.Builder verifierBuilder = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).setResources(new HashSet<String>(Collections.singleton(testDb)));
    Assert.assertTrue(verifierBuilder.build().verify());
    IdealState idealState = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, testDb);
    verifyAssignmentInIdealStateWithPersistEnabled(idealState, new HashSet<String>());
    // kill 1 node
    _participants[0].syncStop();
    Set<String> liveInstances = new HashSet<String>(_instanceNames);
    liveInstances.remove(_participants[0].getInstanceName());
    verifierBuilder.setExpectLiveInstances(liveInstances);
    Assert.assertTrue(verifierBuilder.build().verify());
    idealState = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, testDb);
    // verify that IdealState contains updated assignment in it map fields.
    Set<String> excludedInstances = new HashSet<String>();
    excludedInstances.add(_participants[0].getInstanceName());
    verifyAssignmentInIdealStateWithPersistEnabled(idealState, excludedInstances);
    // clean up
    _setupTool.getClusterManagementTool().dropResource(CLUSTER_NAME, testDb);
    _participants[0] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, _participants[0].getInstanceName());
    _participants[0].syncStart();
}
Also used : MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) BestPossibleExternalViewVerifier(org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier) IdealState(org.apache.helix.model.IdealState) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 93 with IdealState

use of org.apache.helix.model.IdealState in project helix by apache.

the class TestReelectedPipelineCorrectness method testReelection.

@Test
public void testReelection() throws Exception {
    final int NUM_CONTROLLERS = 2;
    final int NUM_PARTICIPANTS = 4;
    final int NUM_PARTITIONS = 8;
    final int NUM_REPLICAS = 2;
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
    // 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, "MasterSlave", RebalanceMode.FULL_AUTO, // do rebalance
    true);
    // configure distributed controllers
    String controllerCluster = clusterName + "_controllers";
    setupTool.addCluster(controllerCluster, true);
    for (int i = 0; i < NUM_CONTROLLERS; i++) {
        setupTool.addInstanceToCluster(controllerCluster, "controller_" + i);
    }
    setupTool.activateCluster(clusterName, controllerCluster, true);
    // start participants
    MockParticipantManager[] participants = new MockParticipantManager[NUM_PARTICIPANTS];
    for (int i = 0; i < NUM_PARTICIPANTS; i++) {
        final String instanceName = "localhost_" + (12918 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participants[i].syncStart();
    }
    // start controllers
    ClusterDistributedController[] controllers = new ClusterDistributedController[NUM_CONTROLLERS];
    for (int i = 0; i < NUM_CONTROLLERS; i++) {
        controllers[i] = new ClusterDistributedController(ZK_ADDR, controllerCluster, "controller_" + i);
        controllers[i].syncStart();
    }
    Thread.sleep(1000);
    // Ensure a balanced cluster
    boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // Disable the leader, resulting in a leader election
    HelixDataAccessor accessor = participants[0].getHelixDataAccessor();
    LiveInstance leader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
    int totalWait = 0;
    while (leader == null && totalWait < CHECK_TIMEOUT) {
        Thread.sleep(CHECK_INTERVAL);
        totalWait += CHECK_INTERVAL;
        leader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
    }
    if (totalWait >= CHECK_TIMEOUT) {
        Assert.fail("No leader was ever elected!");
    }
    String leaderId = leader.getId();
    String standbyId = (leaderId.equals("controller_0")) ? "controller_1" : "controller_0";
    HelixAdmin admin = setupTool.getClusterManagementTool();
    admin.enableInstance(controllerCluster, leaderId, false);
    // Stop a participant to make sure that the leader election worked
    Thread.sleep(500);
    participants[0].syncStop();
    Thread.sleep(500);
    result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // Disable the original standby (leaving 0 active controllers) and kill another participant
    admin.enableInstance(controllerCluster, standbyId, false);
    Thread.sleep(500);
    participants[1].syncStop();
    // Also change the ideal state
    IdealState idealState = admin.getResourceIdealState(clusterName, "TestDB0");
    idealState.setMaxPartitionsPerInstance(1);
    admin.setResourceIdealState(clusterName, "TestDB0", idealState);
    Thread.sleep(500);
    // Also disable an instance in the main cluster
    admin.enableInstance(clusterName, "localhost_12920", false);
    // Re-enable the original leader
    admin.enableInstance(controllerCluster, leaderId, true);
    // Now check that both the ideal state and the live instances are adhered to by the rebalance
    Thread.sleep(500);
    result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // cleanup
    for (int i = 0; i < NUM_CONTROLLERS; i++) {
        controllers[i].syncStop();
    }
    for (int i = 2; i < NUM_PARTICIPANTS; i++) {
        participants[i].syncStop();
    }
    System.out.println("STOP " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ClusterSetup(org.apache.helix.tools.ClusterSetup) HelixAdmin(org.apache.helix.HelixAdmin) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) IdealState(org.apache.helix.model.IdealState) ClusterDistributedController(org.apache.helix.integration.manager.ClusterDistributedController) HelixDataAccessor(org.apache.helix.HelixDataAccessor) LiveInstance(org.apache.helix.model.LiveInstance) Test(org.testng.annotations.Test)

Example 94 with IdealState

use of org.apache.helix.model.IdealState in project helix by apache.

the class TestRenamePartition method testRenamePartitionCustomIS.

@Test()
public void testRenamePartitionCustomIS() throws Exception {
    String clusterName = "CLUSTER_" + getShortClassName() + "_custom";
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    // participant start port
    TestHelper.setupCluster(// participant start port
    clusterName, // participant start port
    ZK_ADDR, // participant start port
    12918, // participant name prefix
    "localhost", // resource name prefix
    "TestDB", // resources
    1, // partitions per resource
    10, // number of nodes
    5, // replicas
    3, "MasterSlave", // do rebalance
    false);
    // calculate idealState
    List<String> instanceNames = Arrays.asList("localhost_12918", "localhost_12919", "localhost_12920", "localhost_12921", "localhost_12922");
    ZNRecord destIS = DefaultIdealStateCalculator.calculateIdealState(instanceNames, 10, 3 - 1, "TestDB0", "MASTER", "SLAVE");
    IdealState idealState = new IdealState(destIS);
    idealState.setRebalanceMode(RebalanceMode.CUSTOMIZED);
    idealState.setReplicas("3");
    idealState.setStateModelDefRef("MasterSlave");
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    Builder keyBuilder = accessor.keyBuilder();
    accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);
    startAndVerify(clusterName);
    Map<String, String> stateMap = idealState.getRecord().getMapFields().remove("TestDB0_0");
    idealState.getRecord().getMapFields().put("TestDB0_100", stateMap);
    accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);
    boolean result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    stop(clusterName);
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : Builder(org.apache.helix.PropertyKey.Builder) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) Date(java.util.Date) ZNRecord(org.apache.helix.ZNRecord) IdealState(org.apache.helix.model.IdealState) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Example 95 with IdealState

use of org.apache.helix.model.IdealState in project helix by apache.

the class TestResourceGroupEndtoEnd method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    _admin = new ZKHelixAdmin(_gZkClient);
    // setup storage cluster
    _gSetupTool.addCluster(CLUSTER_NAME, true);
    List<String> instanceGroupTags = new ArrayList<String>();
    for (int i = 0; i < INSTANCE_GROUP_NR; i++) {
        String groupTag = "cluster_" + i;
        addInstanceGroup(CLUSTER_NAME, groupTag, GROUP_NODE_NR);
        instanceGroupTags.add(groupTag);
    }
    for (String tag : instanceGroupTags) {
        List<String> instances = _admin.getInstancesInClusterWithTag(CLUSTER_NAME, tag);
        IdealState idealState = createIdealState(TEST_DB, tag, instances, PARTITIONS, _replica, IdealState.RebalanceMode.CUSTOMIZED.toString(), BuiltInStateModelDefinitions.OnlineOffline.name());
        _gSetupTool.addResourceToCluster(CLUSTER_NAME, idealState.getResourceName(), idealState);
    }
    // start dummy participants
    int i = 0;
    for (String group : instanceGroupTags) {
        List<String> instances = _admin.getInstancesInClusterWithTag(CLUSTER_NAME, group);
        for (String instance : instances) {
            _participants[i] = new TestParticipantManager(ZK_ADDR, CLUSTER_NAME, TEST_DB, group, instance);
            _participants[i].syncStart();
            i++;
        }
    }
    // start controller
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME));
    Assert.assertTrue(result);
    // start speculator
    _routingTableProvider = new RoutingTableProvider();
    _spectator = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "spectator", InstanceType.SPECTATOR, ZK_ADDR);
    _spectator.connect();
    _spectator.addExternalViewChangeListener(_routingTableProvider);
    Thread.sleep(1000);
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) ArrayList(java.util.ArrayList) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) IdealState(org.apache.helix.model.IdealState) RoutingTableProvider(org.apache.helix.spectator.RoutingTableProvider) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

IdealState (org.apache.helix.model.IdealState)250 Test (org.testng.annotations.Test)110 ZNRecord (org.apache.helix.ZNRecord)69 ExternalView (org.apache.helix.model.ExternalView)54 ArrayList (java.util.ArrayList)50 HelixAdmin (org.apache.helix.HelixAdmin)42 HashMap (java.util.HashMap)38 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)35 Date (java.util.Date)33 HelixDataAccessor (org.apache.helix.HelixDataAccessor)33 Builder (org.apache.helix.PropertyKey.Builder)33 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)33 HashSet (java.util.HashSet)31 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)28 Map (java.util.Map)26 PropertyKey (org.apache.helix.PropertyKey)26 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)24 StateModelDefinition (org.apache.helix.model.StateModelDefinition)23 List (java.util.List)21 HelixException (org.apache.helix.HelixException)21