Class ReplicatedConsistentHash
java.lang.Object
org.infinispan.distribution.ch.impl.ReplicatedConsistentHash
- All Implemented Interfaces:
ConsistentHash
Special implementation of
ConsistentHash for 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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanThe capacity factor of each member.Should return the addresses of the nodes used to create this consistent hash.intintReturns 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()booleanbooleanisSegmentLocalToNode(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()
-
Constructor Details
-
ReplicatedConsistentHash
-
ReplicatedConsistentHash
-
-
Method Details
-
getMembers
Description copied from interface:ConsistentHashShould return the addresses of the nodes used to create this consistent hash.- Specified by:
getMembersin interfaceConsistentHash- Returns:
- list of node addresses.
-
union
-
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() -
locateOwnersForSegment
- 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
- 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
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.
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.- 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.
The set is empty if
owneris not a member of the consistent hash.
-
getRoutingTableAsString
Description copied from interface:ConsistentHashReturns a string containing all the segments and their associated addresses.- Specified by:
getRoutingTableAsStringin interfaceConsistentHash
-
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.
- 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
Description copied from interface:ConsistentHashWrites thisConsistentHashto the specified scoped persistent state.- Specified by:
toScopedStatein interfaceConsistentHash- Parameters:
state- The state to which thisConsistentHashwill be written.addressMapper- The mapperFunctionto convert theAddressto theUUIDused to persist the address within the state.
-
getCapacityFactors
Description copied from interface:ConsistentHashThe capacity factor of each member. Determines the relative capacity of each node compared to the others. Ifnull, all the members are assumed to have a capacity factor of 1.- Specified by:
getCapacityFactorsin interfaceConsistentHash
-
toString
-
hashCode
-
equals
-