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, as long as each key has at least one owner.
The first element in the list of owners is the "primary owner". A key will always have a primary owner.
The other owners are called "backup owners".
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 |
---|---|
Hash |
getHashFunction() |
List<Address> |
getMembers()
Should return the addresses of the nodes used to create this consistent hash.
|
int |
getNumOwners() |
int |
getNumSegments() |
String |
getRoutingTableAsString()
Returns a string containing all the segments and their associated addresses.
|
int |
getSegment(Object key) |
Set<Integer> |
getSegmentsForOwner(Address owner)
Returns the segments owned by a cache member.
|
boolean |
isKeyLocalToNode(Address nodeAddress,
Object key)
Test to see whether a key is owned by a given node.
|
Set<Address> |
locateAllOwners(Collection<Object> keys)
The logical equivalent of calling
locateOwners(java.lang.Object) multiple times for each key in the collection of
keys and merging the results. |
List<Address> |
locateOwners(Object key)
Finds all the owners of a key.
|
List<Address> |
locateOwnersForSegment(int segmentId) |
Address |
locatePrimaryOwner(Object key)
Should be equivalent to return the first element of
locateOwners(java.lang.Object) . |
Address |
locatePrimaryOwnerForSegment(int segmentId) |
int getNumOwners()
Hash getHashFunction()
int getNumSegments()
List<Address> getMembers()
Address locatePrimaryOwner(Object key)
locateOwners(java.lang.Object)
.
Useful as a performance optimization, as this is a frequently needed information.key
- key to locateList<Address> locateOwners(Object key)
key
- key to locatenull
, and it will always have at least 1 element.Set<Address> locateAllOwners(Collection<Object> keys)
locateOwners(java.lang.Object)
multiple times for each key in the collection of
keys and merging the results. Implementations may be optimised for such a bulk lookup.keys
- keys to locate.boolean isKeyLocalToNode(Address nodeAddress, Object key)
nodeAddress
- address of the node to testkey
- key to testtrue
if the key is mapped to the address; false
otherwiseint getSegment(Object key)
List<Address> locateOwnersForSegment(int segmentId)
Address locatePrimaryOwnerForSegment(int segmentId)
locateOwnersForSegment(segmentId).get(0)
but is more efficientSet<Integer> getSegmentsForOwner(Address owner)
owner
- the address of the memberString getRoutingTableAsString()
Copyright © 2017 JBoss, a division of Red Hat. All Rights Reserved.