Package com.tangosol.net.partition
Class SimpleAssignmentStrategy.AnalysisContext
java.lang.Object
com.tangosol.net.partition.SimpleAssignmentStrategy.AnalysisContext
- Enclosing class:
SimpleAssignmentStrategy
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
LoadComparator is a Comparator that can be used to compare two Member objects based on their partition load (as defined by the LoadCalculator).class
NotOwnedFilter is a Filter implementation used to evaluate Member objects, and selects members who are not represented in the reference ownership object.class
SafetyFilter is a Filter implementation used to evaluate Member objects, and selects members that are "strong" with respect to the reference ownership, as defined by the backup-strength.class
StrengthComparator is an Comparator that can be used to compare two Member objects based on their "distance" from a given set of members (as represented by an Ownership object).class
UnderloadedFilter is a Filter implementation that is used to evaluate Member objects, and selects those whose partition load is "underloaded" in comparison to the fair-share load. -
Field Summary
Modifier and TypeFieldDescriptionprotected Ownership[]
The ownership array for this analysis context.protected Member[]
An array of the ownership members to include in the distribution, arranged in arbitrary order.protected SimpleAssignmentStrategy.LoadCalculator
The backup LoadCalculator.protected SimpleAssignmentStrategy.LoadCalculator
The primary LoadCalculator.protected int
The number of backup storages to maintain.protected long
An explicit delay to be used in favor of a determined delay incalculateAnalysisDelay()
.protected int
The fair-share backup partition load.protected int
The fair-share primary partition load.protected long
The timestamp of when the analysis represented by this context was completed, or 0 if it is not yet complete.protected Map
<Member, PartitionSet[]> The map of member ownership information for this analysis context.protected PartitionSet
The set of partitions that were determined to be orphaned in the call toPartitionAssignmentStrategy.analyzeOrphans(Map)
.protected PartitionSet
The set of partitions that have been updated in this analysis context; may be null.protected Set
The set of ownership members that are leaving.protected Set
The set of ownership members to include in the distribution.protected SimpleAssignmentStrategy.BackupStrength
The backup strength for the resiliency of the resulting distribution. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected long
Calculate whether the analysis should be delayed.protected int
calculateFairShare
(boolean fPrimary) Return the "fair share" (F) load.protected PartitionSet
collectEndangered
(PartitionSet parts) Return a partition set representing the subset of the specified partitions that are "endangered".protected PartitionSet
collectOrphaned
(PartitionSet parts) Return a partition set representing the subset of the specified partitions that are "orphaned".protected PartitionSet
collectWeak
(PartitionSet parts) Return a partition set representing the subset of the specified partitions that are "weak" or "vulnerable" (as defined by the backup strength).protected void
Copy transient values from another, generally the previous, AnalysisContext to this AnalysisContext.protected PartitionSet
Ensure and return the set of updated partitions.protected int
Return the number of backups to maintain, given the actual set of ownership-enabled and leaving members.protected long
Return the number of milliseconds the analysis should be delayed;0L
suggests immediate analysis.Return the LoadCalculator used to calculate the backup partition load.protected SimpleAssignmentStrategy.BackupStrength
Return the BackupStrength for this analysis context.long
Return the time at which the analysis associated with this context was completed, or 0 if it has not been completed.protected int
getFairShare
(boolean fPrimary) Return the (primary or backup) fair-share partition load.Return the set of ownership members that are leaving.protected int
getMemberLoad
(Member member, boolean fPrimary) Return the (primary or backup) partition load of the specified member.protected PartitionSet
Return the partitions deemed orphaned as a result of a previous execution ofanalyzeOrphans
.getOwnedPartitions
(Member member, int iStore) Return the set of partitions for which the specified member owns (or has been assigned by this analysis to own) the specified storage index.Return the set of members across which to distribute the partition ownership.protected Member[]
Return an array containing the members across which to distribute the partition ownership, arranged in arbitrary order.protected int
getPartitionLoad
(int iPartition, boolean fPrimary) Return the load (as defined by the appropriate load calculator) for the specified partition.getPartitionOwnership
(int iPartition) Return the Ownership information (or the ownership assigned by this analysis) for the specified partition.Return the LoadCalculator used to calculate the primary partition load.protected PartitionSet
Return the set of updated partitions; may be null.protected void
Initialize the AnalysisContext.protected SimpleAssignmentStrategy.BackupStrength
instantiateBackupStrength
(Set setOwners) Create a backup strength to be used for distribution among the specified set of ownership members.Instantiate a default member Comparator.instantiateLoadComparator
(boolean fPrimary) Return a comparator for primary or backup partition load.instantiateNotOwnedFilter
(Ownership owners) Instantiate and return a NotOwnedFilter with the specified ownership.instantiateOverloadedFilter
(boolean fPrimary) Instantiate a filter that matches members with an over-load.instantiateSafetyFilter
(Ownership owners, int iStore) Instantiate and return a SafetyFilter with the specified ownership.Instantiate a StrengthComparator for the specified reference ownership.instantiateUnderloadedFilter
(boolean fPrimary) Instantiate a filter that matches members with an under-load.boolean
isInitialDistribution
(Member memberCoordinator) Check if the distribution is in the initial state, when the coordinator owns all the partitions and there are no backups.protected boolean
isMemberLeaving
(Member member) Return true iff the specified member is in the process of leaving.protected boolean
isPartitionEndangered
(int iPartition) Return true iff the specified partition is "endangered".protected boolean
isPartitionEndangered
(Ownership owners) Return true iff the specified ownership is "endangered".protected boolean
isPartitionStrong
(int iPartition) Return true iff the ownership of the specified partition is "strong", as defined by the current BackupStrength.protected boolean
isPartitionStrong
(Ownership owners) Return true iff the specified ownership is "strong", as defined by the current BackupStrength.protected boolean
Return true iff the specified members are mutually "strong", as defined by the backup strength.protected boolean
Return true iff the specified member is "strong" with respect to the specified ownership, as defined by the backup strength.protected boolean
isStrongPossible
(Set setOwners, Map mapSplit) Return true iff a "strong" balanced distribution is achievable for the specified set of members, split among a set of categories (e.g. machine, rack, site).protected boolean
isTransferStrong
(int iPartition, int iStore, Member member) Return true iff the specified partition transfer would result in a "strong" ownership, as defined by the current BackupStrength.protected void
primeDistribution
(Member member1, Member member2) Set the context to pretend to be the "two servers" membership.protected void
Reset those attributes that should be transient betweenSimpleAssignmentStrategy.analyzeDistribution()
requests.protected void
setAnalysisDelay
(long cDelay) Set the number of milliseconds the analysis should be delayed;0L
suggests immediate analysis.protected void
Set the BackupStrength for this analysis context.protected void
setCompletedTime
(long ldt) Set the timestamp at which the analysis associated with this context completed.protected void
Set the orphaned partitions that can be prioritized for transfer in order to reduce the transfer cost.protected boolean
Suggest any distribution that may have been collected by this analysis context to the DistributionManager.protected void
transitionPartition
(int iPartition, int iStore, Member memberFrom, Member memberTo) Update the analysis context to reflect the suggested transfer of the specified number of primary partitions between the specified members.
-
Field Details
-
m_calculatorPrimary
The primary LoadCalculator. -
m_calculatorBackup
The backup LoadCalculator. -
m_mapOwnedPartitions
The map of member ownership information for this analysis context. -
m_aOwners
The ownership array for this analysis context. -
m_partsUpdated
The set of partitions that have been updated in this analysis context; may be null. -
m_partsOrphaned
The set of partitions that were determined to be orphaned in the call toPartitionAssignmentStrategy.analyzeOrphans(Map)
. -
m_strength
The backup strength for the resiliency of the resulting distribution. -
m_cBackupActual
protected int m_cBackupActualThe number of backup storages to maintain.Note: this may differ from the configured backup count if there is an inadequate number of ownership members to sustain the configured backup count.
-
m_setOwnershipMembers
The set of ownership members to include in the distribution.Note: this set does not include members that are leaving
-
m_setOwenersLeaving
The set of ownership members that are leaving. -
m_aOwnershipMembers
An array of the ownership members to include in the distribution, arranged in arbitrary order. This array could be used for algorithms performing in-place sorting of the members.Note: this list does not include members that are leaving
-
m_ldtCompleted
protected long m_ldtCompletedThe timestamp of when the analysis represented by this context was completed, or 0 if it is not yet complete. -
m_cDelay
protected long m_cDelayAn explicit delay to be used in favor of a determined delay incalculateAnalysisDelay()
.
-
-
Constructor Details
-
AnalysisContext
public AnalysisContext()Default constructor.
-
-
Method Details
-
getUpdatedPartitions
Return the set of updated partitions; may be null.- Returns:
- the set of updated partitions, or null
-
getBackupStrength
Return the BackupStrength for this analysis context. The backup strength determines the degree of resiliency that the resulting distribution will ensure (e.g. machine-safe, rack-safe, site-safe).- Returns:
- the backup strength
-
setBackupStrength
Set the BackupStrength for this analysis context.- Parameters:
strength
- the backup strength
-
getOwnershipMembers
Return the set of members across which to distribute the partition ownership.Note: The set of ownership members does not include any members that may be in the process of leaving
- Returns:
- the set of (non-leaving) ownership enabled members
-
getLeavingOwners
Return the set of ownership members that are leaving.- Returns:
- the set of leaving ownership enabled members
-
getOwnershipMembersList
Return an array containing the members across which to distribute the partition ownership, arranged in arbitrary order.Note: The array does not include any members that may be in the process of leaving
- Returns:
- an array containing the (non-leaving) ownership enabled members
-
getPrimaryLoadCalculator
Return the LoadCalculator used to calculate the primary partition load.- Returns:
- the primary partition load calculator
-
getBackupLoadCalculator
Return the LoadCalculator used to calculate the backup partition load.- Returns:
- the backup partition load calculator
-
getActualBackupCount
protected int getActualBackupCount()Return the number of backups to maintain, given the actual set of ownership-enabled and leaving members.- Returns:
- the number of backups to maintain
-
getCompletedTime
public long getCompletedTime()Return the time at which the analysis associated with this context was completed, or 0 if it has not been completed.- Returns:
- the time at which the analysis was completed, or 0
-
setCompletedTime
protected void setCompletedTime(long ldt) Set the timestamp at which the analysis associated with this context completed.- Parameters:
ldt
- the completion timestamp, or 0
-
getOrphanedPartitions
Return the partitions deemed orphaned as a result of a previous execution ofanalyzeOrphans
.- Returns:
- the partitions deemed orphaned after executing analyzeOrphans
-
setOrphanedPartitions
Set the orphaned partitions that can be prioritized for transfer in order to reduce the transfer cost.- Parameters:
parts
- the set of orphaned partitions
-
getAnalysisDelay
protected long getAnalysisDelay()Return the number of milliseconds the analysis should be delayed;0L
suggests immediate analysis.- Returns:
- the number of milliseconds the analysis should be delayed
-
setAnalysisDelay
protected void setAnalysisDelay(long cDelay) Set the number of milliseconds the analysis should be delayed;0L
suggests immediate analysis.- Parameters:
cDelay
- the number of milliseconds the analysis should be delayed
-
resetTransients
protected void resetTransients()Reset those attributes that should be transient betweenSimpleAssignmentStrategy.analyzeDistribution()
requests. -
initialize
protected void initialize()Initialize the AnalysisContext. -
copyTransients
Copy transient values from another, generally the previous, AnalysisContext to this AnalysisContext. This provides an opportunity for the other context to impart knowledge to this context.- Parameters:
ctxLast
- the previous AnalysisContext
-
isMemberLeaving
Return true iff the specified member is in the process of leaving.- Parameters:
member
- the member- Returns:
- true iff the specified member is in the process of leaving
-
instantiateBackupStrength
Create a backup strength to be used for distribution among the specified set of ownership members.- Parameters:
setOwners
- the ownership members- Returns:
- the backup strength
-
isStrongPossible
Return true iff a "strong" balanced distribution is achievable for the specified set of members, split among a set of categories (e.g. machine, rack, site).- Parameters:
setOwners
- the set of ownership membersmapSplit
- the map of members, associated by their category- Returns:
- true iff a "strong" balanced distribution is achievable
-
isPartitionStrong
protected boolean isPartitionStrong(int iPartition) Return true iff the ownership of the specified partition is "strong", as defined by the current BackupStrength.- Parameters:
iPartition
- the partition- Returns:
- true iff the specified partition is strong
-
isPartitionStrong
Return true iff the specified ownership is "strong", as defined by the current BackupStrength.- Parameters:
owners
- the ownership- Returns:
- true iff the specified ownership is strong
-
isTransferStrong
Return true iff the specified partition transfer would result in a "strong" ownership, as defined by the current BackupStrength.- Parameters:
iPartition
- the partition to transferiStore
- the storage index to transfermember
- the member receiving the transfer- Returns:
- true iff the specified partition transfer is strong
-
isStrong
Return true iff the specified members are mutually "strong", as defined by the backup strength.- Parameters:
member1
- the first member to comparemember2
- the second member to compare- Returns:
- true iff the specified members are mutually strong
-
isStrong
Return true iff the specified member is "strong" with respect to the specified ownership, as defined by the backup strength.- Parameters:
member
- the memberowners
- the ownership- Returns:
- true iff the member is "strong" with respect to the ownership
-
collectOrphaned
Return a partition set representing the subset of the specified partitions that are "orphaned".- Parameters:
parts
- the partition set to collect- Returns:
- a partition set containing the orphaned partitions
-
collectWeak
Return a partition set representing the subset of the specified partitions that are "weak" or "vulnerable" (as defined by the backup strength).- Parameters:
parts
- the partition set to collect- Returns:
- a partition set containing the weak partitions
-
isPartitionEndangered
protected boolean isPartitionEndangered(int iPartition) Return true iff the specified partition is "endangered". A partition is "endangered" if it is incompletely backed up (e.g. some backup copies do not exist).- Parameters:
iPartition
- the partition to test the endangered status- Returns:
- true iff the specified partition is endangered
-
isPartitionEndangered
Return true iff the specified ownership is "endangered". A partition is "endangered" if it is incompletely backed up (e.g. some backup copies do not exist).- Parameters:
owners
- the ownership to test for endangered status- Returns:
- true iff the specified partition is endangered
-
collectEndangered
Return a partition set representing the subset of the specified partitions that are "endangered".- Parameters:
parts
- the partition set to collect- Returns:
- a partition set containing the endangered partitions
-
ensureUpdatedPartitions
Ensure and return the set of updated partitions.- Returns:
- the set of updated partitions
-
getOwnedPartitions
Return the set of partitions for which the specified member owns (or has been assigned by this analysis to own) the specified storage index.- Parameters:
member
- the memberiStore
- the storage index- Returns:
- the set of partitions owned by the member at the specified index
-
isInitialDistribution
Check if the distribution is in the initial state, when the coordinator owns all the partitions and there are no backups.- Parameters:
memberCoordinator
- the coordinator- Returns:
- true if the coordinator owns all the partitions and there are no backups
-
primeDistribution
Set the context to pretend to be the "two servers" membership.- Parameters:
member1
- the first membermember2
- the second member
-
getPartitionOwnership
Return the Ownership information (or the ownership assigned by this analysis) for the specified partition.- Parameters:
iPartition
- the partition to return the ownership for- Returns:
- the Ownership information
-
getPartitionLoad
protected int getPartitionLoad(int iPartition, boolean fPrimary) Return the load (as defined by the appropriate load calculator) for the specified partition.- Parameters:
iPartition
- the partition to determine the load offPrimary
- true iff the primary load should be returned, or false for backup- Returns:
- the load for the specified partition
-
getMemberLoad
Return the (primary or backup) partition load of the specified member.- Parameters:
member
- the member to calculate the partition load forfPrimary
- true for primary partition load, else backup load- Returns:
- the partition load for the specified member
-
calculateAnalysisDelay
protected long calculateAnalysisDelay()Calculate whether the analysis should be delayed.- Returns:
- the delay before the next analysis, or 0 if the analysis should commence immediately
-
transitionPartition
Update the analysis context to reflect the suggested transfer of the specified number of primary partitions between the specified members.- Parameters:
iPartition
- the partition id to transferiStore
- the storage index to transfermemberFrom
- the member to transfer partitions from, or null if the partition storage-index was endangeredmemberTo
- the member to transfer partitions to, or null if the partition storage index should be endangered
-
suggestDistribution
protected boolean suggestDistribution()Suggest any distribution that may have been collected by this analysis context to the DistributionManager.- Returns:
- true iff a distribution was suggested
-
instantiateNotOwnedFilter
Instantiate and return a NotOwnedFilter with the specified ownership.- Parameters:
owners
- the ownership- Returns:
- a NotOwnedFilter
-
instantiateSafetyFilter
Instantiate and return a SafetyFilter with the specified ownership.- Parameters:
owners
- the ownershipiStore
- the storage index at which to evaluate members for safety- Returns:
- a SafetyFilter
-
instantiateOverloadedFilter
Instantiate a filter that matches members with an over-load.- Parameters:
fPrimary
- true for primary partition load- Returns:
- a filter that matches members with an over-load
-
instantiateUnderloadedFilter
Instantiate a filter that matches members with an under-load.- Parameters:
fPrimary
- true for primary partition load- Returns:
- a filter that matches members with an under-load
-
instantiateLoadComparator
public SimpleAssignmentStrategy.AnalysisContext.LoadComparator instantiateLoadComparator(boolean fPrimary) Return a comparator for primary or backup partition load.- Parameters:
fPrimary
- true for primary, or false for backup- Returns:
- a comparator for primary or backup partition load
-
instantiateStrengthComparator
public SimpleAssignmentStrategy.AnalysisContext.StrengthComparator instantiateStrengthComparator(Ownership owners) Instantiate a StrengthComparator for the specified reference ownership.- Parameters:
owners
- the ownership, from which to determine member strength- Returns:
- a StrengthComparator
-
instantiateDefaultComparator
Instantiate a default member Comparator. The returned comparator must define a strict total ordering over the set of Members. In other words, no two distinct members may becompared
to be equivalent.- Returns:
- a Comparator that defines a strict total ordering of Members
-