Class DefaultConsistentHash
java.lang.Object
org.infinispan.distribution.ch.impl.AbstractConsistentHash
org.infinispan.distribution.ch.impl.DefaultConsistentHash
- All Implemented Interfaces:
ConsistentHash
Default
ConsistentHash implementation. This object is immutable.
Every segment must have a primary owner.- Since:
- 5.2
- Author:
- Dan Berindei, anistor@redhat.com
-
Field Summary
Fields inherited from class org.infinispan.distribution.ch.impl.AbstractConsistentHash
capacityFactors, members, STATE_CAPACITY_FACTOR, STATE_CAPACITY_FACTORS, STATE_NUM_SEGMENTS -
Method Summary
Modifier and TypeMethodDescriptionstatic DefaultConsistentHashcreate(int numOwners, int numSegments, List<Address> members, Map<Address, Float> capacityFactors, List<Address>[] segmentOwners) booleanintintReturns the segments that this cache member is the primary owner for.Returns a string containing all the segments and their associated addresses.getSegmentsForOwner(Address owner) Returns the segments owned by a cache member.inthashCode()booleanisSegmentLocalToNode(Address nodeAddress, int segmentId) Check if a segment is local to a given member.locateOwnersForSegment(int segmentId) locatePrimaryOwnerForSegment(int segmentId) voidtoScopedState(ScopedPersistentState state, Function<Address, UUID> addressMapper) Writes thisConsistentHashto the specified scoped persistent state.toString()union(DefaultConsistentHash dch2) Merges two consistent hash objects that have the same number of segments, numOwners and hash function.Methods inherited from class org.infinispan.distribution.ch.impl.AbstractConsistentHash
checkSameHashAndSegments, getCapacityFactors, getMemberIndexMap, getMembers, mergeLists, parseMembers, parseNumSegments, unionCapacityFactors, writeAddressToStateMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.infinispan.distribution.ch.ConsistentHash
isReplicated
-
Method Details
-
create
-
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
Description copied from interface:ConsistentHashReturns 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
owneris not a member of the consistent hash.
-
getPrimarySegmentsForOwner
Description copied from interface:ConsistentHashReturns 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
owneris not a member of the consistent hash.
-
locateOwnersForSegment
-
locatePrimaryOwnerForSegment
- Returns:
- The primary owner of a given hash space segment. This is equivalent to
locateOwnersForSegment(segmentId).get(0)but is more efficient
-
isSegmentLocalToNode
Description copied from interface:ConsistentHashCheck 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
-
equals
-
toString
-
getRoutingTableAsString
Description copied from interface:ConsistentHashReturns 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
Description copied from interface:ConsistentHashWrites thisConsistentHashto the specified scoped persistent state.- Specified by:
toScopedStatein interfaceConsistentHash- Overrides:
toScopedStatein classAbstractConsistentHash- Parameters:
state- The state to which thisConsistentHashwill be written.addressMapper- The mapperFunctionto convert theAddressto theUUIDused to persist the address within the state.
-