Class SimpleAssignmentStrategy.AnalysisContext

java.lang.Object
com.tangosol.net.partition.SimpleAssignmentStrategy.AnalysisContext
Enclosing class:
SimpleAssignmentStrategy

protected class SimpleAssignmentStrategy.AnalysisContext extends Object
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.
  • Field Details

    • m_calculatorPrimary

      protected SimpleAssignmentStrategy.LoadCalculator m_calculatorPrimary
      The primary LoadCalculator.
    • m_calculatorBackup

      protected SimpleAssignmentStrategy.LoadCalculator m_calculatorBackup
      The backup LoadCalculator.
    • m_mapOwnedPartitions

      protected Map<Member,PartitionSet[]> m_mapOwnedPartitions
      The map of member ownership information for this analysis context.
    • m_aOwners

      protected Ownership[] m_aOwners
      The ownership array for this analysis context.
    • m_partsUpdated

      protected PartitionSet m_partsUpdated
      The set of partitions that have been updated in this analysis context; may be null.
    • m_partsOrphaned

      protected PartitionSet m_partsOrphaned
      The set of partitions that were determined to be orphaned in the call to PartitionAssignmentStrategy.analyzeOrphans(Map).
    • m_strength

      The backup strength for the resiliency of the resulting distribution.
    • m_cBackupActual

      protected int m_cBackupActual
      The 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_cFairSharePrimary

      protected int m_cFairSharePrimary
      The fair-share primary partition load.
    • m_cFairShareBackup

      protected int m_cFairShareBackup
      The fair-share backup partition load.
    • m_setOwnershipMembers

      protected Set m_setOwnershipMembers
      The set of ownership members to include in the distribution.

      Note: this set does not include members that are leaving

    • m_setOwenersLeaving

      protected Set m_setOwenersLeaving
      The set of ownership members that are leaving.
    • m_aOwnershipMembers

      protected Member[] 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_ldtCompleted
      The timestamp of when the analysis represented by this context was completed, or 0 if it is not yet complete.
    • m_cDelay

      protected long m_cDelay
      An explicit delay to be used in favor of a determined delay in calculateAnalysisDelay().
  • Constructor Details

    • AnalysisContext

      public AnalysisContext()
      Default constructor.
  • Method Details

    • getUpdatedPartitions

      protected PartitionSet getUpdatedPartitions()
      Return the set of updated partitions; may be null.
      Returns:
      the set of updated partitions, or null
    • getBackupStrength

      protected SimpleAssignmentStrategy.BackupStrength 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

      protected void setBackupStrength(SimpleAssignmentStrategy.BackupStrength strength)
      Set the BackupStrength for this analysis context.
      Parameters:
      strength - the backup strength
    • getOwnershipMembers

      protected Set<Member> 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

      protected Set<Member> getLeavingOwners()
      Return the set of ownership members that are leaving.
      Returns:
      the set of leaving ownership enabled members
    • getOwnershipMembersList

      protected Member[] 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

      public SimpleAssignmentStrategy.LoadCalculator getPrimaryLoadCalculator()
      Return the LoadCalculator used to calculate the primary partition load.
      Returns:
      the primary partition load calculator
    • getBackupLoadCalculator

      public SimpleAssignmentStrategy.LoadCalculator 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

      protected PartitionSet getOrphanedPartitions()
      Return the partitions deemed orphaned as a result of a previous execution of analyzeOrphans.
      Returns:
      the partitions deemed orphaned after executing analyzeOrphans
    • setOrphanedPartitions

      protected void setOrphanedPartitions(PartitionSet parts)
      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 between SimpleAssignmentStrategy.analyzeDistribution() requests.
    • initialize

      protected void initialize()
      Initialize the AnalysisContext.
    • copyTransients

      protected void copyTransients(SimpleAssignmentStrategy.AnalysisContext ctxLast)
      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
    • getFairShare

      protected int getFairShare(boolean fPrimary)
      Return the (primary or backup) fair-share partition load.
      Parameters:
      fPrimary - true iff the primary fair-share should be returned
      Returns:
      the fair-share partition load
    • calculateFairShare

      protected int calculateFairShare(boolean fPrimary)
      Return the "fair share" (F) load. It is a ceiling for the load on a for fully balance distribution. The fairness goal is to achieve such a state that the load for all members is between F-L and F, where L is typically the minimum of partition load values.
      Parameters:
      fPrimary - true for the primary fair-share, or false for backup
      Returns:
      the fair share
    • isMemberLeaving

      protected boolean isMemberLeaving(Member member)
      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

      protected SimpleAssignmentStrategy.BackupStrength instantiateBackupStrength(Set setOwners)
      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

      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).
      Parameters:
      setOwners - the set of ownership members
      mapSplit - 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

      protected boolean isPartitionStrong(Ownership owners)
      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

      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.
      Parameters:
      iPartition - the partition to transfer
      iStore - the storage index to transfer
      member - the member receiving the transfer
      Returns:
      true iff the specified partition transfer is strong
    • isStrong

      protected boolean isStrong(Member member1, Member member2)
      Return true iff the specified members are mutually "strong", as defined by the backup strength.
      Parameters:
      member1 - the first member to compare
      member2 - the second member to compare
      Returns:
      true iff the specified members are mutually strong
    • isStrong

      protected boolean isStrong(Member member, Ownership owners)
      Return true iff the specified member is "strong" with respect to the specified ownership, as defined by the backup strength.
      Parameters:
      member - the member
      owners - the ownership
      Returns:
      true iff the member is "strong" with respect to the ownership
    • collectOrphaned

      protected PartitionSet collectOrphaned(PartitionSet parts)
      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

      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).
      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

      protected boolean isPartitionEndangered(Ownership owners)
      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

      protected PartitionSet collectEndangered(PartitionSet parts)
      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

      protected PartitionSet ensureUpdatedPartitions()
      Ensure and return the set of updated partitions.
      Returns:
      the set of updated partitions
    • getOwnedPartitions

      public PartitionSet 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.
      Parameters:
      member - the member
      iStore - the storage index
      Returns:
      the set of partitions owned by the member at the specified index
    • isInitialDistribution

      public 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.
      Parameters:
      memberCoordinator - the coordinator
      Returns:
      true if the coordinator owns all the partitions and there are no backups
    • primeDistribution

      protected void primeDistribution(Member member1, Member member2)
      Set the context to pretend to be the "two servers" membership.
      Parameters:
      member1 - the first member
      member2 - the second member
    • getPartitionOwnership

      public Ownership getPartitionOwnership(int iPartition)
      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 of
      fPrimary - true iff the primary load should be returned, or false for backup
      Returns:
      the load for the specified partition
    • getMemberLoad

      protected int getMemberLoad(Member member, boolean fPrimary)
      Return the (primary or backup) partition load of the specified member.
      Parameters:
      member - the member to calculate the partition load for
      fPrimary - 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

      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.
      Parameters:
      iPartition - the partition id to transfer
      iStore - the storage index to transfer
      memberFrom - the member to transfer partitions from, or null if the partition storage-index was endangered
      memberTo - 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

      public Filter instantiateNotOwnedFilter(Ownership owners)
      Instantiate and return a NotOwnedFilter with the specified ownership.
      Parameters:
      owners - the ownership
      Returns:
      a NotOwnedFilter
    • instantiateSafetyFilter

      public Filter instantiateSafetyFilter(Ownership owners, int iStore)
      Instantiate and return a SafetyFilter with the specified ownership.
      Parameters:
      owners - the ownership
      iStore - the storage index at which to evaluate members for safety
      Returns:
      a SafetyFilter
    • instantiateOverloadedFilter

      public Filter instantiateOverloadedFilter(boolean fPrimary)
      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

      public Filter instantiateUnderloadedFilter(boolean fPrimary)
      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

      public Comparator 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 be compared to be equivalent.
      Returns:
      a Comparator that defines a strict total ordering of Members