Search in sources :

Example 21 with BestPossAndExtViewZkVerifier

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

the class TestBatchMessage method testChangeBatchMessageMode.

// a non-batch-message run followed by a batch-message-enabled run
@Test
public void testChangeBatchMessageMode() throws Exception {
    // Logger.getRootLogger().setLevel(Level.INFO);
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    int n = 2;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    // 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
    32, // number of nodes
    n, // replicas
    2, "MasterSlave", // do rebalance
    true);
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    // start participants
    MockParticipantManager[] participants = new MockParticipantManager[n];
    for (int i = 0; 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);
    // stop all participants
    for (int i = 0; i < n; i++) {
        participants[i].syncStop();
    }
    // 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);
    // registry a message listener so we know how many message generated
    TestZkChildListener listener = new TestZkChildListener();
    _gZkClient.subscribeChildChanges(keyBuilder.messages("localhost_12918").getPath(), listener);
    // restart all participants
    for (int i = 0; i < n; i++) {
        String instanceName = "localhost_" + (12918 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participants[i].syncStart();
    }
    result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // Change to three is because there is an extra factory registered
    // So one extra NO_OP message send
    Assert.assertTrue(listener._maxNbOfChilds <= 3, "Should get no more than 2 messages (O->S and S->M)");
    // clean up
    // wait for all zk callbacks done
    controller.syncStop();
    for (int i = 0; i < n; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) Builder(org.apache.helix.PropertyKey.Builder) 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) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Example 22 with BestPossAndExtViewZkVerifier

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

the class TestBatchMessage method testParticipantIncompatibleWithBatchMsg.

@Test
public void testParticipantIncompatibleWithBatchMsg() throws Exception {
    // Logger.getRootLogger().setLevel(Level.INFO);
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    int n = 2;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    // 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
    32, // number of nodes
    n, // replicas
    2, "MasterSlave", // do rebalance
    true);
    // enable batch message
    // --addResourceProperty <clusterName resourceName propertyName propertyValue>
    ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--addResourceProperty", clusterName, "TestDB0", HelixPropertyAttribute.BATCH_MESSAGE_MODE.toString(), "true" });
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    Builder keyBuilder = accessor.keyBuilder();
    // register a message listener so we know how many message generated
    TestZkChildListener listener = new TestZkChildListener();
    _gZkClient.subscribeChildChanges(keyBuilder.messages("localhost_12918").getPath(), listener);
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    // pause controller
    // --enableCluster <clusterName true/false>
    ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--enableCluster", clusterName, "false" });
    // start participants
    MockParticipantManager[] participants = new MockParticipantManager[n];
    for (int i = 0; i < n; i++) {
        String instanceName = "localhost_" + (12918 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participants[i].syncStart();
    }
    // change localhost_12918 version to 0.5, so batch-message-mode will be ignored
    LiveInstance liveInstance = accessor.getProperty(keyBuilder.liveInstance("localhost_12918"));
    liveInstance.setHelixVersion("0.5");
    accessor.setProperty(keyBuilder.liveInstance("localhost_12918"), liveInstance);
    // resume controller
    // --enableCluster <clusterName true/false>
    ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--enableCluster", clusterName, "true" });
    boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    Assert.assertTrue(listener._maxNbOfChilds > 16, "Should see more than 16 messages at the same time (32 O->S and 32 S->M)");
    // clean up
    // wait for all zk callbacks done
    controller.syncStop();
    for (int i = 0; i < n; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) Builder(org.apache.helix.PropertyKey.Builder) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) 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 BestPossAndExtViewZkVerifier

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

the class TestMessageThrottle method testMessageThrottle.

@Test()
public void testMessageThrottle() throws Exception {
    // Logger.getRootLogger().setLevel(Level.INFO);
    String clusterName = getShortClassName();
    MockParticipantManager[] participants = new MockParticipantManager[5];
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    // participant start
    TestHelper.setupCluster(// participant start
    clusterName, // participant start
    ZK_ADDR, // participant start
    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);
    // setup message constraint
    // "MESSAGE_TYPE=STATE_TRANSITION,TRANSITION=OFFLINE-SLAVE,INSTANCE=.*,CONSTRAINT_VALUE=1";
    HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
    ConstraintItemBuilder builder = new ConstraintItemBuilder();
    builder.addConstraintAttribute("MESSAGE_TYPE", "STATE_TRANSITION").addConstraintAttribute("INSTANCE", ".*").addConstraintAttribute("CONSTRAINT_VALUE", "1");
    // Map<String, String> constraints = new TreeMap<String, String>();
    // constraints.put("MESSAGE_TYPE", "STATE_TRANSITION");
    // // constraints.put("TRANSITION", "OFFLINE-SLAVE");
    // constraints.put("CONSTRAINT_VALUE", "1");
    // constraints.put("INSTANCE", ".*");
    admin.setConstraint(clusterName, ConstraintType.MESSAGE_CONSTRAINT, "constraint1", builder.build());
    final ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    // make sure we never see more than 1 state transition message for each participant
    final AtomicBoolean success = new AtomicBoolean(true);
    for (int i = 0; i < 5; i++) {
        String instanceName = "localhost_" + (12918 + i);
        String msgPath = PropertyPathBuilder.instanceMessage(clusterName, instanceName);
        _gZkClient.subscribeChildChanges(msgPath, new IZkChildListener() {

            @Override
            public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
                if (currentChilds != null && currentChilds.size() > 1) {
                    List<ZNRecord> records = accessor.getBaseDataAccessor().getChildren(parentPath, null, 0);
                    int transitionMsgCount = 0;
                    for (ZNRecord record : records) {
                        Message msg = new Message(record);
                        if (msg.getMsgType().equals(Message.MessageType.STATE_TRANSITION.name())) {
                            transitionMsgCount++;
                        }
                    }
                    if (transitionMsgCount > 1) {
                        success.set(false);
                        Assert.fail("Should not see more than 1 message");
                    }
                }
            }
        });
    }
    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 MasterNbInExtViewVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    Assert.assertTrue(success.get());
    // 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 : MasterNbInExtViewVerifier(org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) Message(org.apache.helix.model.Message) ConstraintItemBuilder(org.apache.helix.model.builder.ConstraintItemBuilder) HelixAdmin(org.apache.helix.HelixAdmin) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) IZkChildListener(org.I0Itec.zkclient.IZkChildListener) List(java.util.List) ZNRecord(org.apache.helix.ZNRecord) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Example 24 with BestPossAndExtViewZkVerifier

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

