public class TopologyAwareConsistentHash extends AbstractWheelConsistentHash
Algorithm: - place nodes on the hash wheel based address's hash code - For selecting owner nodes: - pick the first one based on key's hash code - for subsequent nodes, walk clockwise and pick nodes that have a different site id - if not enough nodes found repeat walk again and pick nodes that have different site id and rack id - if not enough nodes found repeat walk again and pick nodes that have different site id, rack id and machine id - Ultimately cycle back to the first node selected, don't discard any nodes, regardless of machine id/rack id/site id match.
Modifier and Type | Class and Description |
---|---|
static class |
TopologyAwareConsistentHash.Externalizer |
caches, hashFunction, numVirtualNodes, positionKeys, positionValues, trace
groupManager
Constructor and Description |
---|
TopologyAwareConsistentHash() |
TopologyAwareConsistentHash(Hash hash) |
Modifier and Type | Method and Description |
---|---|
protected Log |
getLog() |
boolean |
isKeyLocalToAddress(Address target,
Object key,
int replCount)
Test to see whether a key is mapped to a given address.
|
List<Address> |
locate(Object key,
int replCount)
Locates a key, given a replication count (number of copies).
|
void |
setCaches(Set<Address> newCaches)
Sets the collection of cache addresses in the cluster.
|
getCaches, getHashIds, getNormalizedHash, getPositionIndex, getPositionsIterator, isVirtualNodesEnabled, primaryLocation, setHashFunction, setNumVirtualNodes, toString
getBackupsForNode, getGrouping, getStateProvidersOnJoin, getStateProvidersOnLeave, locateAll, setGroupManager
public TopologyAwareConsistentHash()
public TopologyAwareConsistentHash(Hash hash)
public void setCaches(Set<Address> newCaches)
ConsistentHash
setCaches
in interface ConsistentHash
setCaches
in class AbstractWheelConsistentHash
newCaches
- A set of unique caches in cluster.public List<Address> locate(Object key, int replCount)
ConsistentHash
key
- key to locatereplCount
- replication count (number of copies)ConsistentHash.setCaches(java.util.Set)
. Should never be null, and should contain replCount elements or the max
number of caches available, whichever is smaller.public boolean isKeyLocalToAddress(Address target, Object key, int replCount)
ConsistentHash
isKeyLocalToAddress
in interface ConsistentHash
isKeyLocalToAddress
in class AbstractConsistentHash
target
- address to testkey
- key to testreplCount
- repl countprotected Log getLog()
getLog
in class AbstractWheelConsistentHash
Copyright © 2012 JBoss by Red Hat. All Rights Reserved.