Search in sources :

Example 11 with HelixClusterVerifier

use of org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier in project helix by apache.

the class TestDrop method testDropErrorPartitionFailedAutoIS.

@Test
public void testDropErrorPartitionFailedAutoIS() throws Exception {
    // Logger.getRootLogger().setLevel(Level.INFO);
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    final int n = 5;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    MockParticipantManager[] participants = new MockParticipantManager[n];
    // 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
    8, // number of nodes
    n, // replicas
    3, "MasterSlave", // do rebalance
    true);
    // start controller
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    // start participants
    Map<String, Set<String>> errTransitions = new HashMap<String, Set<String>>();
    errTransitions.put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
    errTransitions.put("ERROR-DROPPED", TestHelper.setOf("TestDB0_4"));
    for (int i = 0; i < n; i++) {
        String instanceName = "localhost_" + (12918 + i);
        if (i == 0) {
            participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
            participants[i].setTransition(new ErrTransition(errTransitions));
        } else {
            participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        }
        participants[i].syncStart();
    }
    Map<String, Map<String, String>> errStateMap = new HashMap<>();
    errStateMap.put("TestDB0", new HashMap<String, String>());
    errStateMap.get("TestDB0").put("TestDB0_4", "localhost_12918");
    HelixClusterVerifier verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).setErrStates(errStateMap).build();
    Assert.assertTrue(verifier.verify());
    // drop resource containing error partitions should invoke error->dropped transition
    // if error happens during error->dropped transition, partition should be disabled
    ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--dropResource", clusterName, "TestDB0" });
    Thread.sleep(100);
    // make sure TestDB0_4 stay in ERROR state and is disabled
    Assert.assertTrue(verifier.verify());
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
    InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig("localhost_12918"));
    List<String> disabledPartitions = config.getDisabledPartitions();
    // System.out.println("disabledPartitions: " + disabledPartitions);
    Assert.assertEquals(disabledPartitions.size(), 1, "TestDB0_4 should be disabled");
    Assert.assertEquals(disabledPartitions.get(0), "TestDB0_4");
    // ExteranlView should have TestDB0_4->localhost_12918_>ERROR
    Thread.sleep(2000);
    ExternalView ev = accessor.getProperty(keyBuilder.externalView("TestDB0"));
    Set<String> partitions = ev.getPartitionSet();
    Assert.assertEquals(partitions.size(), 1, "Should have TestDB0_4->localhost_12918->ERROR");
    String errPartition = partitions.iterator().next();
    Assert.assertEquals(errPartition, "TestDB0_4");
    Map<String, String> stateMap = ev.getStateMap(errPartition);
    Assert.assertEquals(stateMap.size(), 1);
    Assert.assertEquals(stateMap.keySet().iterator().next(), "localhost_12918");
    Assert.assertEquals(stateMap.get("localhost_12918"), HelixDefinedState.ERROR.name());
    // localhost_12918 should have TestDB0_4 in ERROR state
    CurrentState cs = accessor.getProperty(keyBuilder.currentState(participants[0].getInstanceName(), participants[0].getSessionId(), "TestDB0"));
    Map<String, String> partitionStateMap = cs.getPartitionStateMap();
    Assert.assertEquals(partitionStateMap.size(), 1);
    Assert.assertEquals(partitionStateMap.keySet().iterator().next(), "TestDB0_4");
    Assert.assertEquals(partitionStateMap.get("TestDB0_4"), HelixDefinedState.ERROR.name());
    // all other participants should have cleaned up empty current state
    for (int i = 1; i < n; i++) {
        String instanceName = participants[i].getInstanceName();
        String sessionId = participants[i].getSessionId();
        Assert.assertNull(accessor.getProperty(keyBuilder.currentState(instanceName, sessionId, "TestDB0")));
    }
    // 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) Set(java.util.Set) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) HashMap(java.util.HashMap) InstanceConfig(org.apache.helix.model.InstanceConfig) CurrentState(org.apache.helix.model.CurrentState) BestPossibleExternalViewVerifier(org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier) ZNRecord(org.apache.helix.ZNRecord) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) HelixClusterVerifier(org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier) ErrTransition(org.apache.helix.mock.participant.ErrTransition) Date(java.util.Date) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) HashMap(java.util.HashMap) Map(java.util.Map) PropertyKey(org.apache.helix.PropertyKey) Test(org.testng.annotations.Test)

Example 12 with HelixClusterVerifier

use of org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier in project helix by apache.

