org.infinispan.distribution.ch
Class TopologyAwareConsistentHash
java.lang.Object
org.infinispan.distribution.ch.AbstractConsistentHash
org.infinispan.distribution.ch.AbstractWheelConsistentHash
org.infinispan.distribution.ch.TopologyAwareConsistentHash
- All Implemented Interfaces:
- ConsistentHash
public class TopologyAwareConsistentHash
- extends AbstractWheelConsistentHash
Consistent hash that is aware of cluster topology. Design described here: http://community.jboss.org/wiki/DesigningServerHinting.
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.
- Since:
- 4.2
- Author:
- Mircea.Markus@jboss.com
TopologyAwareConsistentHash
public TopologyAwareConsistentHash()
TopologyAwareConsistentHash
public TopologyAwareConsistentHash(Hash hash)
setCaches
public void setCaches(Set<Address> newCaches)
- Description copied from interface:
ConsistentHash
- Sets the collection of cache addresses in the cluster. The implementation should store these internally and use
these to locate keys.
- Specified by:
setCaches in interface ConsistentHash- Overrides:
setCaches in class AbstractWheelConsistentHash
- Parameters:
newCaches - A set of unique caches in cluster.
locate
public List<Address> locate(Object key,
int replCount)
- Description copied from interface:
ConsistentHash
- Locates a key, given a replication count (number of copies).
- Parameters:
key - key to locatereplCount - replication count (number of copies)
- Returns:
- a list of addresses where the key resides, where this list is a subset of the addresses set in
ConsistentHash.setCaches(java.util.Set). Should never be null, and should contain replCount elements or the max
number of caches available, whichever is smaller.
isKeyLocalToAddress
public boolean isKeyLocalToAddress(Address target,
Object key,
int replCount)
- Description copied from interface:
ConsistentHash
- Test to see whether a key is mapped to a given address.
- Specified by:
isKeyLocalToAddress in interface ConsistentHash- Overrides:
isKeyLocalToAddress in class AbstractConsistentHash
- Parameters:
target - address to testkey - key to testreplCount - repl count
- Returns:
- true if the key is mapped to the address; false otherwise
getLog
protected Log getLog()
- Overrides:
getLog in class AbstractWheelConsistentHash
Copyright © 2012 JBoss, a division of Red Hat. All Rights Reserved.