Class DefaultConsistentHash

java.lang.Object
org.infinispan.distribution.ch.impl.AbstractConsistentHash
org.infinispan.distribution.ch.impl.DefaultConsistentHash
All Implemented Interfaces:
ConsistentHash

@Immutable @ProtoTypeId(1067) public class DefaultConsistentHash extends AbstractConsistentHash
Default ConsistentHash implementation. This object is immutable. Every segment must have a primary owner.
Since:
5.2
Author:
Dan Berindei, anistor@redhat.com
  • Method Details

    • create

      public static DefaultConsistentHash create(int numOwners, int numSegments, List<Address> members, Map<Address,Float> capacityFactors, List<Address>[] segmentOwners)
    • getNumOwners

      @ProtoField(3) public int getNumOwners()
    • getNumSegments

      public int getNumSegments()
      Returns:
      The actual number of hash space segments. Note that it may not be the same as the number of segments passed in at creation time.
    • getSegmentsForOwner

      public Set<Integer> getSegmentsForOwner(Address owner)
      Description copied from interface: ConsistentHash
      Returns the segments owned by a cache member.
      Parameters:
      owner - the address of the member
      Returns:
      a non-null set of segment IDs, may or may not be unmodifiable, which shouldn't be modified by caller. The set is empty if owner is not a member of the consistent hash.
    • getPrimarySegmentsForOwner

      public Set<Integer> getPrimarySegmentsForOwner(Address owner)
      Description copied from interface: ConsistentHash
      Returns the segments that this cache member is the primary owner for.
      Parameters:
      owner - the address of the member
      Returns:
      a non-null set of segment IDs, may or may not be unmodifiable, which shouldn't be modified by caller. The set is empty if owner is not a member of the consistent hash.
    • locateOwnersForSegment

      public List<Address> locateOwnersForSegment(int segmentId)
      Returns:
      All the nodes that own a given hash space segment, first address is the primary owner. The returned list is unmodifiable.
    • locatePrimaryOwnerForSegment

      public Address locatePrimaryOwnerForSegment(int segmentId)
      Returns:
      The primary owner of a given hash space segment. This is equivalent to locateOwnersForSegment(segmentId).get(0) but is more efficient
    • isSegmentLocalToNode

      public boolean isSegmentLocalToNode(Address nodeAddress, int segmentId)
      Description copied from interface: ConsistentHash
      Check if a segment is local to a given member.

      Implementation note: normally key-based method are implemented based on segment-based methods. Here, however, we need a default implementation for the segment-based method for backwards-compatibility reasons.

    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getRoutingTableAsString

      public String getRoutingTableAsString()
      Description copied from interface: ConsistentHash
      Returns a string containing all the segments and their associated addresses.
    • union

      Merges two consistent hash objects that have the same number of segments, numOwners and hash function. For each segment, the primary owner of the first CH has priority, the other primary owners become backups.
    • toScopedState

      public void toScopedState(ScopedPersistentState state, Function<Address,UUID> addressMapper)
      Description copied from interface: ConsistentHash
      Writes this ConsistentHash to the specified scoped persistent state.
      Specified by:
      toScopedState in interface ConsistentHash
      Overrides:
      toScopedState in class AbstractConsistentHash
      Parameters:
      state - The state to which this ConsistentHash will be written.
      addressMapper - The mapper Function to convert the Address to the UUID used to persist the address within the state.