org.infinispan.distribution.ch
Class TopologyAwareConsistentHash

java.lang.Object
  extended by org.infinispan.distribution.ch.AbstractConsistentHash
      extended by org.infinispan.distribution.ch.AbstractWheelConsistentHash
          extended by 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

Nested Class Summary
static class TopologyAwareConsistentHash.Externalizer
           
 
Field Summary
 
Fields inherited from class org.infinispan.distribution.ch.AbstractWheelConsistentHash
caches, hashFunction, numVirtualNodes, positionKeys, positionValues, trace
 
Fields inherited from class org.infinispan.distribution.ch.AbstractConsistentHash
groupManager
 
Constructor Summary
TopologyAwareConsistentHash()
           
TopologyAwareConsistentHash(Hash hash)
           
 
Method Summary
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.
 
Methods inherited from class org.infinispan.distribution.ch.AbstractWheelConsistentHash
getCaches, getHashIds, getNormalizedHash, getPositionIndex, getPositionsIterator, isVirtualNodesEnabled, primaryLocation, setHashFunction, setNumVirtualNodes, toString
 
Methods inherited from class org.infinispan.distribution.ch.AbstractConsistentHash
getBackupsForNode, getGrouping, getStateProvidersOnJoin, getStateProvidersOnLeave, locateAll, setGroupManager
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TopologyAwareConsistentHash

public TopologyAwareConsistentHash()

TopologyAwareConsistentHash

public TopologyAwareConsistentHash(Hash hash)
Method Detail

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 locate
replCount - 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 test
key - key to test
replCount - 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.