Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.1.0

E22843-01


com.tangosol.net.partition
Class SimpleAssignmentStrategy

java.lang.Object
  extended by com.tangosol.net.partition.SimpleAssignmentStrategy

All Implemented Interfaces:
PartitionAssignmentStrategy
Direct Known Subclasses:
MirroringAssignmentStrategy

public class SimpleAssignmentStrategy
extends java.lang.Object
implements PartitionAssignmentStrategy

SimpleAssignmentStrategy is a PartitionAssignmentStrategy that attempts to balance the partition distribution based on the number of primary and backup partitions owned. The SimpleAssignmentStrategy will attempt to ensure machine-safety, but only if a balanced "safe" distribution is achievable.

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
protected  class SimpleAssignmentStrategy.AnalysisContext
          AnalysisContext 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 class SimpleAssignmentStrategy.BackupStrength
          BackupStrength represents a level of "strength" or "resiliency" between the primary and backup owners of a partition.
static interface SimpleAssignmentStrategy.LoadCalculator
          LoadCalculator is used to calculate the scalar load (expressed as an integer) of a partition (or set of partitions).
static class SimpleAssignmentStrategy.SimpleLoadCalculator
          SimpleLoadCalculator defines a "count-based" load (e.g. the load of each partition is defined to be 1).

 

Field Summary
protected  SimpleAssignmentStrategy.AnalysisContext m_ctxLast
          The last analysis context.
protected  DistributionManager m_manager
          The DistributionManager.
protected static java.util.Comparator MEMBERID_COMPARATOR
          Comparator used to provide arbitrary (equals-compatible) comparisons between members.

 

Constructor Summary
SimpleAssignmentStrategy()
          Default constructor.

 

Method Summary
 long analyzeDistribution()
          Analyze the distribution and return the desired time interval before the next distribution analysis.
protected  long analyzeDistribution(SimpleAssignmentStrategy.AnalysisContext ctx)
          Analyze the distribution using the specified analysis context.
protected static java.util.Comparator chainComparators(java.util.Comparator comp1, java.util.Comparator comp2, java.util.Comparator comp3)
          Helper method to return a Comparator chaining the specified comparators.
protected  int checkBackupBalance(SimpleAssignmentStrategy.AnalysisContext ctx)
          Check that the distribution of backup partitions is balanced.
protected  int checkBackupStrong(SimpleAssignmentStrategy.AnalysisContext ctx)
          Check that the backups are strong.
protected  void checkEndangered(SimpleAssignmentStrategy.AnalysisContext ctx)
          Check the distribution to ensure that backups are created for any "endangered" partitions.
protected  void checkLeaving(SimpleAssignmentStrategy.AnalysisContext ctx)
          Check for any service members that are leaving, and adjust the distribution plan accordingly.
protected  void checkPrimaryBalance(SimpleAssignmentStrategy.AnalysisContext ctx)
          Check the distribution to ensure that primary the partition load is balanced.
protected static Ownership cloneOwnership(Ownership owners, int iStore)
          Clone the specified ownership for the purpose of enacting a transfer of the specified storage index.
protected  int doBalancePrimary(SimpleAssignmentStrategy.AnalysisContext ctx, Member memberFrom, PartitionSet parts, Member[] aMembersTarget)
          Do balancing transfers for primary distribution.
protected static int filterArray(java.lang.Object[] ao, Filter filter)
          Apply the specified filter to the elements of the specified array.
protected static int filterSort(java.lang.Object[] ao, java.util.Comparator comparator, Filter filter)
          Filter the elements in the specified array and sort any matching elements using the specified comparator.
protected  int getBackupCount()
          Return the configured backup count.
 java.lang.String getDescription()
          Return a human-readable description of the state of the partition assignment.
 SimpleAssignmentStrategy.AnalysisContext getLastAnalysisContext()
          Return the last AnalysisContext.
 DistributionManager getManager()
          Return the DistributionManager.
protected  Member getMember(int nMemberId)
          Return the PartitionedService Member with the specified mini-id.
protected  int getPartitionCount()
          Return the partition count.
 void init(DistributionManager manager)
          Initialize the PartitionAssignmentStrategy and bind it to the specified DistributionManager.
 SimpleAssignmentStrategy.AnalysisContext instantiateAnalysisContext()
          Factory method.
 SimpleAssignmentStrategy.LoadCalculator instantiateLoadCalculator(boolean fPrimary)
          Instantiate the load calculator.
 void setLastAnalysisContext(SimpleAssignmentStrategy.AnalysisContext ctx)
          Set the last AnalysisContext.
 java.lang.String toString()
          
protected  void validateBackups(SimpleAssignmentStrategy.AnalysisContext ctx)
          Check if there are enough ownership members to maintain the configured backup count, reducing the number of backups otherwise.

 

Field Detail

