Search in sources :

Example 21 with ZKHelixDataAccessor

use of org.apache.helix.manager.zk.ZKHelixDataAccessor in project helix by apache.

the class TestDistributedCMMain method testDistributedCMMain.

@Test
public void testDistributedCMMain() 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 + 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");
    // add more controllers to controller cluster
    ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
    for (int i = 0; i < n; i++) {
        String controller = "controller_" + (n + i);
        setupTool.addInstanceToCluster(controllerClusterName, controller);
    }
    setupTool.rebalanceStorageCluster(controllerClusterName, clusterNamePrefix + "0", 6);
    for (int i = n; i < 2 * n; i++) {
        controllers[i] = new ClusterDistributedController(ZK_ADDR, controllerClusterName, "controller_" + i);
        controllers[i].syncStart();
    }
    // verify controller cluster
    result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName));
    Assert.assertTrue(result, "Controller cluster NOT in ideal state");
    // verify first cluster
    result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, firstClusterName));
    Assert.assertTrue(result, "first cluster NOT in ideal state");
    // stop controller_0-5
    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(controllerClusterName, baseAccessor);
    Builder keyBuilder = accessor.keyBuilder();
    for (int i = 0; i < n; i++) {
        LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
        String leaderName = leader.getId();
        int j = Integer.parseInt(leaderName.substring(leaderName.lastIndexOf('_') + 1));
        controllers[j].syncStop();
        result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName));
        Assert.assertTrue(result, "Controller cluster NOT in ideal state");
        result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, firstClusterName));
        Assert.assertTrue(result, "first 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 ClusterStateVerifier.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) ClusterSetup(org.apache.helix.tools.ClusterSetup) 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 22 with ZKHelixDataAccessor

use of org.apache.helix.manager.zk.ZKHelixDataAccessor 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 23 with ZKHelixDataAccessor

use of org.apache.helix.manager.zk.ZKHelixDataAccessor 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 24 with ZKHelixDataAccessor

use of org.apache.helix.manager.zk.ZKHelixDataAccessor in project helix by apache.

the class TestResetPartitionState method clearStatusUpdate.

private void clearStatusUpdate(String clusterName, String instance, String resource, String partition) {
    // clear status update for error partition so verify() will not fail on old
    // errors
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    Builder keyBuilder = accessor.keyBuilder();
    LiveInstance liveInstance = accessor.getProperty(keyBuilder.liveInstance(instance));
    accessor.removeProperty(keyBuilder.stateTransitionStatus(instance, liveInstance.getSessionId(), resource, partition));
}
Also used : LiveInstance(org.apache.helix.model.LiveInstance) Builder(org.apache.helix.PropertyKey.Builder) ZNRecord(org.apache.helix.ZNRecord) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor)

Example 25 with ZKHelixDataAccessor

use of org.apache.helix.manager.zk.ZKHelixDataAccessor 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)

Aggregations

ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)104 ZNRecord (org.apache.helix.ZNRecord)78 Date (java.util.Date)66 Test (org.testng.annotations.Test)66 Builder (org.apache.helix.PropertyKey.Builder)47 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)41 HelixDataAccessor (org.apache.helix.HelixDataAccessor)38 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)37 IdealState (org.apache.helix.model.IdealState)33 ZkBaseDataAccessor (org.apache.helix.manager.zk.ZkBaseDataAccessor)30 PropertyKey (org.apache.helix.PropertyKey)29 ExternalView (org.apache.helix.model.ExternalView)21 BestPossAndExtViewZkVerifier (org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier)21 LiveInstance (org.apache.helix.model.LiveInstance)20 ClusterStateVerifier (org.apache.helix.tools.ClusterStateVerifier)16 HelixManager (org.apache.helix.HelixManager)15 Message (org.apache.helix.model.Message)12 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)11 HashMap (java.util.HashMap)10 ZkClient (org.apache.helix.manager.zk.ZkClient)10