public interface Affinity<K>
Ignite.affinity(cacheName)
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()
IgniteException
- If there are no alive nodes for this cache.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
int partition(K key)
key
- Key to get partition id for.IgniteException
- If there are no alive nodes for this cache.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.IgniteException
- If there are no alive nodes for this cache.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.IgniteException
- If there are no alive nodes for this cache.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.IgniteException
- If there are no alive nodes for this cache.int[] primaryPartitions(ClusterNode n)
n
- Cluster node.IgniteException
- If there are no alive nodes for this cache.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
int[] backupPartitions(ClusterNode n)
n
- Cluster node.IgniteException
- If there are no alive nodes for this cache.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
int[] allPartitions(ClusterNode n)
n
- Cluster node.IgniteException
- If there are no alive nodes for this cache.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
Object affinityKey(K key)
AffinityKeyMapped
annotation
or if a custom AffinityKeyMapper
was configured.key
- Key to map.IgniteException
- If there are no alive nodes for this cache.Map<ClusterNode,Collection<K>> mapKeysToNodes(Collection<? extends K> keys)
This method works as following:
keys
- Keys to map to nodes.IgniteException
- If there are no alive nodes for this cache.ClusterNode mapKeyToNode(K key)
This method works as following:
key
- Keys to map to a node.IgniteException
- If there are no alive nodes for this cache.NullPointerException
- if key
is null
.Collection<ClusterNode> mapKeyToPrimaryAndBackups(K key)
key
- Key to get affinity nodes for.IgniteException
- If there are no alive nodes for this cache.ClusterNode mapPartitionToNode(int part)
part
- Partition id.IgniteException
- If there are no alive nodes for this cache.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
Map<Integer,ClusterNode> mapPartitionsToNodes(Collection<Integer> parts)
parts
- Partition ids.IgniteException
- If there are no alive nodes for this cache.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
Collection<ClusterNode> mapPartitionToPrimaryAndBackups(int part)
part
- Partition to get affinity nodes for.IgniteException
- If there are no alive nodes for this cache.
GridGain In-Memory Computing Platform : ver. 8.9.15 Release Date : December 3 2024