Examples of PartitionedRebalancerContext


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

      batchMessageMode = resourceConfiguration.getBatchMessageMode();
      RebalancerConfig rebalancerConfig = new RebalancerConfig(resourceConfiguration);
      rebalancerContext = rebalancerConfig.getRebalancerContext(RebalancerContext.class);
    }
    if (rebalancerContext == null) {
      rebalancerContext = new PartitionedRebalancerContext();
    }
    return new Resource(resourceId, type, idealState, resourceAssignment, externalView,
        rebalancerContext, userConfig, bucketSize, batchMessageMode);
  }
View Full Code Here

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

      LOG.info("HelixManager is null!");
      return null;
    }

    // get the context
    PartitionedRebalancerContext context =
        rebalancerConfig.getRebalancerContext(PartitionedRebalancerContext.class);
    if (context == null) {
      LOG.info("Resource is not partitioned");
      return null;
    }

    // get the ideal state and rebalancer class
    ResourceId resourceId = context.getResourceId();
    StateModelDefinition stateModelDef =
        cluster.getStateModelMap().get(context.getStateModelDefId());
    if (stateModelDef == null) {
      LOG.info("StateModelDefinition unavailable for " + resourceId);
      return null;
    }
    HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
View Full Code Here

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

   */
  @Override
  public ResourceAssignment computeResourceMapping(RebalancerConfig rebalancerConfig,
      Cluster cluster, ResourceCurrentState currentState) {
    // get a typed context
    PartitionedRebalancerContext context =
        rebalancerConfig.getRebalancerContext(PartitionedRebalancerContext.class);

    // Initialize an empty mapping of locks to participants
    ResourceAssignment assignment = new ResourceAssignment(context.getResourceId());

    // Get the list of live participants in the cluster
    List<ParticipantId> liveParticipants =
        new ArrayList<ParticipantId>(cluster.getLiveParticipantMap().keySet());

    // Get the state model (should be a simple lock/unlock model) and the highest-priority state
    StateModelDefId stateModelDefId = context.getStateModelDefId();
    StateModelDefinition stateModelDef = cluster.getStateModelMap().get(stateModelDefId);
    if (stateModelDef.getStatesPriorityList().size() < 1) {
      LOG.error("Invalid state model definition. There should be at least one state.");
      return assignment;
    }
    State lockState = stateModelDef.getTypedStatesPriorityList().get(0);

    // Count the number of participants allowed to lock each lock
    String stateCount = stateModelDef.getNumParticipantsPerState(lockState);
    int lockHolders = 0;
    try {
      // a numeric value is a custom-specified number of participants allowed to lock the lock
      lockHolders = Integer.parseInt(stateCount);
    } catch (NumberFormatException e) {
      LOG.error("Invalid state model definition. The lock state does not have a valid count");
      return assignment;
    }

    // Fairly assign the lock state to the participants using a simple mod-based sequential
    // assignment. For instance, if each lock can be held by 3 participants, lock 0 would be held
    // by participants (0, 1, 2), lock 1 would be held by (1, 2, 3), and so on, wrapping around the
    // number of participants as necessary.
    // This assumes a simple lock-unlock model where the only state of interest is which nodes have
    // acquired each lock.
    int i = 0;
    for (PartitionId partition : context.getPartitionSet()) {
      Map<ParticipantId, State> replicaMap = new HashMap<ParticipantId, State>();
      for (int j = i; j < i + lockHolders; j++) {
        int participantIndex = j % liveParticipants.size();
        ParticipantId participant = liveParticipants.get(participantIndex);
        // enforce that a participant can only have one instance of a given lock
View Full Code Here

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

     * which is in the highest-priority state.
     */
    @Override
    public ResourceAssignment computeResourceMapping(RebalancerConfig config, Cluster cluster,
        ResourceCurrentState currentState) {
      PartitionedRebalancerContext context =
          config.getRebalancerContext(PartitionedRebalancerContext.class);
      StateModelDefinition stateModelDef =
          cluster.getStateModelMap().get(context.getStateModelDefId());
      List<ParticipantId> liveParticipants =
          new ArrayList<ParticipantId>(cluster.getLiveParticipantMap().keySet());
      ResourceAssignment resourceMapping = new ResourceAssignment(context.getResourceId());
      int i = 0;
      for (PartitionId partitionId : context.getPartitionSet()) {
        int nodeIndex = i % liveParticipants.size();
        Map<ParticipantId, State> replicaMap = new HashMap<ParticipantId, State>();
        replicaMap.put(liveParticipants.get(nodeIndex), stateModelDef.getTypedStatesPriorityList()
            .get(0));
        resourceMapping.addReplicaMap(partitionId, replicaMap);
View Full Code Here

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

    ResourceAccessor resourceAccessor = resourceAccessor();
    Map<String, IdealState> idealStateMap = _accessor.getChildValuesMap(_keyBuilder.idealStates());
    for (String resourceName : idealStateMap.keySet()) {
      IdealState idealState = idealStateMap.get(resourceName);
      swapParticipantsInIdealState(idealState, oldParticipantId, newParticipantId);
      PartitionedRebalancerContext context = PartitionedRebalancerContext.from(idealState);
      resourceAccessor.setRebalancerContext(ResourceId.from(resourceName), context);
      _accessor.setProperty(_keyBuilder.idealStates(resourceName), idealState);
    }
    return true;
  }
View Full Code Here

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

   */
  public boolean generateDefaultAssignment(ResourceId resourceId, int replicaCount,
      String participantGroupTag) {
    Resource resource = readResource(resourceId);
    RebalancerConfig config = resource.getRebalancerConfig();
    PartitionedRebalancerContext context =
        config.getRebalancerContext(PartitionedRebalancerContext.class);
    if (context == null) {
      LOG.error("Only partitioned resource types are supported");
      return false;
    }
    if (replicaCount != -1) {
      context.setReplicaCount(replicaCount);
    }
    if (participantGroupTag != null) {
      context.setParticipantGroupTag(participantGroupTag);
    }
    StateModelDefinition stateModelDef =
        _accessor.getProperty(_keyBuilder.stateModelDef(context.getStateModelDefId().stringify()));
    List<InstanceConfig> participantConfigs =
        _accessor.getChildValues(_keyBuilder.instanceConfigs());
    Set<ParticipantId> participantSet = Sets.newHashSet();
    for (InstanceConfig participantConfig : participantConfigs) {
      participantSet.add(participantConfig.getParticipantId());
    }
    context.generateDefaultConfiguration(stateModelDef, participantSet);
    setRebalancerContext(resourceId, context);
    return true;
  }
View Full Code Here

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

   * @param batchMessageMode true if batch messaging allowed, false otherwise
   * @return IdealState, or null
   */
  static IdealState rebalancerConfigToIdealState(RebalancerConfig config, int bucketSize,
      boolean batchMessageMode) {
    PartitionedRebalancerContext partitionedContext =
        config.getRebalancerContext(PartitionedRebalancerContext.class);
    if (partitionedContext != null) {
      IdealState idealState = new IdealState(partitionedContext.getResourceId());
      idealState.setRebalanceMode(partitionedContext.getRebalanceMode());
      idealState.setRebalancerRef(partitionedContext.getRebalancerRef());
      String replicas = null;
      if (partitionedContext.anyLiveParticipant()) {
        replicas = StateModelToken.ANY_LIVEINSTANCE.toString();
      } else {
        replicas = Integer.toString(partitionedContext.getReplicaCount());
      }
      idealState.setReplicas(replicas);
      idealState.setNumPartitions(partitionedContext.getPartitionSet().size());
      idealState.setInstanceGroupTag(partitionedContext.getParticipantGroupTag());
      idealState.setMaxPartitionsPerInstance(partitionedContext.getMaxPartitionsPerParticipant());
      idealState.setStateModelDefId(partitionedContext.getStateModelDefId());
      idealState.setStateModelFactoryId(partitionedContext.getStateModelFactoryId());
      idealState.setBucketSize(bucketSize);
      idealState.setBatchMessageMode(batchMessageMode);
      if (partitionedContext.getRebalanceMode() == RebalanceMode.SEMI_AUTO) {
        SemiAutoRebalancerContext semiAutoContext =
            config.getRebalancerContext(SemiAutoRebalancerContext.class);
        for (PartitionId partitionId : semiAutoContext.getPartitionSet()) {
          idealState.setPreferenceList(partitionId, semiAutoContext.getPreferenceList(partitionId));
        }
      } else if (partitionedContext.getRebalanceMode() == RebalanceMode.CUSTOMIZED) {
        CustomRebalancerContext customContext =
            config.getRebalancerContext(CustomRebalancerContext.class);
        for (PartitionId partitionId : customContext.getPartitionSet()) {
          idealState.setParticipantStateMap(partitionId,
              customContext.getPreferenceMap(partitionId));
        }
      } else {
        for (PartitionId partitionId : partitionedContext.getPartitionSet()) {
          List<ParticipantId> preferenceList = Collections.emptyList();
          idealState.setPreferenceList(partitionId, preferenceList);
          Map<ParticipantId, State> participantStateMap = Collections.emptyMap();
          idealState.setParticipantStateMap(partitionId, participantStateMap);
        }
View Full Code Here

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

    Resource resource = accessor.readResource(resourceId);

    StringBuilder sb = new StringBuilder();
    Map<ParticipantId, State> stateMap = resource.getExternalView().getStateMap(partitionId);
    sb.append(resourceName + "/" + partitionName + ", externalView: " + stateMap);
    PartitionedRebalancerContext partitionedContext =
        resource.getRebalancerConfig().getRebalancerContext(PartitionedRebalancerContext.class);
    if (partitionedContext != null) {
      // for partitioned contexts, check the mode and apply mode-specific information if possible
      if (partitionedContext.getRebalanceMode() == RebalanceMode.SEMI_AUTO) {
        SemiAutoRebalancerContext semiAutoContext =
            resource.getRebalancerConfig().getRebalancerContext(SemiAutoRebalancerContext.class);
        sb.append(", preferenceList: " + semiAutoContext.getPreferenceList(partitionId));
      } else if (partitionedContext.getRebalanceMode() == RebalanceMode.CUSTOMIZED) {
        CustomRebalancerContext customContext =
            resource.getRebalancerConfig().getRebalancerContext(CustomRebalancerContext.class);
        sb.append(", preferenceMap: " + customContext.getPreferenceMap(partitionId));
      }
      if (partitionedContext.anyLiveParticipant()) {
        sb.append(", anyLiveParticipant: " + partitionedContext.anyLiveParticipant());
      } else {
        sb.append(", replicaCount: " + partitionedContext.getReplicaCount());
      }
    }

    System.out.println(sb.toString());
  }
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.