|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.infinispan.distribution.ch.AbstractConsistentHash
org.infinispan.distribution.ch.AbstractWheelConsistentHash
public abstract class AbstractWheelConsistentHash
Abstract class for the wheel-based CH implementations.
This base class supports consistent hashses which wish to enable virtual nodes. To do this
the implementation should override isVirtualNodesEnabled()
and return true when
virtual nodes should be enabled (we recommend at least that numVirtualNodes
should be
> 1 for virtual nodes to be enabled!). It is assumed that implementations of a consistent hash
in which virtual nodes are enabled will take responsibility for ensuring that the fact virtual
nodes are in use does not escape the consistent hash implementation.
The only consistent hash in Inifinispan to provide virtual node support is the topology aware consistent hash,
In order to do this, the
implementation can use getRealAddress(Address)
and
getRealAddresses(Set)
to convert the virtual addresses obtained from positions
,
addressToHashIds
and AbstractConsistentHash.caches
to real addresses. In particular an
implementation should ensure that ConsistentHash.locate(Object, int)
, ConsistentHash.getStateProvidersOnLeave(Address, int)
and ConsistentHash.getStateProvidersOnJoin(Address, int)
do not return virtual addresses (as implementations of
these methods are not provided by this abstract super class). The behavior of Infinispan if
virtual addresses leak from the consistent hash implementation is not tested.
Nested Class Summary | |
---|---|
static class |
AbstractWheelConsistentHash.Externalizer<T extends AbstractWheelConsistentHash>
|
Field Summary | |
---|---|
protected Map<Address,Integer> |
addressToHashIds
|
protected Hash |
hashFunction
|
protected Log |
log
|
protected int |
numVirtualNodes
|
protected SortedMap<Integer,Address> |
positions
|
protected boolean |
trace
|
Fields inherited from class org.infinispan.distribution.ch.AbstractConsistentHash |
---|
caches, groupManager |
Constructor Summary | |
---|---|
protected |
AbstractWheelConsistentHash()
|
Method Summary | |
---|---|
protected void |
addNode(Address a)
|
protected Address |
createVirtualAddress(Address realAddress,
int id)
Default implementation that creates a VirtualAddress from an Address . |
List<Address> |
getBackupsForNode(Address node,
int replCount)
Returns the nodes that backup data for the supplied node including the node itself. |
Set<Address> |
getCaches()
Should return a collection of cache addresses in the cluster. |
int |
getHashId(Address a)
Returns the value between 0 and the hash space limit, or hash id, for a particular address. |
int |
getHashSpace()
Returns the hash space constant for this consistent hash algorithm class. |
int |
getNormalizedHash(Object key)
|
protected Address |
getRealAddress(Address a)
|
protected Set<Address> |
getRealAddresses(Set<Address> virtualAddresses)
|
protected boolean |
isVirtualNodesEnabled()
|
void |
setCaches(Set<Address> newCaches)
Sets the collection of cache addresses in the cluster. |
void |
setHashFunction(Hash h)
|
void |
setNumVirtualNodes(Integer numVirtualNodes)
|
String |
toString()
|
Methods inherited from class org.infinispan.distribution.ch.AbstractConsistentHash |
---|
getGrouping, isKeyLocalToAddress, locateAll, setGroupManager |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.infinispan.distribution.ch.ConsistentHash |
---|
getStateProvidersOnJoin, getStateProvidersOnLeave, locate |
Field Detail |
---|
protected final Log log
protected final boolean trace
protected SortedMap<Integer,Address> positions
protected Map<Address,Integer> addressToHashIds
protected Hash hashFunction
protected int numVirtualNodes
Constructor Detail |
---|
protected AbstractWheelConsistentHash()
Method Detail |
---|
public void setHashFunction(Hash h)
public void setNumVirtualNodes(Integer numVirtualNodes)
public void setCaches(Set<Address> newCaches)
ConsistentHash
setCaches
in interface ConsistentHash
setCaches
in class AbstractConsistentHash
newCaches
- A set of unique caches in cluster.protected Address createVirtualAddress(Address realAddress, int id)
VirtualAddress
from an Address
.
public Set<Address> getCaches()
ConsistentHash
getCaches
in interface ConsistentHash
getCaches
in class AbstractConsistentHash
protected void addNode(Address a)
protected Address getRealAddress(Address a)
protected Set<Address> getRealAddresses(Set<Address> virtualAddresses)
public List<Address> getBackupsForNode(Address node, int replCount)
ConsistentHash
public int getHashSpace()
ConsistentHash
public int getHashId(Address a)
ConsistentHash
public int getNormalizedHash(Object key)
public String toString()
toString
in class AbstractConsistentHash
protected boolean isVirtualNodesEnabled()
|
--> | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |