Package org.apache.helix.api.id

Examples of org.apache.helix.api.id.PartitionId


      LOGGER.info(instanceName + " becomes SLAVE from OFFLINE for " + partitionId);
    }

    @Transition(to = "SLAVE", from = "MASTER")
    public void onBecomeSlaveFromMaster(Message message, NotificationContext context) {
      PartitionId partitionId = message.getPartitionId();
      String instanceName = message.getTgtName();
      LOGGER.info(instanceName + " becomes SLAVE from MASTER for " + partitionId);
    }
View Full Code Here


      LOGGER.info(instanceName + " becomes SLAVE from MASTER for " + partitionId);
    }

    @Transition(to = "MASTER", from = "SLAVE")
    public void onBecomeMasterFromSlave(Message message, NotificationContext context) {
      PartitionId partitionId = message.getPartitionId();
      String instanceName = message.getTgtName();
      LOGGER.info(instanceName + " becomes MASTER from SLAVE for " + partitionId);
    }
View Full Code Here

      LOGGER.info(instanceName + " becomes MASTER from SLAVE for " + partitionId);
    }

    @Transition(to = "OFFLINE", from = "SLAVE")
    public void onBecomeOfflineFromSlave(Message message, NotificationContext context) {
      PartitionId partitionId = message.getPartitionId();
      String instanceName = message.getTgtName();
      LOGGER.info(instanceName + " becomes OFFLINE from SLAVE for " + partitionId);
    }
View Full Code Here

      LOGGER.info(instanceName + " becomes OFFLINE from SLAVE for " + partitionId);
    }

    @Transition(to = "DROPPED", from = "OFFLINE")
    public void onBecomeDroppedFromOffline(Message message, NotificationContext context) {
      PartitionId partitionId = message.getPartitionId();
      String instanceName = message.getTgtName();
      LOGGER.info(instanceName + " becomes DROPPED from OFFLINE for " + partitionId);
    }
View Full Code Here

      LOGGER.info(instanceName + " becomes DROPPED from OFFLINE for " + partitionId);
    }

    @Transition(to = "OFFLINE", from = "ERROR")
    public void onBecomeOfflineFromError(Message message, NotificationContext context) {
      PartitionId partitionId = message.getPartitionId();
      String instanceName = message.getTgtName();
      LOGGER.info(instanceName + " becomes OFFLINE from ERROR for " + partitionId);
    }