the class TestMessageThrottle2 method test.

@Test
public void test() throws Exception {
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    startAdmin();
    startController();
    // start node2 first
    Node.main(new String[] { "2" });
    // wait for node2 becoming MASTER
    final Builder keyBuilder = new Builder(clusterName);
    final HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    TestHelper.verify(new TestHelper.Verifier() {

        @Override
        public boolean verify() throws Exception {
            ExternalView view = accessor.getProperty(keyBuilder.externalView(resourceName));
            String state = null;
            if (view != null) {
                Map<String, String> map = view.getStateMap(resourceName);
                if (map != null) {
                    state = map.get("node2");
                }
            }
            return state != null && state.equals("MASTER");
        }
    }, 10 * 1000);
    // start node 1
    Node.main(new String[] { "1" });
    boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : ExternalView(org.apache.helix.model.ExternalView) ConstraintItemBuilder(org.apache.helix.model.builder.ConstraintItemBuilder) Builder(org.apache.helix.PropertyKey.Builder) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) TestHelper(org.apache.helix.TestHelper) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) HelixDataAccessor(org.apache.helix.HelixDataAccessor) HashMap(java.util.HashMap) Map(java.util.Map) ZNRecord(org.apache.helix.ZNRecord) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Example 25 with BestPossAndExtViewZkVerifier

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

the class TestParticipantErrorMessage method TestParticipantErrorMessageSend.

@Test()
public void TestParticipantErrorMessageSend() {
    String participant1 = "localhost_" + START_PORT;
    String participant2 = "localhost_" + (START_PORT + 1);
    Message errorMessage1 = new Message(MessageType.PARTICIPANT_ERROR_REPORT, UUID.randomUUID().toString());
    errorMessage1.setTgtSessionId("*");
    errorMessage1.getRecord().setSimpleField(DefaultParticipantErrorMessageHandlerFactory.ACTIONKEY, ActionOnError.DISABLE_INSTANCE.toString());
    Criteria recipientCriteria = new Criteria();
    recipientCriteria.setRecipientInstanceType(InstanceType.CONTROLLER);
    recipientCriteria.setSessionSpecific(false);
    _participants[0].getMessagingService().send(recipientCriteria, errorMessage1);
    Message errorMessage2 = new Message(MessageType.PARTICIPANT_ERROR_REPORT, UUID.randomUUID().toString());
    errorMessage2.setTgtSessionId("*");
    errorMessage2.setResourceName("TestDB");
    errorMessage2.setPartitionName("TestDB_14");
    errorMessage2.getRecord().setSimpleField(DefaultParticipantErrorMessageHandlerFactory.ACTIONKEY, ActionOnError.DISABLE_PARTITION.toString());
    Criteria recipientCriteria2 = new Criteria();
    recipientCriteria2.setRecipientInstanceType(InstanceType.CONTROLLER);
    recipientCriteria2.setSessionSpecific(false);
    _participants[1].getMessagingService().send(recipientCriteria2, errorMessage2);
    try {
        Thread.sleep(1500);
    } catch (InterruptedException e) {
        LOG.error("Interrupted sleep", e);
    }
    boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME));
    Assert.assertTrue(result);
    Builder kb = _participants[1].getHelixDataAccessor().keyBuilder();
    ExternalView externalView = _participants[1].getHelixDataAccessor().getProperty(kb.externalView("TestDB"));
    for (String partitionName : externalView.getRecord().getMapFields().keySet()) {
        for (String hostName : externalView.getRecord().getMapField(partitionName).keySet()) {
            if (hostName.equals(participant1)) {
                Assert.assertTrue(externalView.getRecord().getMapField(partitionName).get(hostName).equalsIgnoreCase("OFFLINE"));
            }
        }
    }
    Assert.assertTrue(externalView.getRecord().getMapField("TestDB_14").get(participant2).equalsIgnoreCase("OFFLINE"));
}
Also used : ExternalView(org.apache.helix.model.ExternalView) Message(org.apache.helix.model.Message) Builder(org.apache.helix.PropertyKey.Builder) Criteria(org.apache.helix.Criteria) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) 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