Search in sources :

Example 11 with BestPossAndExtViewZkVerifier

use of org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier in project helix by apache.

the class TestDistributedClusterController method testDistributedClusterController.

@Test
public void testDistributedClusterController() throws Exception {
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterNamePrefix = className + "_" + methodName;
    final int n = 5;
    final int clusterNb = 10;
    System.out.println("START " + clusterNamePrefix + " at " + new Date(System.currentTimeMillis()));
    // setup 10 clusters
    for (int i = 0; i < clusterNb; i++) {
        String clusterName = clusterNamePrefix + "0_" + i;
        String participantName = "localhost" + i;
        String resourceName = "TestDB" + i;
        // participant port
        TestHelper.setupCluster(// participant port
        clusterName, // participant port
        ZK_ADDR, // participant port
        12918, // participant name prefix
        participantName, // resource name prefix
        resourceName, // resources
        1, // partitions per resource
        8, // number of nodes
        n, // replicas
        3, "MasterSlave", // do rebalance
        true);
    }
    // setup controller cluster
    final String controllerClusterName = "CONTROLLER_" + clusterNamePrefix;
    // controller
    TestHelper.setupCluster(// controller
    "CONTROLLER_" + clusterNamePrefix, // controller
    ZK_ADDR, // controller
    0, // participant name prefix
    "controller", // resource name prefix
    clusterNamePrefix, // resources
    1, // partitions per resource
    clusterNb, // number of nodes
    n, // replicas
    3, "LeaderStandby", // do rebalance
    true);
    // start distributed cluster controllers
    ClusterDistributedController[] controllers = new ClusterDistributedController[n];
    for (int i = 0; i < n; i++) {
        controllers[i] = new ClusterDistributedController(ZK_ADDR, controllerClusterName, "controller_" + i);
        controllers[i].syncStart();
    }
    boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName), 30000);
    Assert.assertTrue(result, "Controller cluster NOT in ideal state");
    // start first cluster
    MockParticipantManager[] participants = new MockParticipantManager[n];
    final String firstClusterName = clusterNamePrefix + "0_0";
    for (int i = 0; i < n; i++) {
        String instanceName = "localhost0_" + (12918 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, firstClusterName, instanceName);
        participants[i].syncStart();
    }
    result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, firstClusterName));
    Assert.assertTrue(result, "first cluster NOT in ideal state");
    // stop current leader in controller cluster
    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(controllerClusterName, baseAccessor);
    Builder keyBuilder = accessor.keyBuilder();
    LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
    String leaderName = leader.getId();
    int j = Integer.parseInt(leaderName.substring(leaderName.lastIndexOf('_') + 1));
    controllers[j].syncStop();
    // setup the second cluster
    MockParticipantManager[] participants2 = new MockParticipantManager[n];
    final String secondClusterName = clusterNamePrefix + "0_1";
    for (int i = 0; i < n; i++) {
        String instanceName = "localhost1_" + (12918 + i);
        participants2[i] = new MockParticipantManager(ZK_ADDR, secondClusterName, instanceName);
        participants2[i].syncStart();
    }
    result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, secondClusterName));
    Assert.assertTrue(result, "second cluster NOT in ideal state");
    // clean up
    // wait for all zk callbacks done
    System.out.println("Cleaning up...");
    for (int i = 0; i < 5; i++) {
        result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName));
        controllers[i].syncStop();
    }
    for (int i = 0; i < 5; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterNamePrefix + " at " + new Date(System.currentTimeMillis()));
}
Also used : ZkBaseDataAccessor(org.apache.helix.manager.zk.ZkBaseDataAccessor) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) Builder(org.apache.helix.PropertyKey.Builder) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) ClusterDistributedController(org.apache.helix.integration.manager.ClusterDistributedController) LiveInstance(org.apache.helix.model.LiveInstance) ZNRecord(org.apache.helix.ZNRecord) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Example 12 with BestPossAndExtViewZkVerifier

use of org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier 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 13 with BestPossAndExtViewZkVerifier

use of org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier in project helix by apache.

the class TestSchemataSM method testSchemataSM.

@Test
public void testSchemataSM() throws Exception {
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    int n = 5;
    MockParticipantManager[] participants = new MockParticipantManager[n];
    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
    "TestSchemata", // resources
    1, // partitions per resource
    1, // number of nodes
    n, // replicas
    0, "STORAGE_DEFAULT_SM_SCHEMATA", // don't rebalance
    false);
    // rebalance ideal-state to use ANY_LIVEINSTANCE for preference list
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
    PropertyKey key = keyBuilder.idealStates("TestSchemata0");
    IdealState idealState = accessor.getProperty(key);
    idealState.setReplicas(IdealState.IdealStateConstants.ANY_LIVEINSTANCE.toString());
    idealState.getRecord().setListField("TestSchemata0_0", Arrays.asList(IdealState.IdealStateConstants.ANY_LIVEINSTANCE.toString()));
    accessor.setProperty(key, idealState);
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
    controller.syncStart();
    // start n-1 participants
    for (int i = 1; i < n; i++) {
        String instanceName = "localhost_" + (12918 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participants[i].syncStart();
    }
    boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // start the remaining 1 participant
    participants[0] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12918");
    participants[0].syncStart();
    // make sure we have all participants in MASTER state
    result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    key = keyBuilder.externalView("TestSchemata0");
    ExternalView externalView = accessor.getProperty(key);
    Map<String, String> stateMap = externalView.getStateMap("TestSchemata0_0");
    Assert.assertNotNull(stateMap);
    Assert.assertEquals(stateMap.size(), n, "all " + n + " participants should be in Master state");
    for (int i = 0; i < n; i++) {
        String instanceName = "localhost_" + (12918 + i);
        Assert.assertNotNull(stateMap.get(instanceName));
        Assert.assertEquals(stateMap.get(instanceName), "MASTER");
    }
    // clean up
    controller.syncStop();
    for (int i = 0; i < n; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : ExternalView(org.apache.helix.model.ExternalView) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) IdealState(org.apache.helix.model.IdealState) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) ZNRecord(org.apache.helix.ZNRecord) PropertyKey(org.apache.helix.PropertyKey) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Example 14 with BestPossAndExtViewZkVerifier

