public class

ConstraintBasedAssignment

extends Object
java.lang.Object
   ↳ org.apache.helix.controller.rebalancer.util.ConstraintBasedAssignment

Class Overview

Collection of functions that will compute the best possible state based on the participants and the rebalancer configuration of a resource.

Summary

Public Constructors
ConstraintBasedAssignment()
Public Methods
static Map<ParticipantIdState> computeAutoBestStateForPartition(Map<StateString> upperBounds, Set<ParticipantId> liveParticipantSet, StateModelDefinition stateModelDef, List<ParticipantId> participantPreferenceList, Map<ParticipantIdState> currentStateMap, Set<ParticipantId> disabledParticipantsForPartition)
compute best state for resource in SEMI_AUTO and FULL_AUTO modes
static Map<ParticipantIdState> computeCustomizedBestStateForPartition(Set<ParticipantId> liveParticipantSet, StateModelDefinition stateModelDef, Map<ParticipantIdState> preferenceMap, Map<ParticipantIdState> currentStateMap, Set<ParticipantId> disabledParticipantsForPartition)
compute best state for resource in CUSTOMIZED rebalancer mode
static Map<ParticipantIdState> dropAndDisablePartitions(Map<ParticipantIdState> currentStateMap, Collection<ParticipantId> participants, Set<ParticipantId> disabledParticipants, State initialState)
Get a mapping for a partition for the current state participants who have been dropped or disabled for a given partition.
static Set<ParticipantId> getDisabledParticipants(Map<ParticipantIdParticipant> participantMap, PartitionId partitionId)
Get a set of disabled participants for a partition
static List<ParticipantId> getPreferenceList(Cluster cluster, PartitionId partitionId, List<ParticipantId> prefList)
Get an ordered list of participants that can serve a partition
static Map<StateString> stateConstraints(StateModelDefinition stateModelDef, ResourceId resourceId, ClusterConfig cluster)
Get a map of state to upper bound constraint given a cluster
static LinkedHashMap<StateInteger> stateCount(Map<StateString> upperBounds, StateModelDefinition stateModelDef, int liveNodesNb, int totalReplicas)
Get the number of replicas that should be in each state for a partition
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ConstraintBasedAssignment ()

Public Methods

public static Map<ParticipantIdState> computeAutoBestStateForPartition (Map<StateString> upperBounds, Set<ParticipantId> liveParticipantSet, StateModelDefinition stateModelDef, List<ParticipantId> participantPreferenceList, Map<ParticipantIdState> currentStateMap, Set<ParticipantId> disabledParticipantsForPartition)

compute best state for resource in SEMI_AUTO and FULL_AUTO modes

Parameters
upperBounds map of state to upper bound
liveParticipantSet set of live participant ids
currentStateMap : participant->state for each partition

public static Map<ParticipantIdState> computeCustomizedBestStateForPartition (Set<ParticipantId> liveParticipantSet, StateModelDefinition stateModelDef, Map<ParticipantIdState> preferenceMap, Map<ParticipantIdState> currentStateMap, Set<ParticipantId> disabledParticipantsForPartition)

compute best state for resource in CUSTOMIZED rebalancer mode

public static Map<ParticipantIdState> dropAndDisablePartitions (Map<ParticipantIdState> currentStateMap, Collection<ParticipantId> participants, Set<ParticipantId> disabledParticipants, State initialState)

Get a mapping for a partition for the current state participants who have been dropped or disabled for a given partition.

Parameters
currentStateMap current map of participant id to state for a partition
participants participants selected to serve the partition
disabledParticipants participants that have been disabled for this partition
initialState the initial state of the resource state model
Returns
  • map of participant id to state of dropped and disabled partitions

public static Set<ParticipantId> getDisabledParticipants (Map<ParticipantIdParticipant> participantMap, PartitionId partitionId)

Get a set of disabled participants for a partition

Parameters
participantMap map of all participants
partitionId the partition to check
Returns
  • a set of all participants that are disabled for the partition

public static List<ParticipantId> getPreferenceList (Cluster cluster, PartitionId partitionId, List<ParticipantId> prefList)

Get an ordered list of participants that can serve a partition

Parameters
cluster cluster snapshot
partitionId the partition to look up
Returns
  • list with most preferred participants first

public static Map<StateString> stateConstraints (StateModelDefinition stateModelDef, ResourceId resourceId, ClusterConfig cluster)

Get a map of state to upper bound constraint given a cluster

Parameters
stateModelDef the state model definition to check
resourceId the resource that is constraint
cluster the cluster the resource belongs to
Returns
  • map of state to upper bound

public static LinkedHashMap<StateInteger> stateCount (Map<StateString> upperBounds, StateModelDefinition stateModelDef, int liveNodesNb, int totalReplicas)

Get the number of replicas that should be in each state for a partition

Parameters
upperBounds map of state to upper bound
stateModelDef StateModelDefinition object
liveNodesNb number of live nodes
Returns
  • state count map: state->count