Class ReplicatedConsistentHash
- java.lang.Object
-
- org.infinispan.distribution.ch.impl.ReplicatedConsistentHash
-
- All Implemented Interfaces:
ConsistentHash
public class ReplicatedConsistentHash extends Object implements ConsistentHash
Special implementation ofConsistentHashfor replicated caches. The hash-space has several segments owned by all members and the primary ownership of each segment is evenly spread between members.- Since:
- 5.2
- Author:
- Dan Berindei, anistor@redhat.com
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classReplicatedConsistentHash.Externalizer
-
Constructor Summary
Constructors Constructor Description ReplicatedConsistentHash(List<Address> members, int[] primaryOwners)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)List<Address>getMembers()Should return the addresses of the nodes used to create this consistent hash.intgetNumOwners()intgetNumSegments()Set<Integer>getPrimarySegmentsForOwner(Address owner)Returns the segments that this cache member is the primary owner for.StringgetRoutingTableAsString()Returns a string containing all the segments and their associated addresses.Set<Integer>getSegmentsForOwner(Address owner)Returns the segments owned by a cache member.inthashCode()booleanisReplicated()booleanisSegmentLocalToNode(Address nodeAddress, int segmentId)Check if a segment is local to a given member.List<Address>locateOwnersForSegment(int segmentId)AddresslocatePrimaryOwnerForSegment(int segmentId)ConsistentHashremapAddresses(UnaryOperator<Address> remapper)Returns a new ConsistentHash with the addresses remapped according to the providedUnaryOperator.voidtoScopedState(ScopedPersistentState state)Writes this ConsistentHash to the specified scoped state.StringtoString()ReplicatedConsistentHashunion(ReplicatedConsistentHash ch2)-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.infinispan.distribution.ch.ConsistentHash
getCapacityFactors
-
-
-
-
Method Detail
-
union
public ReplicatedConsistentHash union(ReplicatedConsistentHash ch2)
-
getNumSegments
public int getNumSegments()
- Specified by:
getNumSegmentsin interfaceConsistentHash- 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.
-
getNumOwners
public int getNumOwners()
-
getMembers
public List<Address> getMembers()
Description copied from interface:ConsistentHashShould return the addresses of the nodes used to create this consistent hash.- Specified by:
getMembersin interfaceConsistentHash- Returns:
- set of node addresses.
-
locateOwnersForSegment
public List<Address> locateOwnersForSegment(int segmentId)
- Specified by:
locateOwnersForSegmentin interfaceConsistentHash- 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)
- Specified by:
locatePrimaryOwnerForSegmentin interfaceConsistentHash- Returns:
- The primary owner of a given hash space segment. This is equivalent to
locateOwnersForSegment(segmentId).get(0)but is more efficient
-
getSegmentsForOwner
public Set<Integer> getSegmentsForOwner(Address owner)
Description copied from interface:ConsistentHashReturns the segments owned by a cache member.- Specified by:
getSegmentsForOwnerin interfaceConsistentHash- 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
-
getPrimarySegmentsForOwner
public Set<Integer> getPrimarySegmentsForOwner(Address owner)
Description copied from interface:ConsistentHashReturns the segments that this cache member is the primary owner for.- Specified by:
getPrimarySegmentsForOwnerin interfaceConsistentHash- 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
-
getRoutingTableAsString
public String getRoutingTableAsString()
Description copied from interface:ConsistentHashReturns a string containing all the segments and their associated addresses.- Specified by:
getRoutingTableAsStringin interfaceConsistentHash
-
isSegmentLocalToNode
public boolean isSegmentLocalToNode(Address nodeAddress, int segmentId)
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.
- Specified by:
isSegmentLocalToNodein interfaceConsistentHash
-
isReplicated
public boolean isReplicated()
- Specified by:
isReplicatedin interfaceConsistentHash- Returns:
trueif every member owns every segment. This allows callers to skip computing the segment of a key in some cases.
-
toScopedState
public void toScopedState(ScopedPersistentState state)
Description copied from interface:ConsistentHashWrites this ConsistentHash to the specified scoped state. Before invoking this method, the ConsistentHash addresses will have to be replaced with their correspondingPersistentUUIDs- Specified by:
toScopedStatein interfaceConsistentHash- Parameters:
state- the state to which this ConsistentHash will be written
-
remapAddresses
public ConsistentHash remapAddresses(UnaryOperator<Address> remapper)
Description copied from interface:ConsistentHashReturns 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.- Specified by:
remapAddressesin interfaceConsistentHash- 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
-
-