public interface ConsistentHash
ConsistentHashFactory.
A consistent hash assigns each key a list of owners; the number of owners is defined at creation time,
but the consistent hash is free to return a smaller or a larger number of owners, depending on
circumstances.
The first element in the list of owners is the "primary owner". The other owners are called "backup owners".
Some implementations guarantee that there will always be a primary owner, others do not.
This interface gives access to some implementation details of the consistent hash.
Our consistent hashes work by splitting the hash space (the set of possible hash codes) into
fixed segments and then assigning those segments to nodes dynamically. The number of segments
is defined at creation time, and the mapping of keys to segments never changes.
The mapping of segments to nodes can change as the membership of the cache changes.
Normally application code doesn't need to know about this implementation detail, but some
applications may benefit from the knowledge that all the keys that map to one segment are
always located on the same server.| Modifier and Type | Method and Description |
|---|---|
default Map<Address,Float> |
getCapacityFactors()
The capacity factor of each member.
|
List<Address> |
getMembers()
Should return the addresses of the nodes used to create this consistent hash.
|
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.
|
Set<Integer> |
getSegmentsForOwner(Address owner)
Returns the segments owned by a cache member.
|
default boolean |
isReplicated() |
default 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) |
default ConsistentHash |
remapAddresses(UnaryOperator<Address> remapper)
Returns a new ConsistentHash with the addresses remapped according to the provided
UnaryOperator. |
default void |
toScopedState(ScopedPersistentState state)
Writes this ConsistentHash to the specified scoped state.
|
int getNumSegments()
List<Address> getMembers()
List<Address> locateOwnersForSegment(int segmentId)
Address locatePrimaryOwnerForSegment(int segmentId)
locateOwnersForSegment(segmentId).get(0) but is more efficientdefault boolean isSegmentLocalToNode(Address nodeAddress, int segmentId)
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.
default boolean isReplicated()
true if every member owns every segment. This allows callers to skip computing the
segment of a key in some cases.Set<Integer> getSegmentsForOwner(Address owner)
owner - the address of the memberSet<Integer> getPrimarySegmentsForOwner(Address owner)
owner - the address of the memberString getRoutingTableAsString()
default void toScopedState(ScopedPersistentState state)
PersistentUUIDsstate - the state to which this ConsistentHash will be writtendefault ConsistentHash remapAddresses(UnaryOperator<Address> remapper)
UnaryOperator.
If an address cannot me remapped (i.e. the remapper returns null) this method should return null.remapper - the remapper which given an address replaces it with another oneCopyright © 2022 JBoss by Red Hat. All rights reserved.