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
addressToHashIds, hashFunction, log, positions, trace
 
Fields inherited from class org.infinispan.distribution.ch.AbstractConsistentHash
caches
 
Constructor Summary
TopologyAwareConsistentHash()
           
TopologyAwareConsistentHash(Hash hash)
           
 
Method Summary
 List<Address> getStateProvidersOnJoin(Address joiner, int replCount)
          In this situation are the same nodes providing state on join as the nodes that provide state on leave.
 List<Address> getStateProvidersOnLeave(Address leaver, int replCount)
          Returns the nodes that need will replicate their state if the specified node crashes.
 TopologyInfo getTopologyInfo()
           
 List<Address> locate(Object key, int replCount)
          Locates a key, given a replication count (number of copies).
 void setTopologyInfo(TopologyInfo topologyInfo)
          Sets cluster topology information that can be used by CH to improve fault tolerance by smart choosing of backups.
 String toString()
           
 
Methods inherited from class org.infinispan.distribution.ch.AbstractWheelConsistentHash
getBackupsForNode, getHashId, getHashSpace, getNormalizedHash, setCaches, setHashFunction
 
Methods inherited from class org.infinispan.distribution.ch.AbstractConsistentHash
getCaches, isKeyLocalToAddress, locateAll
 
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

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.

getStateProvidersOnLeave

public List<Address> getStateProvidersOnLeave(Address leaver,
                                              int replCount)
Description copied from interface: ConsistentHash
Returns the nodes that need will replicate their state if the specified node crashes. The return collection should contain all the nodes that backup-ed on leaver and one of the nodes which acted as a backup for the leaver .

Pre: leaver must be present in the caches known to this CH, as returned by ConsistentHash.getCaches()

Parameters:
leaver - the node that leaves the cluster

getStateProvidersOnJoin

public List<Address> getStateProvidersOnJoin(Address joiner,
                                             int replCount)
In this situation are the same nodes providing state on join as the nodes that provide state on leave.


setTopologyInfo

public void setTopologyInfo(TopologyInfo topologyInfo)
Description copied from interface: ConsistentHash
Sets cluster topology information that can be used by CH to improve fault tolerance by smart choosing of backups. More about it here

Specified by:
setTopologyInfo in interface ConsistentHash
Overrides:
setTopologyInfo in class AbstractConsistentHash

getTopologyInfo

public TopologyInfo getTopologyInfo()

toString

public String toString()
Overrides:
toString in class AbstractWheelConsistentHash


Copyright © 2011 JBoss, a division of Red Hat. All Rights Reserved.