Class SimpleAssignmentStrategy
- All Implemented Interfaces:
PartitionAssignmentStrategy,SimpleStrategyMBean
- Direct Known Subclasses:
MirroringAssignmentStrategy
The SimpleAssignmentStrategy is an extensible implementation of the internal distribution algorithm that was available prior to Coherence 3.7.
- Since:
- Coherence 3.7
- Author:
- rhl 2010.11.08
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classAnalysisContext holds the working view of the partition ownership that is used throughout the analysis and is used to reflect changes made during this analysis.protected static classBackupStrength represents a level of "strength" or "resiliency" between the primary and backup owners of a partition.protected classA class that calculate MBean attribute values from last sampled PartitionStatsstatic interfaceLoadCalculator is used to calculate the scalar load (expressed as an integer) of a partition (or set of partitions).static classSimpleLoadCalculator defines a "count-based" load (e.g. the load of each partition is defined to be 1).Nested classes/interfaces inherited from interface com.tangosol.net.partition.SimpleStrategyMBean
SimpleStrategyMBean.HAStatus -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longThe amount of time in ms to delay the analysis after a distribution suggestion has been made and before it is carried out.protected SimpleAssignmentStrategy.AnalysisContextThe last analysis context.protected booleanTrue if JMXPartitionStats should be updated.protected DistributionManagerThe DistributionManager.protected Map<Ownership, PartitionSet> The Map containing the last distribution suggested by this strategy.protected SetThe Set of ownership-enabled members at the time of the last analysis.The JMXPartitionStats that hold the last updated jmx attributes.protected static final ComparatorComparator used to provide arbitrary (equals-compatible) comparisons between members.protected static final StringThe message returned by SimpleStrategyMBean when all suggested distributions have completed and none are in-progress or scheduled.protected static final StringThe message returned by SimpleStrategyMBean when the distribution coordinator has not done its first analysis yet.Fields inherited from interface com.tangosol.net.partition.SimpleStrategyMBean
NOTIFY_LOST -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected longAnalyze the distribution using the specified analysis context.longAnalyze the distribution and return the desired time interval before the next distribution analysis.protected longAnalyze the distribution and suggest the resulting distribution to distribution manager.voidanalyzeOrphans(Map<Member, PartitionSet> mapConstraints) Analyze and suggest the assignment of orphaned partitions (partitions without an active primary or backup owner) subject to the specified constraints.protected static ComparatorchainComparators(Comparator comp1, Comparator comp2) Helper method to return a Comparator chaining the specified comparators.protected static ComparatorchainComparators(Comparator comp1, Comparator comp2, Comparator comp3) Helper method to return a Comparator chaining the specified comparators.protected intCheck that the distribution of backup partitions is balanced.protected intCheck if the distribution of backup partitions is balanced.protected intCheck that the backups are strong.protected voidCheck the distribution to ensure that backups are created for any "endangered" partitions.protected voidCheck for any service members that are leaving, and adjust the distribution plan accordingly.protected voidCheck the distribution to ensure that primary the partition load is balanced.protected booleanAnalyze the distribution for the special two-server case using the specified analysis context.protected Map<Member, PartitionSet[]> Collect the scheduled partition distributions, grouped by the primary owner and storage index.protected intdoBalancePrimary(SimpleAssignmentStrategy.AnalysisContext ctx, Member memberFrom, PartitionSet parts, Member[] aMembersTarget) Do balancing transfers for primary distribution.protected voidemitLossNotification(PartitionSet partsLost) Emit a partition loss notification for given partitions.protected static intfilterArray(Object[] ao, int cElems, Filter filter) Apply the specified filter to the specified array elements.protected static intfilterArray(Object[] ao, Filter filter) Apply the specified filter to the elements of the specified array.protected static intfilterSort(Object[] ao, int cElems, Comparator comparator, Filter filter) Filter the specified array elements and sort any matching elements using the specified comparator.protected static intfilterSort(Object[] ao, Comparator comparator, Filter filter) Filter the elements in the specified array and sort any matching elements using the specified comparator.longGet the average partition storage size.longGet the average node storage size.intGet the configured number of backups.intGet the node id of the ownership distribution coordinator.Return a human-readable description of the state of the partition assignment.intGet the number of backup partitions per storage-enabled service member that this strategy will currently attempt to maintain.intGet the number of primary partitions per storage-enabled service member that this strategy will currently attempt to maintain.The High Availability status for the service.intThe High Availability status for the service as an integer.The High Availability status that this strategy attempts to achieve.Return the last AnalysisContext.Get the last time a partition distribution analysis was performed.Return the set of ownership-enabled members present when the analysis was last considered.Return the DistributionManager.intGet the node id with the maximum storage size.longGet the maximum partition storage size.longGet maximum node storage size.protected MembergetMember(int nMemberId) Return the PartitionedService Member with the specified mini-id.protected longReturn the amount of time in ms to delay the analysis after a member has joined.intGet the configured number of partitions for the service.intGet the number of distributions (partition transfers) that remain to be completed before the service achieves the goals set by this strategy.intGet the number of machines that host storage-enabled nodes running this service.intGet the number of storage-enabled nodes running this service.intGet the number of racks that host storage-enabled nodes running this service.intGet the number of sites that host storage-enabled nodes running this service.Get name of the PartitionAssignmentStrategy in use.protected longReturn the amount of time in ms to delay the analysis after a distribution suggestion has been made and before it is carried out.protected longReturn the amount of time in ms to delay the analysis.protected PartitionSetgetUnownedPartitions(PartitionSet parts, int nMember) Calculate a subset of the PartitionSet consisting of partitions that are not owned (primary or backup) by the specified member.protected intgetVariance(SimpleAssignmentStrategy.AnalysisContext ctx, boolean fPrimary) Return the maximum load variance in the partition assignments represented by the analysis context.voidinit(DistributionManager manager) Initialize the PartitionAssignmentStrategy and bind it to the specified DistributionManager.Factory method.instantiateLoadCalculator(boolean fPrimary) Instantiate the load calculator.protected StringmakeMBeanName(PartitionedService service) Create a name for the MBean representing this strategy.protected voidOptimize the distribution with minimum backup fan-out by distributing the partitions among first two strong members.protected voidRegister an MBean representing this SimpleAssignmentStrategy.reportScheduledDistributions(boolean fVerbose) Report partitions that storage-enabled members are waiting to receive or still need to send in order to achieve distribution goal set by the strategy.protected voidSet the last AnalysisContext.protected voidsetLastOwnershipMembers(Set setOwners) Record the set of ownership-enabled members present when the analysis was last considered.protected SortedMap<Integer, PartitionSet> splitByOwner(PartitionSet parts) Split the partition set scheduled for distribution by the current primary owner (all transfers originate from the primary owner).toString()protected voidUnregister the MBean representing this SimpleAssignmentStrategy.Return a JMXPartitionStats that contains calculated MBean Attributes, updated periodically.protected voidCheck if there are enough ownership members to maintain the configured backup count, reducing the number of backups otherwise.
-
Field Details
-
MEMBERID_COMPARATOR
Comparator used to provide arbitrary (equals-compatible) comparisons between members. -
MSG_NO_RESULT
The message returned by SimpleStrategyMBean when the distribution coordinator has not done its first analysis yet.- See Also:
-
MSG_NO_PENDING
The message returned by SimpleStrategyMBean when all suggested distributions have completed and none are in-progress or scheduled.- See Also:
-
m_manager
The DistributionManager. -
m_ctxLast
The last analysis context. -
m_setOwnersLast
The Set of ownership-enabled members at the time of the last analysis. -
m_mapSuggestLast
The Map containing the last distribution suggested by this strategy. -
m_statsPartition
The JMXPartitionStats that hold the last updated jmx attributes. -
m_fRefresh
protected boolean m_fRefreshTrue if JMXPartitionStats should be updated. -
m_cPlanCompletionDelay
protected long m_cPlanCompletionDelayThe amount of time in ms to delay the analysis after a distribution suggestion has been made and before it is carried out.
-
-
Constructor Details
-
SimpleAssignmentStrategy
public SimpleAssignmentStrategy()Default constructor.
-
-
Method Details
-
getManager
Return the DistributionManager.- Returns:
- the DistributionManager
-
getLastAnalysisContext
Return the last AnalysisContext.- Returns:
- the last AnalysisContext
-
setLastAnalysisContext
Set the last AnalysisContext.- Parameters:
ctx- the AnalysisContext
-
getLastOwnershipMembers
Return the set of ownership-enabled members present when the analysis was last considered.- Returns:
- the set of ownership-enabled members when analysis was last considered
-
setLastOwnershipMembers
Record the set of ownership-enabled members present when the analysis was last considered.- Parameters:
setOwners- the set of ownership-enabled members
-
getMemberJoinDelay
protected long getMemberJoinDelay()Return the amount of time in ms to delay the analysis after a member has joined. This delay could be used to "dampen" the reactivity of the strategy to membership changes.- Returns:
- the amount of time in ms to delay the analysis after a member joins
-
getSuggestionDelay
protected long getSuggestionDelay()Return the amount of time in ms to delay the analysis.- Returns:
- the amount of time in ms to delay the analysis
-
getSuggestionCompletionDelay
protected long getSuggestionCompletionDelay()Return the amount of time in ms to delay the analysis after a distribution suggestion has been made and before it is carried out. This delay could be used to "dampen" the volatility of the strategy by allowing sufficient time for in-flight transfers to complete prior to considering further recommendations.- Returns:
- the amount of time in ms to delay the analysis after a suggestion is made
-
init
Initialize the PartitionAssignmentStrategy and bind it to the specified DistributionManager. This method is called only on the distribution coordinator, prior its first distributionanalysis.- Specified by:
initin interfacePartitionAssignmentStrategy- Parameters:
manager- the DistributionManager that this strategy is bound to
-
analyzeOrphans
Analyze and suggest the assignment of orphaned partitions (partitions without an active primary or backup owner) subject to the specified constraints. For each partition, the supplied constraints specify the set of members which are eligible to be assigned the ownership.The strategy must provide suggestions for all orphaned partitions which are consistent with the supplied constraints. Failure to provide a complete set of valid suggestions may result in the loss of partition data.
- Specified by:
analyzeOrphansin interfacePartitionAssignmentStrategy- Parameters:
mapConstraints- the map of assignment constraints associating members with the set of partitions that they could be assigned ownership of
-
analyzeDistribution
public long analyzeDistribution()Analyze the distribution and return the desired time interval before the next distribution analysis. This method may or may not make distribution suggestions through the distribution manager. The strategy can influence (but not guarantee) the frequency with which it is analyzed by returning the desired interval before the next call, or -1 if the strategy has no preference and will rely on the PartitionedService to decide.As a result of failover, partitions may become 'endangered', meaning that the necessary number of backups do not exist. Failure to suggest a distribution recovery plan for those partitions may result in the partition remaining in the endangered state. Additionally, ownership-enabled service members that are in the process of shutting down will wait until all owned partitions are transferred out. Failure to suggest a distribution plan may delay the exit of these leaving members.
The statistics and ownership information exposed by the DistributionManager will not mutate for the duration of this method call.
- Specified by:
analyzeDistributionin interfacePartitionAssignmentStrategy- Returns:
- the time interval before the next desired analysis, or -1
-
analyzeDistribution
Analyze the distribution and suggest the resulting distribution to distribution manager.- Parameters:
ctx- the analysis context- Returns:
- the time interval before the next desired analysis, or -1
-
primeDistribution
Optimize the distribution with minimum backup fan-out by distributing the partitions among first two strong members.- Parameters:
ctx- the analysis context
-
analyze
Analyze the distribution using the specified analysis context.- Parameters:
ctx- the analysis context- Returns:
- the time interval before the next desired analysis, or -1
-
checkSimpleDistribution
Analyze the distribution for the special two-server case using the specified analysis context.- Parameters:
ctx- the analysis context- Returns:
- true if the simple distribution is in effect
-
getDescription
Return a human-readable description of the state of the partition assignment.- Specified by:
getDescriptionin interfacePartitionAssignmentStrategy- Returns:
- a human-readable description
-
toString
-
checkLeaving
Check for any service members that are leaving, and adjust the distribution plan accordingly.Partitions owned by leaving members must be transferred to other members before the departing members are able to shutdown.
- Parameters:
ctx- the AnalysisContext
-
validateBackups
Check if there are enough ownership members to maintain the configured backup count, reducing the number of backups otherwise.- Parameters:
ctx- the AnalysisContext
-
checkPrimaryBalance
Check the distribution to ensure that primary the partition load is balanced.- Parameters:
ctx- the analysis context
-
doBalancePrimary
protected int doBalancePrimary(SimpleAssignmentStrategy.AnalysisContext ctx, Member memberFrom, PartitionSet parts, Member[] aMembersTarget) Do balancing transfers for primary distribution.- Parameters:
ctx- the analysis contextmemberFrom- the member to transfer partitions fromparts- the set of partitions from which to transferaMembersTarget- the (unordered) array of members- Returns:
- the number of changes (transfers) that were made
-
checkEndangered
Check the distribution to ensure that backups are created for any "endangered" partitions.A partition is "endangered" if it is incompletely backed up (e.g. some backup copies do not exist).
- Parameters:
ctx- the analysis context
-
checkBackupStrong
Check that the backups are strong.- Parameters:
ctx- the analysis context- Returns:
- the number of changes (transfers) that were made
-
checkBackupBalance
Check that the distribution of backup partitions is balanced.- Parameters:
ctx- the analysis context- Returns:
- the number of changes (transfers) that were made
-
checkBackupOverloaded
Check if the distribution of backup partitions is balanced. If not, disturb the distribution by moving a partition from the overloaded member to another member that retains partition strength.- Parameters:
ctx- the analysis context- Returns:
- the number of unbalanced partitions that need to be transferred
-
getMember
Return the PartitionedService Member with the specified mini-id.- Parameters:
nMemberId- the mini-id- Returns:
- the PartitionedService Member with the specified mini-id, or null
-
getVariance
Return the maximum load variance in the partition assignments represented by the analysis context. The maximum variance is the difference in load between the 'lightest' and 'heaviest' members.- Parameters:
ctx- the analysis contextfPrimary- true iff the "primary" load variance should be computed- Returns:
- the maximum variance
-
chainComparators
Helper method to return a Comparator chaining the specified comparators.- Parameters:
comp1- the first comparatorcomp2- the second comparator- Returns:
- a chained comparator
-
chainComparators
Helper method to return a Comparator chaining the specified comparators.- Parameters:
comp1- the first comparatorcomp2- the second comparatorcomp3- the third comparator- Returns:
- a chained comparator
-
filterSort
Filter the elements in the specified array and sort any matching elements using the specified comparator. All matching results will be compacted to the front of the array. The order of results not matching the filter is undefined.- Parameters:
ao- the object array to sort and filtercomparator- the comparator to order the elementsfilter- the filter to use to filter the results- Returns:
- the number of elements matching the specified filter
-
filterSort
Filter the specified array elements and sort any matching elements using the specified comparator. All matching results will be compacted to the front of the array. The order of results not matching the filter is undefined.- Parameters:
ao- the object array to sort and filtercElems- the number of elements to filter and sortcomparator- the comparator to order the elementsfilter- the filter to use to filter the results- Returns:
- the number of elements matching the specified filter
-
filterArray
Apply the specified filter to the elements of the specified array. All matching results will be compacted to the front of the array in a "stable" manner. The order of results not matching the filter may not be preserved.- Parameters:
ao- the object array to apply the filter tofilter- the filter to apply- Returns:
- the number of elements matching the specified filter
-
filterArray
Apply the specified filter to the specified array elements. All matching results will be compacted to the front of the array in a "stable" manner. The order of results not matching the filter may not be preserved.- Parameters:
ao- the object array to apply the filter tocElems- the number of elements to filterfilter- the filter to apply- Returns:
- the number of elements matching the specified filter
-
getPartitionCount
public int getPartitionCount()Get the configured number of partitions for the service.- Specified by:
getPartitionCountin interfaceSimpleStrategyMBean- Returns:
- the partition count
-
getBackupCount
public int getBackupCount()Get the configured number of backups.- Specified by:
getBackupCountin interfaceSimpleStrategyMBean- Returns:
- the backup count
-
getServiceNodeCount
public int getServiceNodeCount()Get the number of storage-enabled nodes running this service.- Specified by:
getServiceNodeCountin interfaceSimpleStrategyMBean- Returns:
- the number of storage-enabled nodes
-
getServiceMachineCount
public int getServiceMachineCount()Get the number of machines that host storage-enabled nodes running this service.- Specified by:
getServiceMachineCountin interfaceSimpleStrategyMBean- Returns:
- the number of machines with storage-enabled nodes
-
getServiceRackCount
public int getServiceRackCount()Get the number of racks that host storage-enabled nodes running this service.- Specified by:
getServiceRackCountin interfaceSimpleStrategyMBean- Returns:
- the number of racks with storage-enabled nodes
-
getServiceSiteCount
public int getServiceSiteCount()Get the number of sites that host storage-enabled nodes running this service.- Specified by:
getServiceSiteCountin interfaceSimpleStrategyMBean- Returns:
- the number of sites with storage-enabled nodes
-
getHAStatus
The High Availability status for the service.- Specified by:
getHAStatusin interfaceSimpleStrategyMBean- Returns:
- one of the following values: ENDANGERED, NODE-SAFE, MACHINE-SAFE, RACK-SAFE, SITE-SAFE
-
getHAStatusCode
public int getHAStatusCode()The High Availability status for the service as an integer.Below is an example of how to map a HA Status integer to a string:
HAStatus.values()[getHAStatusCode()].name()
- Specified by:
getHAStatusCodein interfaceSimpleStrategyMBean- Returns:
- integer representation of
SimpleStrategyMBean.HAStatus
-
getHATarget
The High Availability status that this strategy attempts to achieve. Values are the same as for HAStatus attribute.- Specified by:
getHATargetin interfaceSimpleStrategyMBean- Returns:
- the target High Availability status
-
getStrategyName
Get name of the PartitionAssignmentStrategy in use.- Specified by:
getStrategyNamein interfaceSimpleStrategyMBean- Returns:
- partitioning strategy name
-
getLastAnalysisTime
Get the last time a partition distribution analysis was performed.- Specified by:
getLastAnalysisTimein interfaceSimpleStrategyMBean- Returns:
- the time of the last analysis
-
getCoordinatorId
public int getCoordinatorId()Get the node id of the ownership distribution coordinator.- Specified by:
getCoordinatorIdin interfaceSimpleStrategyMBean- Returns:
- current distribution coordinator node id
-
getRemainingDistributionCount
public int getRemainingDistributionCount()Get the number of distributions (partition transfers) that remain to be completed before the service achieves the goals set by this strategy.- Specified by:
getRemainingDistributionCountin interfaceSimpleStrategyMBean- Returns:
- the number of remaining partition transfers
-
getAveragePartitionSizeKB
public long getAveragePartitionSizeKB()Get the average partition storage size.- Specified by:
getAveragePartitionSizeKBin interfaceSimpleStrategyMBean- Returns:
- the average partition storage size in kilobytes
-
getMaxPartitionSizeKB
public long getMaxPartitionSizeKB()Get the maximum partition storage size.- Specified by:
getMaxPartitionSizeKBin interfaceSimpleStrategyMBean- Returns:
- the maximum partition storage size in kilobytes
-
getMaxStorageSizeKB
public long getMaxStorageSizeKB()Get maximum node storage size.- Specified by:
getMaxStorageSizeKBin interfaceSimpleStrategyMBean- Returns:
- the maximum node storage size in kilobytes
-
getAverageStorageSizeKB
public long getAverageStorageSizeKB()Get the average node storage size.- Specified by:
getAverageStorageSizeKBin interfaceSimpleStrategyMBean- Returns:
- the average node storage size in kilobytes
-
getMaxLoadNodeId
public int getMaxLoadNodeId()Get the node id with the maximum storage size.- Specified by:
getMaxLoadNodeIdin interfaceSimpleStrategyMBean- Returns:
- the node id with the maximum storage size
-
updateCompositeStats
Return a JMXPartitionStats that contains calculated MBean Attributes, updated periodically.- Returns:
- JMXPartitionStats with calculated MBean Attributes
-
reportScheduledDistributions
Report partitions that storage-enabled members are waiting to receive or still need to send in order to achieve distribution goal set by the strategy.- Specified by:
reportScheduledDistributionsin interfaceSimpleStrategyMBean- Parameters:
fVerbose- if true, the report includes partition numbers for each scheduled transfer- Returns:
- a description of scheduled distributions for the service
-
registerMBean
protected void registerMBean()Register an MBean representing this SimpleAssignmentStrategy.This implementation creates and registers a
SimpleStrategyMBean. -
makeMBeanName
Create a name for the MBean representing this strategy.The name must be globally unique, but not contain the nodeId property. This allows us to re-bind the same JMX name to the MBean on a different node when the distribution coordinator migrates.
- Parameters:
service- partitioned service that uses this strategy- Returns:
- the name for the MBean
-
unregisterMBean
protected void unregisterMBean()Unregister the MBean representing this SimpleAssignmentStrategy. -
emitLossNotification
Emit a partition loss notification for given partitions.- Parameters:
partsLost- the partition id that has been lost
-
collectScheduledDistributions
Collect the scheduled partition distributions, grouped by the primary owner and storage index. A partition distribution (either primary or backup) is considered to be scheduled if the distribution has been suggested but the ownership change has not yet occurred.- Returns:
- a Map of partition sets still awaiting distribution keyed by primary owner
-
getUnownedPartitions
Calculate a subset of the PartitionSet consisting of partitions that are not owned (primary or backup) by the specified member.- Parameters:
parts- set of partitions to check the ownership ofnMember- the member-id- Returns:
- the subset of partitions that are not owned by the specified member
-
splitByOwner
Split the partition set scheduled for distribution by the current primary owner (all transfers originate from the primary owner).- Parameters:
parts- a set of partitions not yet transferred- Returns:
- the partitions scheduled for distribution, associated with their primary owners
-
instantiateLoadCalculator
Instantiate the load calculator.- Parameters:
fPrimary- true iff the load calculator will be used for primary partition load; backup otherwise- Returns:
- a load calculator
-
instantiateAnalysisContext
Factory method.- Returns:
- a new AnalysisContext
-