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, tracegroupManager| 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, toStringgetBackupsForNode, getGrouping, getStateProvidersOnJoin, getStateProvidersOnLeave, locateAll, setGroupManagerpublic TopologyAwareConsistentHash()
public TopologyAwareConsistentHash(Hash hash)
public void setCaches(Set<Address> newCaches)
ConsistentHashsetCaches in interface ConsistentHashsetCaches in class AbstractWheelConsistentHashnewCaches - A set of unique caches in cluster.public List<Address> locate(Object key, int replCount)
ConsistentHashkey - 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)
ConsistentHashisKeyLocalToAddress in interface ConsistentHashisKeyLocalToAddress in class AbstractConsistentHashtarget - address to testkey - key to testreplCount - repl countprotected Log getLog()
getLog in class AbstractWheelConsistentHashCopyright © 2012 JBoss by Red Hat. All Rights Reserved.