Package net.spy.memcached
Class KetamaNodeLocator
java.lang.Object
net.spy.memcached.compat.SpyObject
net.spy.memcached.KetamaNodeLocator
- All Implemented Interfaces:
NodeLocator
This is an implementation of the Ketama consistent hash strategy from
last.fm. This implementation may not be compatible with libketama as hashing
is considered separate from node location.
Note that this implementation does not currently supported weighted nodes.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Collection
<MemcachedNode> private final KetamaNodeLocatorConfiguration
private final HashAlgorithm
private final boolean
private TreeMap
<Long, MemcachedNode> private final Map
<InetSocketAddress, Integer> -
Constructor Summary
ConstructorsModifierConstructorDescriptionKetamaNodeLocator
(List<MemcachedNode> nodes, HashAlgorithm alg) Create a new KetamaNodeLocator using specified nodes and the specifed hash algorithm.KetamaNodeLocator
(List<MemcachedNode> nodes, HashAlgorithm alg, Map<InetSocketAddress, Integer> nodeWeights, KetamaNodeLocatorConfiguration configuration) Create a new KetamaNodeLocator with specific nodes, hash, node key format, and weightKetamaNodeLocator
(List<MemcachedNode> nodes, HashAlgorithm alg, KetamaNodeKeyFormatter.Format nodeKeyFormat, Map<InetSocketAddress, Integer> weights) Create a new KetamaNodeLocator with specific nodes, hash, node key format, and weightKetamaNodeLocator
(List<MemcachedNode> nodes, HashAlgorithm alg, KetamaNodeLocatorConfiguration conf) Create a new KetamaNodeLocator using specified nodes and the specifed hash algorithm and configuration.private
KetamaNodeLocator
(TreeMap<Long, MemcachedNode> smn, Collection<MemcachedNode> an, HashAlgorithm alg, Map<InetSocketAddress, Integer> nodeWeights, KetamaNodeLocatorConfiguration conf) -
Method Summary
Modifier and TypeMethodDescriptiongetAll()
Get all memcached nodes.protected TreeMap
<Long, MemcachedNode> (package private) long
(package private) MemcachedNode
getNodeForKey
(long hash) getPrimary
(String k) Get the primary location for the given key.Create a read-only copy of this NodeLocator.Get an iterator over the sequence of nodes that make up the backup locations for a given key.ketamaNodePositionsAtIteration
(MemcachedNode node, int iteration) protected void
setKetamaNodes
(List<MemcachedNode> nodes) Setup the KetamaNodeLocator with the list of nodes it should use.void
updateLocator
(List<MemcachedNode> nodes) Update locator status.
-
Field Details
-
ketamaNodes
-
allNodes
-
hashAlg
-
weights
-
isWeightedKetama
private final boolean isWeightedKetama -
config
-
-
Constructor Details
-
KetamaNodeLocator
Create a new KetamaNodeLocator using specified nodes and the specifed hash algorithm.- Parameters:
nodes
- The List of nodes to use in the Ketama consistent hash continuumalg
- The hash algorithm to use when choosing a node in the Ketama consistent hash continuum
-
KetamaNodeLocator
public KetamaNodeLocator(List<MemcachedNode> nodes, HashAlgorithm alg, KetamaNodeKeyFormatter.Format nodeKeyFormat, Map<InetSocketAddress, Integer> weights) Create a new KetamaNodeLocator with specific nodes, hash, node key format, and weight- Parameters:
nodes
- The List of nodes to use in the Ketama consistent hash continuumalg
- The hash algorithm to use when choosing a node in the Ketama consistent hash continuumnodeKeyFormat
- the format used to name the nodes in Ketama, either SPYMEMCACHED or LIBMEMCACHEDweights
- node weights for ketama, a map from InetSocketAddress to weight as Integer
-
KetamaNodeLocator
public KetamaNodeLocator(List<MemcachedNode> nodes, HashAlgorithm alg, KetamaNodeLocatorConfiguration conf) Create a new KetamaNodeLocator using specified nodes and the specifed hash algorithm and configuration.- Parameters:
nodes
- The List of nodes to use in the Ketama consistent hash continuumalg
- The hash algorithm to use when choosing a node in the Ketama consistent hash continuumconf
-
-
KetamaNodeLocator
public KetamaNodeLocator(List<MemcachedNode> nodes, HashAlgorithm alg, Map<InetSocketAddress, Integer> nodeWeights, KetamaNodeLocatorConfiguration configuration) Create a new KetamaNodeLocator with specific nodes, hash, node key format, and weight- Parameters:
nodes
- The List of nodes to use in the Ketama consistent hash continuumalg
- The hash algorithm to use when choosing a node in the Ketama consistent hash continuumconfiguration
- node locator configurationweights
- node weights for ketama, a map from InetSocketAddress to weight as Integer
-
KetamaNodeLocator
private KetamaNodeLocator(TreeMap<Long, MemcachedNode> smn, Collection<MemcachedNode> an, HashAlgorithm alg, Map<InetSocketAddress, Integer> nodeWeights, KetamaNodeLocatorConfiguration conf)
-
-
Method Details
-
getAll
Description copied from interface:NodeLocator
Get all memcached nodes. This is useful for broadcasting messages.- Specified by:
getAll
in interfaceNodeLocator
-
getPrimary
Description copied from interface:NodeLocator
Get the primary location for the given key.- Specified by:
getPrimary
in interfaceNodeLocator
- Parameters:
k
- the object key- Returns:
- the QueueAttachment containing the primary storage for a key
-
getMaxKey
long getMaxKey() -
getNodeForKey
-
getSequence
Description copied from interface:NodeLocator
Get an iterator over the sequence of nodes that make up the backup locations for a given key.- Specified by:
getSequence
in interfaceNodeLocator
- Parameters:
k
- the object key- Returns:
- the sequence of backup nodes.
-
getReadonlyCopy
Description copied from interface:NodeLocator
Create a read-only copy of this NodeLocator.- Specified by:
getReadonlyCopy
in interfaceNodeLocator
-
updateLocator
Description copied from interface:NodeLocator
Update locator status.- Specified by:
updateLocator
in interfaceNodeLocator
- Parameters:
nodes
- New locator nodes.
-
getKetamaNodes
- Returns:
- the ketamaNodes
-
setKetamaNodes
Setup the KetamaNodeLocator with the list of nodes it should use.- Parameters:
nodes
- a List of MemcachedNodes for this KetamaNodeLocator to use in its continuum
-
ketamaNodePositionsAtIteration
-