helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Zhen Zhang (JIRA)" <j...@apache.org>
Subject [jira] [Created] (HELIX-561) Participant receive same transition twice
Date Mon, 15 Dec 2014 23:34:13 GMT
Zhen Zhang created HELIX-561:
--------------------------------

             Summary: Participant receive same transition twice
                 Key: HELIX-561
                 URL: https://issues.apache.org/jira/browse/HELIX-561
             Project: Apache Helix
          Issue Type: Bug
            Reporter: Zhen Zhang


Some user reports that when upgrade from 0.6.x to 0.7.1, participant receives OFFLINE->SLAVE
transition twice for a partition.

Can't reproduce it with the following test case:
{noformat}
package org.apache.helix;

import java.util.Date;

import org.apache.helix.api.StateTransitionHandlerFactory;
import org.apache.helix.api.TransitionHandler;
import org.apache.helix.api.id.PartitionId;
import org.apache.helix.api.id.ResourceId;
import org.apache.helix.api.id.StateModelDefId;
import org.apache.helix.manager.zk.MockController;
import org.apache.helix.model.Message;
import org.apache.helix.participant.statemachine.Transition;
import org.apache.helix.testutil.TestUtil;
import org.apache.helix.testutil.ZkTestBase;
import org.testng.annotations.Test;

public class AppTest extends ZkTestBase {

  @Test
  public void test() throws Exception {
    String clusterName = TestUtil.getTestName();
    int n = 2;

    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));

    TestHelper.setupCluster(clusterName, _zkaddr, 12918, // participant port
        "localhost", // participant name prefix
        "TestDB", // resource name prefix
        1, // resources
        2, // partitions per resource
        n, // number of nodes
        2, // replicas
        "MasterSlave", true); // do rebalance

    MockController controller = new MockController(_zkaddr, clusterName, "controller");
    controller.syncStart();

    String id = "localhost_12918";
    StateModelDefId masterSlave = StateModelDefId.from("MasterSlave");
    HelixManager hManager =
        HelixManagerFactory.getZKHelixManager(clusterName, id, InstanceType.PARTICIPANT, _zkaddr);
    hManager.getStateMachineEngine().registerStateModelFactory(masterSlave,
        new MasterSlaveStateModelFactory());
    hManager.connect();

    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
  }

  class MasterSlaveStateModelFactory extends StateTransitionHandlerFactory<MasterSlaveStateModel>
{

    public MasterSlaveStateModelFactory() {

    }

    @Override
    public MasterSlaveStateModel createStateTransitionHandler(ResourceId resourceId,
        PartitionId partitionId) {
      return new MasterSlaveStateModel();
    }
  }

  public class MasterSlaveStateModel extends TransitionHandler {
    @Transition(to = "SLAVE", from = "OFFLINE")
    public void onBecomeSlaveFromOffline(Message message, NotificationContext context)
        throws Exception {
      System.out.println(message.getPartitionName() + ": OFFLINE->SLAVE");
    }

    @Transition(to = "MASTER", from = "SLAVE")
    public void onBecomeMasterFromSlave(Message message, NotificationContext context)
        throws Exception {
    }

    @Transition(to = "SLAVE", from = "MASTER")
    public void onBecomeSlaveFromMaster(Message message, NotificationContext context)
        throws Exception {
    }

    @Transition(to = "OFFLINE", from = "SLAVE")
    public void onBecomeOfflineFromSlave(Message message, NotificationContext context)
        throws Exception {
    }

    @Transition(to = "DROPPED", from = "OFFLINE")
    public void onBecomeDroppedFromOffline(Message message, NotificationContext context)
        throws Exception {
    }

    @Transition(to = "OFFLINE", from = "ERROR")
    public void onBecomeOfflineFromError(Message message, NotificationContext context)
        throws Exception {
    }

  }

}

{noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message