the class TestDrop method testDropErrorPartitionAutoIS.

@Test
public void testDropErrorPartitionAutoIS() throws Exception {
    // Logger.getRootLogger().setLevel(Level.INFO);
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    final int n = 5;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    MockParticipantManager[] participants = new MockParticipantManager[n];
    // 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
    n, // replicas
    3, "MasterSlave", // do rebalance
    true);
    // start controller
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    // start participants
    Map<String, Set<String>> errTransitions = new HashMap<String, Set<String>>();
    errTransitions.put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
    errTransitions.put("OFFLINE-SLAVE", TestHelper.setOf("TestDB0_8"));
    for (int i = 0; i < n; i++) {
        String instanceName = "localhost_" + (12918 + i);
        if (i == 0) {
            participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
            participants[i].setTransition(new ErrTransition(errTransitions));
        } else {
            participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        }
        participants[i].syncStart();
    }
    Map<String, Map<String, String>> errStateMap = new HashMap<String, Map<String, String>>();
    errStateMap.put("TestDB0", new HashMap<String, String>());
    errStateMap.get("TestDB0").put("TestDB0_4", "localhost_12918");
    errStateMap.get("TestDB0").put("TestDB0_8", "localhost_12918");
    HelixClusterVerifier verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).setErrStates(errStateMap).build();
    Assert.assertTrue(verifier.verify());
    // drop resource containing error partitions should drop the partition successfully
    ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--dropResource", clusterName, "TestDB0" });
    // make sure TestDB0_4 and TestDB0_8 partitions are dropped
    verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).build();
    Assert.assertTrue(verifier.verify());
    assertEmptyCSandEV(className, "TestDB0", participants);
    // 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 : HelixClusterVerifier(org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier) Set(java.util.Set) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) HashMap(java.util.HashMap) ErrTransition(org.apache.helix.mock.participant.ErrTransition) Date(java.util.Date) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) BestPossibleExternalViewVerifier(org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 13 with HelixClusterVerifier

use of org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier in project helix by apache.

the class TestBatchMessageWrapper method testBasic.

@Test
public void testBasic() throws Exception {
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    final int n = 2;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    // startPort
    TestHelper.setupCluster(// startPort
    clusterName, // startPort
    ZK_ADDR, // startPort
    12918, // participantNamePrefix
    "localhost", // resourceNamePrefix
    "TestDB", // resourceNb
    1, // partitionNb
    2, // nodesNb
    n, // replica
    2, "MasterSlave", true);
    // enable batch-message
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    Builder keyBuilder = accessor.keyBuilder();
    IdealState idealState = accessor.getProperty(keyBuilder.idealStates("TestDB0"));
    idealState.setBatchMessageMode(true);
    accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    // start participants
    MockParticipantManager[] participants = new MockParticipantManager[n];
    TestMockMSModelFactory[] ftys = new TestMockMSModelFactory[n];
    for (int i = 0; i < n; i++) {
        String instanceName = "localhost_" + (12918 + i);
        ftys[i] = new TestMockMSModelFactory();
        participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participants[i].getStateMachineEngine().registerStateModelFactory("MasterSlave", ftys[i]);
        participants[i].syncStart();
        // wait for each participant to complete state transitions, so we have deterministic results
        HelixClusterVerifier _clusterVerifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).build();
        Thread.sleep(100);
        Assert.assertTrue(_clusterVerifier.verify(), "participant: " + instanceName + " fails to complete all transitions");
    }
    // check batch-msg-wrapper counts
    MockBatchMsgWrapper wrapper = (MockBatchMsgWrapper) ftys[0].getBatchMessageWrapper("TestDB0");
    // System.out.println("startCount: " + wrapper._startCount);
    Assert.assertEquals(wrapper._startCount, 3, "Expect 3 batch.start: O->S, S->M, and M->S for 1st participant");
    // System.out.println("endCount: " + wrapper._endCount);
    Assert.assertEquals(wrapper._endCount, 3, "Expect 3 batch.end: O->S, S->M, and M->S for 1st participant");
    wrapper = (MockBatchMsgWrapper) ftys[1].getBatchMessageWrapper("TestDB0");
    // System.out.println("startCount: " + wrapper._startCount);
    Assert.assertEquals(wrapper._startCount, 2, "Expect 2 batch.start: O->S and S->M for 2nd participant");
    // System.out.println("endCount: " + wrapper._endCount);
    Assert.assertEquals(wrapper._startCount, 2, "Expect 2 batch.end: O->S and S->M for 2nd participant");
    // 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 : HelixClusterVerifier(org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) Builder(org.apache.helix.PropertyKey.Builder) Date(java.util.Date) IdealState(org.apache.helix.model.IdealState) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) ZNRecord(org.apache.helix.ZNRecord) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Example 14 with HelixClusterVerifier

