Class ScatteredConsistentHash
java.lang.Object
org.infinispan.distribution.ch.impl.AbstractConsistentHash
org.infinispan.distribution.ch.impl.ScatteredConsistentHash
- All Implemented Interfaces:
ConsistentHash
CH used by scattered caches. Allows no owners for segments (until the CH is balanced).
We cannot have an owner for each segment assigned all the time, because after one node crashes,
ConsistentHashFactory.updateMembers(CH, java.util.List<org.infinispan.remoting.transport.Address>, java.util.Map<org.infinispan.remoting.transport.Address, java.lang.Float>)
is called and the result
is sent in CH_UPDATE. Such topology is installed and later during rebalance, a diff of segments
between the installed and new (rebalancing) topology is computed. If we assigned all the owners
right in updateMembers, this diff would be empty.- Since:
- 9.1
-
Nested Class Summary
-
Field Summary
Fields inherited from class org.infinispan.distribution.ch.impl.AbstractConsistentHash
capacityFactors, members, STATE_CAPACITY_FACTOR, STATE_CAPACITY_FACTORS, STATE_NUM_SEGMENTS
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
int
Returns 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.int
hashCode()
boolean
isSegmentLocalToNode
(Address nodeAddress, int segmentId) Check if a segment is local to a given member.locateOwnersForSegment
(int segmentId) locatePrimaryOwnerForSegment
(int segmentId) remapAddresses
(UnaryOperator<Address> remapper) Returns a new ConsistentHash with the addresses remapped according to the providedUnaryOperator
.void
Writes this ConsistentHash to the specified scoped state.toString()
union
(ScatteredConsistentHash sch2) Prefers owners from the second hash -> effectively this will make pendingCH == unionCH (I think)Methods inherited from class org.infinispan.distribution.ch.impl.AbstractConsistentHash
checkSameHashAndSegments, getCapacityFactors, getMembers, 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, remapAddressRemoveMissing
-
Constructor Details
-
ScatteredConsistentHash
-
-
Method Details
-
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: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
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
- Returns:
- All the nodes that own a given hash space segment, first address is the primary owner. The returned list is unmodifiable.
-
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: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() -
equals
-
toString
-
getRoutingTableAsString
Description copied from interface:ConsistentHash
Returns a string containing all the segments and their associated addresses. -
union
Prefers owners from the second hash -> effectively this will make pendingCH == unionCH (I think) -
toScopedState
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
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
-