View Full Code Here

        new StateModelDefinition.Builder(stateModelDefId).addState(master, 1).addState(slave, 2)
            .addState(offline, 3).addState(dropped).addTransition(offline, slave, 3)
            .addTransition(slave, offline, 4).addTransition(slave, master, 2)
            .addTransition(master, slave, 1).addTransition(offline, dropped).initialState(offline)
            .upperBound(master, 1).dynamicUpperBound(slave, "R").build();
    PartitionId partition0 = PartitionId.from(resourceId, "0");
    AutoModeISBuilder idealStateBuilder = new AutoModeISBuilder(resourceId).add(partition0);
    idealStateBuilder.setNumReplica(1).setStateModelDefId(stateModelDefId);
    idealStateBuilder.assignPreferenceList(partition0, participantId);
    IdealState idealState = idealStateBuilder.build();
    clusterAccessor.createCluster(new ClusterConfig.Builder(clusterId).addStateModelDefinition(
View Full Code Here

          continue;
        }
        IdealState idealState = resource.getIdealState();

        if (!message.getBatchMessageMode()) {
          PartitionId partitionId = message.getPartitionId();
          if (idealState.getPartitionIdSet().contains(partitionId)) {
            currentStateOutput.setPendingState(resourceId, partitionId, participantId,
                message.getTypedToState());
          } else {
            // log
View Full Code Here

    public void doTransition(Message message, NotificationContext context) {
      HelixManager manager = context.getManager();
      String clusterName = manager.getClusterName();

      String instance = message.getTgtName();
      PartitionId partitionId = message.getPartitionId();
      State fromState = message.getTypedFromState();
      State toState = message.getTypedToState();
      if (instance.equals("localhost_12919") && partitionId.equals(PartitionId.from("TestDB0_0"))) {
        if (fromState.equals("SLAVE") && toState.equals("OFFLINE")) {
          slaveToOfflineCnt++;

          try {
            String command =
View Full Code Here

      throw new HelixException(errorMessage);
    }

    HelixDataAccessor accessor = _manager.getHelixDataAccessor();

    PartitionId partitionId = _message.getPartitionId();
    State fromState = _message.getTypedFromState();

    // Verify the fromState and current state of the stateModel
    String state = _currentStateDelta.getState(partitionId.stringify());

    if (fromState != null && !fromState.equals("*")
        && !fromState.toString().equalsIgnoreCase(state)) {
      String errorMessage =
          "Current state of stateModel does not match the fromState in Message"
View Full Code Here

  void postHandleMessage() {
    HelixTaskResult taskResult =
        (HelixTaskResult) _notificationContext.get(MapKey.HELIX_TASK_RESULT.toString());
    Exception exception = taskResult.getException();

    PartitionId partitionId = _message.getPartitionId();
    ResourceId resource = _message.getResourceId();
    SessionId sessionId = _message.getTypedTgtSessionId();
    String instanceName = _manager.getInstanceName();

    HelixDataAccessor accessor = _manager.getHelixDataAccessor();
    Builder keyBuilder = accessor.keyBuilder();

    int bucketSize = _message.getBucketSize();
    ZNRecordBucketizer bucketizer = new ZNRecordBucketizer(bucketSize);

    // No need to sync on manager, we are cancel executor in expiry session before start executor in
    // new session
    // sessionId might change when we update the state model state.
    // for zk current state it is OK as we have the per-session current state node
    if (!_message.getTypedTgtSessionId().stringify().equals(_manager.getSessionId())) {
      logger.warn("Session id has changed. Skip postExecutionMessage. Old session "
          + _message.getTypedExecutionSessionId() + " , new session : " + _manager.getSessionId());
      return;
    }

    if (taskResult.isSuccess()) {
      // String fromState = message.getFromState();
      State toState = _message.getTypedToState();
      _currentStateDelta.setState(partitionId, toState);

      if (toState.toString().equalsIgnoreCase(HelixDefinedState.DROPPED.toString())) {
        // for "OnOfflineToDROPPED" message, we need to remove the resource key record
        // from the current state of the instance because the resource key is dropped.
        // In the state model it will be stayed as "OFFLINE", which is OK.
        ZNRecordDelta delta =
            new ZNRecordDelta(_currentStateDelta.getRecord(), MergeOperation.SUBTRACT);
        // Don't subtract simple fields since they contain stateModelDefRef
        delta._record.getSimpleFields().clear();

        List<ZNRecordDelta> deltaList = new ArrayList<ZNRecordDelta>();
        deltaList.add(delta);
        _currentStateDelta.setDeltaList(deltaList);
        _stateModelFactory.removeStateModel(partitionId.stringify());
      } else {
        // if the partition is not to be dropped, update _stateModel to the TO_STATE
        _stateModel.updateState(toState.toString());
      }
    } else {
      if (exception instanceof HelixStateMismatchException) {
        // if fromState mismatch, set current state on zk to stateModel's current state
        logger.warn("Force CurrentState on Zk to be stateModel's CurrentState. partitionKey: "
            + partitionId + ", currentState: " + _stateModel.getCurrentState() + ", message: "
            + _message);
        _currentStateDelta.setState(partitionId, State.from(_stateModel.getCurrentState()));
      } else {
        StateTransitionError error =
            new StateTransitionError(ErrorType.INTERNAL, ErrorCode.ERROR, exception);
        if (exception instanceof InterruptedException) {
          if (_isTimeout) {
            error = new StateTransitionError(ErrorType.INTERNAL, ErrorCode.TIMEOUT, exception);
          } else {
            // State transition interrupted but not caused by timeout. Keep the current
            // state in this case
            logger
                .error("State transition interrupted but not timeout. Not updating state. Partition : "
                    + _message.getPartitionId() + " MsgId : " + _message.getMessageId());
            return;
          }
        }
        _stateModel.rollbackOnError(_message, _notificationContext, error);
        _currentStateDelta.setState(partitionId, State.from(HelixDefinedState.ERROR.toString()));
        _stateModel.updateState(HelixDefinedState.ERROR.toString());

        // if we have errors transit from ERROR state, disable the partition
        if (_message.getTypedFromState().toString().equalsIgnoreCase(HelixDefinedState.ERROR.toString())) {
          disablePartition();
        }
      }
    }

    try {
      // Update the ZK current state of the node
      PropertyKey key =
          keyBuilder.currentState(instanceName, sessionId.stringify(), resource.stringify(),
              bucketizer.getBucketName(partitionId.stringify()));
      if (_message.getAttribute(Attributes.PARENT_MSG_ID) == null) {
        // normal message
        accessor.updateProperty(key, _currentStateDelta);
      } else {
        // sub-message of a batch message
        ConcurrentHashMap<String, CurrentStateUpdate> csUpdateMap =
            (ConcurrentHashMap<String, CurrentStateUpdate>) _notificationContext
                .get(MapKey.CURRENT_STATE_UPDATE.toString());
        csUpdateMap.put(partitionId.stringify(), new CurrentStateUpdate(key, _currentStateDelta));
      }
    } catch (Exception e) {
      logger.error("Error when updating current-state ", e);
      StateTransitionError error =
          new StateTransitionError(ErrorType.FRAMEWORK, ErrorCode.ERROR, e);
View Full Code Here

TOP

Related Classes of org.apache.helix.api.id.PartitionId

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.