use of org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier in project helix by apache.

the class TestCrushAutoRebalance method testZoneIsolationWithInstanceTag.

@Test(dataProvider = "rebalanceStrategies")
public void testZoneIsolationWithInstanceTag(String rebalanceStrategyName, String rebalanceStrategyClass) throws Exception {
    Set<String> tags = new HashSet<String>(_nodeToTagMap.values());
    int i = 0;
    for (String tag : tags) {
        String db = "Test-DB-Tag-" + rebalanceStrategyName + "-" + i++;
        _setupTool.addResourceToCluster(CLUSTER_NAME, db, _PARTITIONS, BuiltInStateModelDefinitions.MasterSlave.name(), RebalanceMode.FULL_AUTO + "", rebalanceStrategyClass);
        IdealState is = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db);
        is.setInstanceGroupTag(tag);
        _setupTool.getClusterManagementTool().setResourceIdealState(CLUSTER_NAME, db, is);
        _setupTool.rebalanceStorageCluster(CLUSTER_NAME, db, _replica);
        _allDBs.add(db);
    }
    Thread.sleep(300);
    HelixClusterVerifier _clusterVerifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).setResources(_allDBs).build();
    Assert.assertTrue(_clusterVerifier.verify());
    for (String db : _allDBs) {
        IdealState is = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db);
        ExternalView ev = _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db);
        validateZoneAndTagIsolation(is, ev, _replica);
    }
}
Also used : ExternalView(org.apache.helix.model.ExternalView) HelixClusterVerifier(org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier) BestPossibleExternalViewVerifier(org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier) IdealState(org.apache.helix.model.IdealState) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 15 with HelixClusterVerifier

use of org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier in project helix by apache.

the class TestCrushAutoRebalance method testZoneIsolation.

@Test(dataProvider = "rebalanceStrategies")
public void testZoneIsolation(String rebalanceStrategyName, String rebalanceStrategyClass) throws Exception {
    System.out.println("testZoneIsolation " + rebalanceStrategyName);
    int i = 0;
    for (String stateModel : _testModels) {
        String db = "Test-DB-" + rebalanceStrategyName + "-" + i++;
        _setupTool.addResourceToCluster(CLUSTER_NAME, db, _PARTITIONS, stateModel, RebalanceMode.FULL_AUTO + "", rebalanceStrategyClass);
        _setupTool.rebalanceStorageCluster(CLUSTER_NAME, db, _replica);
        _allDBs.add(db);
    }
    Thread.sleep(300);
    HelixClusterVerifier _clusterVerifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).setResources(_allDBs).build();
    Assert.assertTrue(_clusterVerifier.verify());
    for (String db : _allDBs) {
        IdealState is = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db);
        ExternalView ev = _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db);
        validateZoneAndTagIsolation(is, ev, _replica);
    }
}
Also used : ExternalView(org.apache.helix.model.ExternalView) HelixClusterVerifier(org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier) BestPossibleExternalViewVerifier(org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier) IdealState(org.apache.helix.model.IdealState) Test(org.testng.annotations.Test)

Aggregations

HelixClusterVerifier (org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier)43 Test (org.testng.annotations.Test)38 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)19 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)17 Date (java.util.Date)15 BestPossibleExternalViewVerifier (org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier)14 IdealState (org.apache.helix.model.IdealState)13 Set (java.util.Set)7 ZNRecord (org.apache.helix.ZNRecord)7 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)7 ExternalView (org.apache.helix.model.ExternalView)7 Map (java.util.Map)6 PropertyKey (org.apache.helix.PropertyKey)6 StrictMatchExternalViewVerifier (org.apache.helix.tools.ClusterVerifiers.StrictMatchExternalViewVerifier)5 HashMap (java.util.HashMap)4 ConfigAccessor (org.apache.helix.ConfigAccessor)4 HashSet (java.util.HashSet)3 ErrTransition (org.apache.helix.mock.participant.ErrTransition)3 ClusterConfig (org.apache.helix.model.ClusterConfig)3 CurrentState (org.apache.helix.model.CurrentState)3