public interface Affinity<K>
Cache.affinity()
method.
Mapping of a key to a node is a three-step operation. First step will get an affinity key for given key
using AffinityKeyMapper
. If mapper is not specified, the original key will be used. Second step
will map affinity key to partition using AffinityFunction.partition(Object)
method. Third step
will map obtained partition to nodes for current grid topology version.
Interface provides various 'mapKeysToNodes(..)'
methods which provide node affinity mapping for
given keys. All 'mapKeysToNodes(..)'
methods are not transactional and will not enlist
keys into ongoing transaction.
Modifier and Type | Method and Description |
---|---|
Object |
affinityKey(K key)
Maps passed in key to a key which will be used for node affinity.
|
int[] |
allPartitions(ClusterNode n)
Gets partition ids for which given cluster node has any ownership
(either primary or backup).
|
int[] |
backupPartitions(ClusterNode n)
Gets partition ids for which given cluster node has backup ownership.
|
boolean |
isBackup(ClusterNode n,
K key)
Returns
true if local node is one of the backup nodes for given key. |
boolean |
isPrimary(ClusterNode n,
K key)
Returns
true if given node is the primary node for given key. |
boolean |
isPrimaryOrBackup(ClusterNode n,
K key)
Returns
true if local node is primary or one of the backup nodes
This method is essentially equivalent to calling
"isPrimary(ClusterNode, Object) || isBackup(ClusterNode, Object) )",
however it is more efficient as it makes both checks at once. |
Map<ClusterNode,Collection<K>> |
mapKeysToNodes(Collection<? extends K> keys)
This method provides ability to detect which keys are mapped to which nodes.
|
ClusterNode |
mapKeyToNode(K key)
This method provides ability to detect to which primary node the given key
is mapped.
|
Collection<ClusterNode> |
mapKeyToPrimaryAndBackups(K key)
Gets primary and backup nodes for the key.
|
Map<Integer,ClusterNode> |
mapPartitionsToNodes(Collection<Integer> parts)
Gets primary nodes for the given partitions.
|
ClusterNode |
mapPartitionToNode(int part)
Gets primary node for the given partition.
|
Collection<ClusterNode> |
mapPartitionToPrimaryAndBackups(int part)
Gets primary and backup nodes for partition.
|
int |
partition(K key)
Gets partition id for the given key.
|
int |
partitions()
Gets number of partitions in cache according to configured affinity function.
|
int[] |
primaryPartitions(ClusterNode n)
Gets partition ids for which the given cluster node has primary ownership.
|
int partitions()
AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
int partition(K key)
key
- Key to get partition id for.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
boolean isPrimary(ClusterNode n, K key)
true
if given node is the primary node for given key.n
- Node to check.key
- Key to check.True
if local node is the primary node for given key.boolean isBackup(ClusterNode n, K key)
true
if local node is one of the backup nodes for given key.n
- Node to check.key
- Key to check.True
if local node is one of the backup nodes for given key.boolean isPrimaryOrBackup(ClusterNode n, K key)
true
if local node is primary or one of the backup nodes
This method is essentially equivalent to calling
"isPrimary(ClusterNode, Object)
|| isBackup(ClusterNode, Object)
)",
however it is more efficient as it makes both checks at once.
n
- Node to check.key
- Key to check.True
if local node is primary or backup for given key.int[] primaryPartitions(ClusterNode n)
n
- Cluster node.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
int[] backupPartitions(ClusterNode n)
n
- Cluster node.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
int[] allPartitions(ClusterNode n)
n
- Cluster node.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
Object affinityKey(K key)
AffinityKeyMapped
annotation
or if a custom AffinityKeyMapper
was configured.key
- Key to map.Map<ClusterNode,Collection<K>> mapKeysToNodes(Collection<? extends K> keys)
This method works as following:
AffinityFunction
is
used to determine which keys are mapped to which nodes.
keys
- Keys to map to nodes.@Nullable ClusterNode mapKeyToNode(K key)
This method works as following:
AffinityFunction
is returned.
key
- Keys to map to a node.null
if there are no alive nodes for this cache.Collection<ClusterNode> mapKeyToPrimaryAndBackups(K key)
key
- Key to get affinity nodes for.ClusterNode mapPartitionToNode(int part)
part
- Partition id.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
Map<Integer,ClusterNode> mapPartitionsToNodes(Collection<Integer> parts)
parts
- Partition ids.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
Collection<ClusterNode> mapPartitionToPrimaryAndBackups(int part)
part
- Partition to get affinity nodes for.
Follow @ApacheIgnite
Apache Ignite Fabric : ver. 1.0.0 Release Date : March 31 2015