Examples of RebalancerContext


Examples of org.apache.helix.controller.rebalancer.context.RebalancerContext

  protected Map<ResourceId, ResourceConfig> getResourceMap(List<IdealState> idealStates) {
    Map<ResourceId, ResourceConfig> resourceMap = new HashMap<ResourceId, ResourceConfig>();
    for (IdealState idealState : idealStates) {
      ResourceId resourceId = idealState.getResourceId();
      RebalancerContext context = PartitionedRebalancerContext.from(idealState);
      Resource resource =
          new Resource(resourceId, ResourceType.DATA, idealState, null, null, context,
              new UserConfig(Scope.resource(resourceId)), idealState.getBucketSize(),
              idealState.getBatchMessageMode());
      resourceMap.put(resourceId, resource.getConfig());
View Full Code Here

Examples of org.apache.helix.controller.rebalancer.context.RebalancerContext

   */
  static Resource createResource(ResourceId resourceId,
      ResourceConfiguration resourceConfiguration, IdealState idealState,
      ExternalView externalView, ResourceAssignment resourceAssignment) {
    UserConfig userConfig;
    RebalancerContext rebalancerContext = null;
    ResourceType type = ResourceType.DATA;
    if (resourceConfiguration != null) {
      userConfig = resourceConfiguration.getUserConfig();
      type = resourceConfiguration.getType();
    } else {
View Full Code Here

Examples of org.apache.helix.controller.rebalancer.context.RebalancerContext

    if (!isClusterStructureValid()) {
      LOG.error("Cluster: " + _clusterId + " structure is not valid");
      return false;
    }
    RebalancerContext context =
        resource.getRebalancerConfig().getRebalancerContext(RebalancerContext.class);
    StateModelDefId stateModelDefId = context.getStateModelDefId();
    if (_accessor.getProperty(_keyBuilder.stateModelDef(stateModelDefId.stringify())) == null) {
      LOG.error("State model: " + stateModelDefId + " not found in cluster: " + _clusterId);
      return false;
    }
View Full Code Here

Examples of org.apache.helix.controller.rebalancer.context.RebalancerContext

    for (ResourceId resourceId : resourceMap.keySet()) {
      ResourceConfig resourceConfig = resourceMap.get(resourceId);
      int bucketSize = resourceConfig.getBucketSize();

      RebalancerContext rebalancerCtx =
          resourceConfig.getRebalancerConfig().getRebalancerContext(RebalancerContext.class);
      StateModelDefinition stateModelDef = stateModelDefMap.get(rebalancerCtx.getStateModelDefId());

      ResourceAssignment resourceAssignment =
          bestPossibleStateOutput.getResourceAssignment(resourceId);
      for (PartitionId subUnitId : resourceAssignment.getMappedPartitionIds()) {
        Map<ParticipantId, State> instanceStateMap = resourceAssignment.getReplicaMap(subUnitId);

        // we should generate message based on the desired-state priority
        // so keep generated messages in a temp map keyed by state
        // desired-state->list of generated-messages
        Map<State, List<Message>> messageMap = new HashMap<State, List<Message>>();

        for (ParticipantId participantId : instanceStateMap.keySet()) {
          State desiredState = instanceStateMap.get(participantId);

          State currentState =
              currentStateOutput.getCurrentState(resourceId, subUnitId, participantId);
          if (currentState == null) {
            currentState = stateModelDef.getTypedInitialState();
          }

          if (desiredState.equals(currentState)) {
            continue;
          }

          State pendingState =
              currentStateOutput.getPendingState(resourceId, subUnitId, participantId);

          // TODO fix it
          State nextState = stateModelDef.getNextStateForTransition(currentState, desiredState);
          if (nextState == null) {
            LOG.error("Unable to find a next state for partition: " + subUnitId
                + " from stateModelDefinition" + stateModelDef.getClass() + " from:" + currentState
                + " to:" + desiredState);
            continue;
          }

          if (pendingState != null) {
            if (nextState.equals(pendingState)) {
              LOG.debug("Message already exists for " + participantId + " to transit " + subUnitId
                  + " from " + currentState + " to " + nextState);
            } else if (currentState.equals(pendingState)) {
              LOG.info("Message hasn't been removed for " + participantId + " to transit"
                  + subUnitId + " to " + pendingState + ", desiredState: " + desiredState);
            } else {
              LOG.info("IdealState changed before state transition completes for " + subUnitId
                  + " on " + participantId + ", pendingState: " + pendingState + ", currentState: "
                  + currentState + ", nextState: " + nextState);
            }
          } else {
            // TODO check if instance is alive
            SessionId sessionId =
                cluster.getLiveParticipantMap().get(participantId).getRunningInstance()
                    .getSessionId();
            RebalancerContext rebalancerContext =
                resourceConfig.getRebalancerConfig().getRebalancerContext(RebalancerContext.class);
            Message message =
                createMessage(manager, resourceId, subUnitId, participantId, currentState,
                    nextState, sessionId, StateModelDefId.from(stateModelDef.getId()),
                    rebalancerContext.getStateModelFactoryId(), bucketSize);

            // TODO refactor get/set timeout/inner-message
            if (rebalancerContext != null
                && rebalancerContext.getStateModelDefId().equalsIgnoreCase(
                    StateModelDefId.SchedulerTaskQueue)) {
              if (resourceConfig.getSubUnitMap().size() > 0) {
                // TODO refactor it -- we need a way to read in scheduler tasks a priori
                Message innerMsg =
                    resourceConfig.getSchedulerTaskConfig().getInnerMessage(subUnitId);
View Full Code Here

Examples of org.apache.helix.controller.rebalancer.context.RebalancerContext

        // For SCHEDULER_TASK_RESOURCE resource group (helix task queue), we need to find out which
        // task
        // partitions are finished (COMPLETED or ERROR), update the status update of the original
        // scheduler
        // message, and then remove the partitions from the ideal state
        RebalancerContext rebalancerContext =
            (rebalancerConfig != null) ? rebalancerConfig
                .getRebalancerContext(RebalancerContext.class) : null;
        if (rebalancerContext != null
            && rebalancerContext.getStateModelDefId().equalsIgnoreCase(
                StateModelDefId.SchedulerTaskQueue)) {
          updateScheduledTaskStatus(resourceId, view, manager, schedulerTaskConfig);
        }
      }
    }
View Full Code Here

Examples of org.apache.helix.controller.rebalancer.context.RebalancerContext

        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();
    RebalancerContext rebalancerCtx =
        new SemiAutoRebalancerContext.Builder(resourceId).addPartitions(1).replicaCount(1)
            .stateModelDefId(stateModelDefId)
            .preferenceList(PartitionId.from("testDB_0"), Arrays.asList(participantId)).build();
    clusterAccessor.createCluster(new ClusterConfig.Builder(clusterId).addStateModelDefinition(
        stateModelDef).build());
View Full Code Here

Examples of org.apache.helix.controller.rebalancer.context.RebalancerContext

      LOG.error("Cannot reset partitions because the resource is not present");
      return false;
    }

    // need the rebalancer context for the resource
    RebalancerContext context =
        resource.getRebalancerConfig().getRebalancerContext(RebalancerContext.class);
    if (context == null) {
      LOG.error("Rebalancer context for resource does not exist");
      return false;
    }

    // ensure that all partitions to reset exist
    Set<PartitionId> partitionSet = ImmutableSet.copyOf(context.getSubUnitIdSet());
    if (!partitionSet.containsAll(resetPartitionIdSet)) {
      LOG.error("Not all of the specified partitions to reset exist for the resource");
      return false;
    }

    // check for a valid current state that has all specified partitions in ERROR state
    CurrentState currentState = participant.getCurrentStateMap().get(resourceId);
    if (currentState == null) {
      LOG.error("The participant does not have a current state for the resource");
      return false;
    }
    for (PartitionId partitionId : resetPartitionIdSet) {
      if (!currentState.getState(partitionId).equals(State.from(HelixDefinedState.ERROR))) {
        LOG.error("Partition " + partitionId + " is not in error state, aborting reset");
        return false;
      }
    }

    // make sure that there are no pending transition messages
    for (Message message : participant.getMessageMap().values()) {
      if (!MessageType.STATE_TRANSITION.toString().equalsIgnoreCase(message.getMsgType())
          || !runningInstance.getSessionId().equals(message.getTypedTgtSessionId())
          || !resourceId.equals(message.getResourceId())
          || !resetPartitionIdSet.contains(message.getPartitionId())) {
        continue;
      }
      LOG.error("Cannot reset partitions because of the following pending message: " + message);
      return false;
    }

    // set up the source id
    String adminName = null;
    try {
      adminName = InetAddress.getLocalHost().getCanonicalHostName() + "-ADMIN";
    } catch (UnknownHostException e) {
      // can ignore it
      if (LOG.isInfoEnabled()) {
        LOG.info("Unable to get host name. Will set it to UNKNOWN, mostly ignorable", e);
      }
      adminName = "UNKNOWN";
    }

    // build messages to signal the transition
    StateModelDefId stateModelDefId = context.getStateModelDefId();
    StateModelDefinition stateModelDef =
        _accessor.getProperty(_keyBuilder.stateModelDef(stateModelDefId.stringify()));
    Map<MessageId, Message> messageMap = Maps.newHashMap();
    for (PartitionId partitionId : resetPartitionIdSet) {
      // send ERROR to initialState message
      MessageId msgId = MessageId.from(UUID.randomUUID().toString());
      Message message = new Message(MessageType.STATE_TRANSITION, msgId);
      message.setSrcName(adminName);
      message.setTgtName(participantId.stringify());
      message.setMsgState(MessageState.NEW);
      message.setPartitionId(partitionId);
      message.setResourceId(resourceId);
      message.setTgtSessionId(runningInstance.getSessionId());
      message.setStateModelDef(stateModelDefId);
      message.setFromState(State.from(HelixDefinedState.ERROR.toString()));
      message.setToState(stateModelDef.getTypedInitialState());
      message.setStateModelFactoryId(context.getStateModelFactoryId());

      messageMap.put(message.getMessageId(), message);
    }

    // send the messages
View Full Code Here

Examples of org.apache.helix.controller.rebalancer.context.RebalancerContext

    idealState.setRebalanceMode(rebalancerMode);
    idealState.setNumPartitions(partitionNumber);
    idealState.setMaxPartitionsPerInstance(maxPartitionsPerNode);
    idealState.setStateModelDefId(stateModelDefId);

    RebalancerContext rebalancerCtx = PartitionedRebalancerContext.from(idealState);
    ResourceConfig.Builder builder =
        new ResourceConfig.Builder(resourceId).rebalancerContext(rebalancerCtx).bucketSize(
            bucketSize);

    ClusterAccessor accessor = clusterAccessor(clusterName);
View Full Code Here

Examples of org.apache.helix.controller.rebalancer.context.RebalancerContext

      if (LOG.isDebugEnabled()) {
        LOG.debug("Processing resource:" + resourceId);
      }
      ResourceConfig resourceConfig = resourceMap.get(resourceId);
      RebalancerConfig rebalancerConfig = resourceConfig.getRebalancerConfig();
      RebalancerContext context = rebalancerConfig.getRebalancerContext(RebalancerContext.class);
      StateModelDefinition stateModelDef = stateModelDefs.get(context.getStateModelDefId());
      ResourceAssignment resourceAssignment = null;
      if (rebalancerConfig != null) {
        HelixRebalancer rebalancer = rebalancerConfig.getRebalancer();
        HelixManager manager = event.getAttribute("helixmanager");
        if (rebalancer == null) {
View Full Code Here

Examples of org.apache.helix.controller.rebalancer.context.RebalancerContext

    try {
      IdealState idealState =
          new IdealState(
              (ZNRecord) (new ZNRecordSerializer().deserialize(readFile(idealStateJsonFile))));

      RebalancerContext rebalancerCtx = PartitionedRebalancerContext.from(idealState);
      ResourceConfig.Builder builder =
          new ResourceConfig.Builder(ResourceId.from(resourceName))
              .rebalancerContext(rebalancerCtx).bucketSize(idealState.getBucketSize());

      ClusterAccessor accessor = clusterAccessor(clusterName);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.