Class DefaultConsistentHash
- java.lang.Object
-
- org.infinispan.distribution.ch.impl.AbstractConsistentHash
-
- org.infinispan.distribution.ch.impl.DefaultConsistentHash
-
- All Implemented Interfaces:
ConsistentHash
@Immutable public class DefaultConsistentHash extends AbstractConsistentHash
DefaultConsistentHash
implementation. This object is immutable. Every segment must have a primary owner.- Since:
- 5.2
- Author:
- Dan Berindei, anistor@redhat.com
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DefaultConsistentHash.Externalizer
-
Field Summary
-
Fields inherited from class org.infinispan.distribution.ch.impl.AbstractConsistentHash
capacityFactors, hashFunction, members, segmentSize, STATE_CAPACITY_FACTOR, STATE_CAPACITY_FACTORS, STATE_NUM_SEGMENTS
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
equals(Object o)
int
getNumOwners()
int
getNumSegments()
Set<Integer>
getPrimarySegmentsForOwner(Address owner)
Returns the segments that this cache member is the primary owner for.String
getRoutingTableAsString()
Returns a string containing all the segments and their associated addresses.List<Integer>
getSegmentEndHashes()
Deprecated.Since 8.2, useHashFunctionPartitioner.getSegmentEndHashes()
instead.Set<Integer>
getSegmentsForOwner(Address owner)
Returns the segments owned by a cache member.int
hashCode()
boolean
isSegmentLocalToNode(Address nodeAddress, int segmentId)
Check if a segment is local to a given member.List<Address>
locateOwnersForSegment(int segmentId)
Address
locatePrimaryOwnerForSegment(int segmentId)
String
prettyPrintOwnership()
ConsistentHash
remapAddresses(UnaryOperator<Address> remapper)
Returns a new ConsistentHash with the addresses remapped according to the providedUnaryOperator
.void
toScopedState(ScopedPersistentState state)
Writes this ConsistentHash to the specified scoped state.String
toString()
DefaultConsistentHash
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, getHashFunction, getMembers, getNormalizedHash, getSegment, isKeyLocalToNode, mergeLists, parseCapacityFactors, parseHashFunction, parseMembers, parseNumSegments, remapCapacityFactors, remapMembers, unionCapacityFactors
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.infinispan.distribution.ch.ConsistentHash
isReplicated, locateAllOwners, locateOwners, locatePrimaryOwner
-
-
-
-
Method Detail
-
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.
-
getSegmentEndHashes
@Deprecated public List<Integer> getSegmentEndHashes()
Deprecated.Since 8.2, useHashFunctionPartitioner.getSegmentEndHashes()
instead.
-
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
-
getNumOwners
public int getNumOwners()
- Returns:
- The configured number of owners. Note that the actual number of owners of each key may be different.
-
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.
-
getRoutingTableAsString
public String getRoutingTableAsString()
Description copied from interface:ConsistentHash
Returns a string containing all the segments and their associated addresses.
-
union
public DefaultConsistentHash union(DefaultConsistentHash dch2)
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.
-
prettyPrintOwnership
public String prettyPrintOwnership()
-
toScopedState
public void toScopedState(ScopedPersistentState state)
Description copied from interface:ConsistentHash
Writes this ConsistentHash to the specified scoped state. Before invoking this method, the ConsistentHash addresses will have to be replaced with their correspondingPersistentUUID
s- Specified by:
toScopedState
in interfaceConsistentHash
- Overrides:
toScopedState
in classAbstractConsistentHash
- Parameters:
state
- the state to which this ConsistentHash will be written
-
remapAddresses
public ConsistentHash remapAddresses(UnaryOperator<Address> remapper)
Description copied from interface:ConsistentHash
Returns a new ConsistentHash with the addresses remapped according to the providedUnaryOperator
. If an address cannot me remapped (i.e. the remapper returns null) this method should return null.- Parameters:
remapper
- the remapper which given an address replaces it with another one- Returns:
- the remapped ConsistentHash or null if one of the remapped addresses is null
-
-