public interface CacheAffinity<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 CacheAffinityKeyMapper
. If mapper is not specified, the original key will be used. Second step
will map affinity key to partition using CacheAffinityFunction.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 nodes of the given projection has ownership
(either primary or backup).
|
int[] |
backupPartitions(ClusterNode n)
Gets partition ids for which nodes of the given projection 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(org.apache.ignite.cluster.ClusterNode, Object) ||
isBackup(org.apache.ignite.cluster.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 nodes of the given projection has primary
ownership.
|
int partitions()
CacheAffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(CacheAffinityFunction)
int partition(K key)
key
- Key to get partition id for.CacheAffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(CacheAffinityFunction)
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(org.apache.ignite.cluster.ClusterNode, Object)
||
isBackup(org.apache.ignite.cluster.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)
Note that since ClusterNode
implements ClusterGroup
,
to find out primary partitions for a single node just pass
a single node into this method.
This method may return an empty array if none of nodes in the projection have nearOnly disabled.
n
- Grid node.CacheAffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(CacheAffinityFunction)
int[] backupPartitions(ClusterNode n)
first
backup or third
backup by specifying the
'levels
parameter. If no 'level'
is specified then
all backup partitions are returned.
Note that since ClusterNode
implements ClusterGroup
,
to find out backup partitions for a single node, just pass that single
node into this method.
This method may return an empty array if none of nodes in the projection have nearOnly disabled.
n
- Grid node.CacheAffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(CacheAffinityFunction)
int[] allPartitions(ClusterNode n)
Note that since ClusterNode
implements ClusterGroup
,
to find out all partitions for a single node, just pass that single
node into this method.
This method may return an empty array if none of nodes in the projection have nearOnly disabled.
n
- Grid node.CacheAffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(CacheAffinityFunction)
Object affinityKey(K key)
CacheAffinityKeyMapped
annotation
or if a custom CacheAffinityKeyMapper
was configured.key
- Key to map.Map<ClusterNode,Collection<K>> mapKeysToNodes(@Nullable Collection<? extends K> keys)
This method works as following:
CacheAffinityFunction
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:
CacheAffinityFunction
is returned.
key
- Keys to map to a node.null
if there are no alive nodes for this cache.Collection<ClusterNode> mapKeyToPrimaryAndBackups(K key)
If there are only cache nodes in the projection with
CacheConfiguration.getDistributionMode()
property set to NEAR_ONLY
, then this
method will return an empty collection.
key
- Key to get affinity nodes for.CacheConfiguration.getDistributionMode()
property set to NEAR_ONLY
.ClusterNode mapPartitionToNode(int part)
part
- Partition id.CacheAffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(CacheAffinityFunction)
Map<Integer,ClusterNode> mapPartitionsToNodes(Collection<Integer> parts)
parts
- Partition ids.CacheAffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(CacheAffinityFunction)
Collection<ClusterNode> mapPartitionToPrimaryAndBackups(int part)
If there are only cache nodes in the projection with
CacheConfiguration.getDistributionMode()
property set to NEAR_ONLY
, then this
method will return an empty collection.
part
- Partition to get affinity nodes for.CacheConfiguration.getDistributionMode()
property set to NEAR_ONLY
.
Follow @ApacheIgnite
Apache Ignite Fabric : ver. 1.0.0-RC1 Release Date : February 16 2015