MEMBERID_COMPARATOR

protected static final java.util.Comparator MEMBERID_COMPARATOR
Comparator used to provide arbitrary (equals-compatible) comparisons between members.

m_manager

protected DistributionManager m_manager
The DistributionManager.

m_ctxLast

protected SimpleAssignmentStrategy.AnalysisContext m_ctxLast
The last analysis context.

Constructor Detail

SimpleAssignmentStrategy

public SimpleAssignmentStrategy()
Default constructor.

Method Detail

getManager

public DistributionManager getManager()
Return the DistributionManager.
Returns:
the DistributionManager

getLastAnalysisContext

public SimpleAssignmentStrategy.AnalysisContext getLastAnalysisContext()
Return the last AnalysisContext.
Returns:
the last AnalysisContext

setLastAnalysisContext

public void setLastAnalysisContext(SimpleAssignmentStrategy.AnalysisContext ctx)
Set the last AnalysisContext.
Parameters:
ctx - the AnalysisContext

init

public void init(DistributionManager manager)
Initialize the PartitionAssignmentStrategy and bind it to the specified DistributionManager.
Specified by:
init in interface PartitionAssignmentStrategy
Parameters:
manager - the DistributionManager that this strategy is bound to

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:
analyzeDistribution in interface PartitionAssignmentStrategy
Returns:
the time interval before the next desired analysis, or -1

analyzeDistribution

protected long analyzeDistribution(SimpleAssignmentStrategy.AnalysisContext ctx)
Analyze the distribution using the specified analysis context.
Parameters:
ctx - the analysis context
Returns:
the time interval before the next desired analysis, or -1
See Also:
analyzeDistribution()

getDescription

public java.lang.String getDescription()
Return a human-readable description of the state of the partition assignment.
Specified by:
getDescription in interface PartitionAssignmentStrategy
Returns:
a human-readable description

toString

public java.lang.String toString()

checkLeaving

protected void checkLeaving(SimpleAssignmentStrategy.AnalysisContext ctx)
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

protected void validateBackups(SimpleAssignmentStrategy.AnalysisContext ctx)
Check if there are enough ownership members to maintain the configured backup count, reducing the number of backups otherwise.
Parameters:
ctx - the AnalysisContext

checkPrimaryBalance

protected void checkPrimaryBalance(SimpleAssignmentStrategy.AnalysisContext ctx)
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 context
memberFrom - the member to transfer partitions from
parts - the set of partitions from which to transfer
aMembersTarget - the (unordered) array of members
Returns:
the number of changes (transfers) that were made

checkEndangered

protected void checkEndangered(SimpleAssignmentStrategy.AnalysisContext ctx)
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

protected int checkBackupStrong(SimpleAssignmentStrategy.AnalysisContext ctx)
Check that the backups are strong.
Parameters:
ctx - the analysis context
Returns:
the number of changes (transfers) that were made

checkBackupBalance

protected int checkBackupBalance(SimpleAssignmentStrategy.AnalysisContext ctx)
Check that the distribution of backup partitions is balanced.
Parameters:
ctx - the analysis context
Returns:
the number of changes (transfers) that were made

getPartitionCount

protected int getPartitionCount()
Return the partition count.
Returns:
the partition count

getBackupCount

protected int getBackupCount()
Return the configured backup count.
Returns:
the configured backup count

getMember

protected Member getMember(int nMemberId)
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

cloneOwnership

protected static Ownership cloneOwnership(Ownership owners,
                                          int iStore)
Clone the specified ownership for the purpose of enacting a transfer of the specified storage index. The returned ownership object will contain no owner at the specified storage index.
Parameters:
owners - the ownership to clone
iStore - the storage index
Returns:
the new ownership

chainComparators

protected static java.util.Comparator chainComparators(java.util.Comparator comp1,
                                                       java.util.Comparator comp2,
                                                       java.util.Comparator comp3)
Helper method to return a Comparator chaining the specified comparators.
Parameters:
comp1 - the first comparator
comp2 - the second comparator
comp3 - the third comparator
Returns:
a chained comparator

filterSort

protected static int filterSort(java.lang.Object[] ao,
                                java.util.Comparator comparator,
                                Filter filter)
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 filter
comparator - the comparator to order the elements
filter - the filter to use to filter the results
Returns:
the number of elements matching the specified filter

filterArray

protected static int filterArray(java.lang.Object[] ao,
                                 Filter filter)
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 to
filter - the filter to apply
Returns:
the number of elements matching the specified filter

instantiateLoadCalculator

public SimpleAssignmentStrategy.LoadCalculator instantiateLoadCalculator(boolean fPrimary)
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

public SimpleAssignmentStrategy.AnalysisContext instantiateAnalysisContext()
Factory method.
Returns:
a new AnalysisContext

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.1.0

E22843-01


Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.