Apache Ignite.NET
Apache.Ignite.Core.Cache.ICacheAffinity Interface Reference

Provides affinity information to detect which node is primary and which nodes are backups for a partitioned cache. You can get an instance of this interface by calling IIgnite.GetAffinity method. More...

Public Member Functions

int GetPartition< TK > (TK key)
 Gets partition id for the given key. More...
 
bool IsPrimary< TK > (IClusterNode n, TK key)
 Returns 'true' if given node is the primary node for given key. More...
 
bool IsBackup< TK > (IClusterNode n, TK key)
 Returns 'true' if given node is the backup node for given key. More...
 
bool IsPrimaryOrBackup< TK > (IClusterNode n, TK key)
 Returns 'true' if given node is either primary or backup node for given key. More...
 
int[] GetPrimaryPartitions (IClusterNode n)
 Gets partition ids for which nodes of the given projection has primary ownership. More...
 
int[] GetBackupPartitions (IClusterNode n)
 Gets partition ids for which nodes of the given projection has backup ownership. More...
 
int[] GetAllPartitions (IClusterNode n)
 Gets partition ids for which nodes of the given projection has ownership (either primary or backup). More...
 
TR GetAffinityKey< TK, TR > (TK key)
 Maps passed in key to a key which will be used for node affinity. More...
 
IDictionary< IClusterNode, IList< TK > > MapKeysToNodes< TK > (IEnumerable< TK > 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. More...
 
IClusterNode MapKeyToNode< TK > (TK 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. More...
 
IList< IClusterNodeMapKeyToPrimaryAndBackups< TK > (TK key)
 Gets primary and backup nodes for the key. Note that primary node is always first in the returned collection. More...
 
IClusterNode MapPartitionToNode (int part)
 Gets primary node for the given partition. More...
 
IDictionary< int, IClusterNodeMapPartitionsToNodes (IEnumerable< int > parts)
 Gets primary nodes for the given partitions. More...
 
IList< IClusterNodeMapPartitionToPrimaryAndBackups (int part)
 Gets primary and backup nodes for partition. Note that primary node is always first in the returned collection. More...
 

Properties

int Partitions [get]
 Gets number of partitions in cache according to configured affinity function. More...
 

Detailed Description

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.

All members are thread-safe and may be used concurrently from multiple threads.

Member Function Documentation

TR Apache.Ignite.Core.Cache.ICacheAffinity.GetAffinityKey< TK, TR > ( TK  key)
Parameters
keyKey to map.
Returns
Key to be used for node-to-affinity mapping (may be the same key as passed in).
int [] Apache.Ignite.Core.Cache.ICacheAffinity.GetAllPartitions ( IClusterNode  n)
Parameters
nNode.
Returns
Partition ids for which given projection has ownership.
int [] Apache.Ignite.Core.Cache.ICacheAffinity.GetBackupPartitions ( IClusterNode  n)
Parameters
nNode.
Returns
Partition ids for which given projection has backup ownership.
int Apache.Ignite.Core.Cache.ICacheAffinity.GetPartition< TK > ( TK  key)
Parameters
keyKey to get partition id for.
Returns
Partition id.
int [] Apache.Ignite.Core.Cache.ICacheAffinity.GetPrimaryPartitions ( IClusterNode  n)
Parameters
nNode.
Returns
Partition ids for which given projection has primary ownership.
bool Apache.Ignite.Core.Cache.ICacheAffinity.IsBackup< TK > ( IClusterNode  n,
TK  key 
)
Parameters
nNode.
keyKey.
Returns
'True' if given node is the backup node for given key.
bool Apache.Ignite.Core.Cache.ICacheAffinity.IsPrimary< TK > ( IClusterNode  n,
TK  key 
)
Parameters
nNode.
keyKey.
Returns
'True' if given node is the primary node for given key.
bool Apache.Ignite.Core.Cache.ICacheAffinity.IsPrimaryOrBackup< TK > ( IClusterNode  n,
TK  key 
)
Parameters
nNode.
keyKey.
Returns
'True' if given node is either primary or backup node for given key.
IDictionary<IClusterNode, IList<TK> > Apache.Ignite.Core.Cache.ICacheAffinity.MapKeysToNodes< TK > ( IEnumerable< TK >  keys)
Parameters
keysKeys to map to nodes.
Returns
Map of nodes to keys or empty map if there are no alive nodes for this cache.
IClusterNode Apache.Ignite.Core.Cache.ICacheAffinity.MapKeyToNode< TK > ( TK  key)
Parameters
keyKeys to map to a node.
Returns
Primary node for the key or null if there are no alive nodes for this cache.
IList<IClusterNode> Apache.Ignite.Core.Cache.ICacheAffinity.MapKeyToPrimaryAndBackups< TK > ( TK  key)
Parameters
key
Returns
IDictionary<int, IClusterNode> Apache.Ignite.Core.Cache.ICacheAffinity.MapPartitionsToNodes ( IEnumerable< int >  parts)
Parameters
partsPartition ids.
Returns
Mapping of given partitions to their primary nodes.
IClusterNode Apache.Ignite.Core.Cache.ICacheAffinity.MapPartitionToNode ( int  part)
Parameters
partPartition id.
Returns
Primary node for the given partition.
IList<IClusterNode> Apache.Ignite.Core.Cache.ICacheAffinity.MapPartitionToPrimaryAndBackups ( int  part)
Parameters
partPartition to get affinity nodes for.
Returns
Collection of primary and backup nodes for partition with primary node always first

Property Documentation

int Apache.Ignite.Core.Cache.ICacheAffinity.Partitions
get
Returns
Number of cache partitions.