use of org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier in project helix by apache.

the class TestNullReplica method testNullReplica.

@Test
public void testNullReplica() throws Exception {
    // Logger.getRootLogger().setLevel(Level.INFO);
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    MockParticipantManager[] participants = new MockParticipantManager[5];
    // 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
    10, // number of nodes
    5, // replicas
    3, "MasterSlave", // do rebalance
    true);
    // set replica in ideal state to null
    String idealStatePath = PropertyPathBuilder.idealState(clusterName, "TestDB0");
    ZNRecord idealState = _gZkClient.readData(idealStatePath);
    idealState.getSimpleFields().remove(IdealState.IdealStateProperty.REPLICAS.toString());
    _gZkClient.writeData(idealStatePath, idealState);
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    // start participants
    for (int i = 0; i < 5; i++) {
        String instanceName = "localhost_" + (12918 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participants[i].syncStart();
    }
    boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // clean up
    controller.syncStop();
    for (int i = 0; i < 5; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) ZNRecord(org.apache.helix.ZNRecord) Test(org.testng.annotations.Test)

Example 15 with BestPossAndExtViewZkVerifier

use of org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier in project helix by apache.

the class TestPauseSignal method testPauseSignal.

@Test()
public void testPauseSignal() throws Exception {
    // Logger.getRootLogger().setLevel(Level.INFO);
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    final String clusterName = className + "_" + methodName;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    MockParticipantManager[] participants = new MockParticipantManager[5];
    // 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
    10, // number of nodes
    5, // replicas
    3, "MasterSlave", // do rebalance
    true);
    // start controller
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    // start participants
    for (int i = 0; i < 5; i++) {
        String instanceName = "localhost_" + (12918 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participants[i].syncStart();
    }
    boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // pause the cluster and make sure pause is persistent
    ZkClient zkClient = new ZkClient(ZK_ADDR);
    zkClient.setZkSerializer(new ZNRecordSerializer());
    final HelixDataAccessor tmpAccessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
    String cmd = "-zkSvr " + ZK_ADDR + " -enableCluster " + clusterName + " false";
    ClusterSetup.processCommandLineArgs(cmd.split(" "));
    tmpAccessor.setProperty(tmpAccessor.keyBuilder().pause(), new PauseSignal("pause"));
    zkClient.close();
    // wait for controller to be signaled by pause
    Thread.sleep(1000);
    // add a new resource group
    ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
    setupTool.addResourceToCluster(clusterName, "TestDB1", 10, "MasterSlave");
    setupTool.rebalanceStorageCluster(clusterName, "TestDB1", 3);
    // make sure TestDB1 external view is empty
    TestHelper.verifyWithTimeout("verifyEmptyCurStateAndExtView", 1000, clusterName, "TestDB1", TestHelper.<String>setOf("localhost_12918", "localhost_12919", "localhost_12920", "localhost_12921", "localhost_12922"), ZK_ADDR);
    // resume controller
    final HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    cmd = "-zkSvr " + ZK_ADDR + " -enableCluster " + clusterName + " true";
    ClusterSetup.processCommandLineArgs(cmd.split(" "));
    result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // clean up
    controller.syncStop();
    for (int i = 0; i < 5; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ClusterSetup(org.apache.helix.tools.ClusterSetup) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) HelixDataAccessor(org.apache.helix.HelixDataAccessor) PauseSignal(org.apache.helix.model.PauseSignal) ZNRecord(org.apache.helix.ZNRecord) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Aggregations

BestPossAndExtViewZkVerifier (org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier)50 Test (org.testng.annotations.Test)47 Date (java.util.Date)40 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)33 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)26 ZNRecord (org.apache.helix.ZNRecord)24 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)18 HashMap (java.util.HashMap)11 HelixDataAccessor (org.apache.helix.HelixDataAccessor)11 Builder (org.apache.helix.PropertyKey.Builder)11 IdealState (org.apache.helix.model.IdealState)11 ClusterDistributedController (org.apache.helix.integration.manager.ClusterDistributedController)9 HelixAdmin (org.apache.helix.HelixAdmin)8 ZkBaseDataAccessor (org.apache.helix.manager.zk.ZkBaseDataAccessor)8 LiveInstance (org.apache.helix.model.LiveInstance)8 MasterNbInExtViewVerifier (org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier)8 ClusterSetup (org.apache.helix.tools.ClusterSetup)7 PropertyKey (org.apache.helix.PropertyKey)6 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)6 ExternalView (org.apache.helix.model.ExternalView)6