Class GridCacheAffinityImpl<K,V>
- java.lang.Object
-
- org.apache.ignite.internal.processors.cache.affinity.GridCacheAffinityImpl<K,V>
-
-
Field Summary
Fields Modifier and Type Field Description static StringFAILED_TO_FIND_CACHE_ERR_MSG
-
Constructor Summary
Constructors Constructor Description GridCacheAffinityImpl(GridCacheContext<K,V> cctx)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectaffinityKey(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.booleanisBackup(ClusterNode n, K key)Returnstrueif local node is one of the backup nodes for given key.booleanisPrimary(ClusterNode n, K key)Returnstrueif given node is the primary node for given key.booleanisPrimaryOrBackup(ClusterNode n, K key)Returnstrueif local node is primary or one of the backup nodesMap<ClusterNode,Collection<K>>mapKeysToNodes(@Nullable Collection<? extends K> keys)This method provides ability to detect which keys are mapped to which nodes.@Nullable ClusterNodemapKeyToNode(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.ClusterNodemapPartitionToNode(int part)Gets primary node for the given partition.Collection<ClusterNode>mapPartitionToPrimaryAndBackups(int part)Gets primary and backup nodes for partition.intpartition(K key)Gets partition id for the given key.intpartitions()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.
-
-
-
Field Detail
-
FAILED_TO_FIND_CACHE_ERR_MSG
public static final String FAILED_TO_FIND_CACHE_ERR_MSG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GridCacheAffinityImpl
public GridCacheAffinityImpl(GridCacheContext<K,V> cctx)
- Parameters:
cctx- Context.
-
-
Method Detail
-
partitions
public int partitions()
Gets number of partitions in cache according to configured affinity function.- Specified by:
partitionsin interfaceAffinity<K>- Returns:
- Number of cache partitions.
- See Also:
AffinityFunction,CacheConfiguration.getAffinity(),CacheConfiguration.setAffinity(AffinityFunction)
-
partition
public int partition(K key)
Gets partition id for the given key.- Specified by:
partitionin interfaceAffinity<K>- Parameters:
key- Key to get partition id for.- Returns:
- Partition id.
- See Also:
AffinityFunction,CacheConfiguration.getAffinity(),CacheConfiguration.setAffinity(AffinityFunction)
-
isPrimary
public boolean isPrimary(ClusterNode n, K key)
Returnstrueif given node is the primary node for given key.
-
isBackup
public boolean isBackup(ClusterNode n, K key)
Returnstrueif local node is one of the backup nodes for given key.
-
isPrimaryOrBackup
public boolean isPrimaryOrBackup(ClusterNode n, K key)
Returnstrueif local node is primary or one of the backup nodesThis method is essentially equivalent to calling "
Affinity.isPrimary(ClusterNode, Object)||Affinity.isBackup(ClusterNode, Object))", however it is more efficient as it makes both checks at once.- Specified by:
isPrimaryOrBackupin interfaceAffinity<K>- Parameters:
n- Node to check.key- Key to check.- Returns:
Trueif local node is primary or backup for given key.
-
primaryPartitions
public int[] primaryPartitions(ClusterNode n)
Gets partition ids for which the given cluster node has primary ownership.- Specified by:
primaryPartitionsin interfaceAffinity<K>- Parameters:
n- Cluster node.- Returns:
- Partition ids for which given cluster node has primary ownership.
- See Also:
AffinityFunction,CacheConfiguration.getAffinity(),CacheConfiguration.setAffinity(AffinityFunction)
-
backupPartitions
public int[] backupPartitions(ClusterNode n)
Gets partition ids for which given cluster node has backup ownership.- Specified by:
backupPartitionsin interfaceAffinity<K>- Parameters:
n- Cluster node.- Returns:
- Partition ids for which given cluster node has backup ownership.
- See Also:
AffinityFunction,CacheConfiguration.getAffinity(),CacheConfiguration.setAffinity(AffinityFunction)
-
allPartitions
public int[] allPartitions(ClusterNode n)
Gets partition ids for which given cluster node has any ownership (either primary or backup).- Specified by:
allPartitionsin interfaceAffinity<K>- Parameters:
n- Cluster node.- Returns:
- Partition ids for which given cluster node has any ownership, primary or backup.
- See Also:
AffinityFunction,CacheConfiguration.getAffinity(),CacheConfiguration.setAffinity(AffinityFunction)
-
mapPartitionToNode
public ClusterNode mapPartitionToNode(int part)
Gets primary node for the given partition.- Specified by:
mapPartitionToNodein interfaceAffinity<K>- Parameters:
part- Partition id.- Returns:
- Primary node for the given partition.
- See Also:
AffinityFunction,CacheConfiguration.getAffinity(),CacheConfiguration.setAffinity(AffinityFunction)
-
mapPartitionsToNodes
public Map<Integer,ClusterNode> mapPartitionsToNodes(Collection<Integer> parts)
Gets primary nodes for the given partitions.- Specified by:
mapPartitionsToNodesin interfaceAffinity<K>- Parameters:
parts- Partition ids.- Returns:
- Mapping of given partitions to their primary nodes.
- See Also:
AffinityFunction,CacheConfiguration.getAffinity(),CacheConfiguration.setAffinity(AffinityFunction)
-
affinityKey
public Object affinityKey(K key)
Maps passed in key to a key which will be used for node affinity. The affinity key may be different from actual key if some field in the actual key was designated for affinity mapping viaAffinityKeyMappedannotation or if a customAffinityKeyMapperwas configured.- Specified by:
affinityKeyin interfaceAffinity<K>- Parameters:
key- Key to map.- Returns:
- Key to be used for node-to-affinity mapping (may be the same key as passed in).
-
mapKeyToNode
@Nullable public @Nullable ClusterNode mapKeyToNode(K key)
This method provides ability to detect to which primary node the given key is mapped. Use it to determine which nodes are storing which keys prior to sending jobs that access these keys.This method works as following:
- For local caches it returns only local node ID.
- For other caches, primary node for the given key is returned.
- Specified by:
mapKeyToNodein interfaceAffinity<K>- Parameters:
key- Keys to map to a node.- Returns:
- Primary node for the key.
-
mapKeysToNodes
public Map<ClusterNode,Collection<K>> mapKeysToNodes(@Nullable @Nullable Collection<? extends K> keys)
This method provides ability to detect which keys are mapped to which nodes. Use it to determine which nodes are storing which keys prior to sending jobs that access these keys.This method works as following:
- For local caches it returns only local node mapped to all keys.
- For other caches, the returned map represents node-to-key affinity.
- Specified by:
mapKeysToNodesin interfaceAffinity<K>- Parameters:
keys- Keys to map to nodes.- Returns:
- Map of nodes to keys.
-
mapKeyToPrimaryAndBackups
public Collection<ClusterNode> mapKeyToPrimaryAndBackups(K key)
Gets primary and backup nodes for the key. Note that primary node is always first in the returned collection.- Specified by:
mapKeyToPrimaryAndBackupsin interfaceAffinity<K>- Parameters:
key- Key to get affinity nodes for.- Returns:
- Collection of primary and backup nodes for the key with primary node always first.
-
mapPartitionToPrimaryAndBackups
public Collection<ClusterNode> mapPartitionToPrimaryAndBackups(int part)
Gets primary and backup nodes for partition. Note that primary node is always first in the returned collection.- Specified by:
mapPartitionToPrimaryAndBackupsin interfaceAffinity<K>- Parameters:
part- Partition to get affinity nodes for.- Returns:
- Collection of primary and backup nodes for partition with primary node always first.
-
-