Apache Ignite C++
Public Member Functions | List of all members
ignite::cache::CacheAffinity< K > Class Template Reference

Provides affinity information to detect which node is primary and which nodes are backups for a partitioned or replicated cache. More...

#include <cache_affinity.h>

Public Member Functions

 CacheAffinity (impl::cache::SP_CacheAffinityImpl impl)
 Constructor. More...
 
int32_t GetPartitions ()
 Get number of partitions in cache according to configured affinity function. More...
 
int32_t GetPartition (const K &key)
 Get partition id for the given key. More...
 
bool IsPrimary (cluster::ClusterNode node, const K &key)
 Return true if given node is the primary node for given key. More...
 
bool IsBackup (cluster::ClusterNode node, const K &key)
 Return true if local node is one of the backup nodes for given key. More...
 
bool IsPrimaryOrBackup (cluster::ClusterNode node, const K &key)
 Returns true if local node is primary or one of the backup nodes. More...
 
std::vector< int32_t > GetPrimaryPartitions (cluster::ClusterNode node)
 Get partition ids for which the given cluster node has primary ownership. More...
 
std::vector< int32_t > GetBackupPartitions (cluster::ClusterNode node)
 Get partition ids for which given cluster node has backup ownership. More...
 
std::vector< int32_t > GetAllPartitions (cluster::ClusterNode node)
 Get partition ids for which given cluster node has any ownership (either primary or backup). More...
 
template<typename TR >
TR GetAffinityKey (const K &key)
 Map passed in key to a key which will be used for node affinity. More...
 
std::map< cluster::ClusterNode, std::vector< K > > MapKeysToNodes (const std::vector< K > &keys)
 This method provides ability to detect which keys are mapped to which nodes. More...
 
cluster::ClusterNode MapKeyToNode (const K &key)
 This method provides ability to detect to which primary node the given key is mapped. More...
 
std::vector< cluster::ClusterNodeMapKeyToPrimaryAndBackups (const K &key)
 Get primary and backup nodes for the key. More...
 
cluster::ClusterNode MapPartitionToNode (int32_t part)
 Get primary node for the given partition. More...
 
std::map< int32_t, cluster::ClusterNodeMapPartitionsToNodes (const std::vector< int32_t > &parts)
 Get primary nodes for the given partitions. More...
 
std::vector< cluster::ClusterNodeMapPartitionToPrimaryAndBackups (int32_t part)
 Get primary and backup nodes for partition. More...
 

Detailed Description

template<typename K>
class ignite::cache::CacheAffinity< K >

Provides affinity information to detect which node is primary and which nodes are backups for a partitioned or replicated cache.

You can get an instance of this interface by calling Ignite.GetAffinity(cacheName) method.

Template Parameters
KCache affinity key type.

Constructor & Destructor Documentation

◆ CacheAffinity()

template<typename K >
ignite::cache::CacheAffinity< K >::CacheAffinity ( impl::cache::SP_CacheAffinityImpl  impl)
inline

Constructor.

Parameters
implPointer to cache affinity implementation.

Member Function Documentation

◆ GetAffinityKey()

template<typename K >
template<typename TR >
TR ignite::cache::CacheAffinity< K >::GetAffinityKey ( const K &  key)
inline

Map passed in key to a key which will be used for node affinity.

Template Parameters
TRKey to be used for node-to-affinity mapping type.
Parameters
keyKey to map.
Returns
Key to be used for node-to-affinity mapping (may be the same key as passed in).

◆ GetAllPartitions()

template<typename K >
std::vector<int32_t> ignite::cache::CacheAffinity< K >::GetAllPartitions ( cluster::ClusterNode  node)
inline

Get partition ids for which given cluster node has any ownership (either primary or backup).

Parameters
nodeCluster node.
Returns
Container of partition ids for which given cluster node has any ownership (either primary or backup).

◆ GetBackupPartitions()

template<typename K >
std::vector<int32_t> ignite::cache::CacheAffinity< K >::GetBackupPartitions ( cluster::ClusterNode  node)
inline

Get partition ids for which given cluster node has backup ownership.

Parameters
nodeCluster node.
Returns
Container of partition ids for which given cluster node has backup ownership.

◆ GetPartition()

template<typename K >
int32_t ignite::cache::CacheAffinity< K >::GetPartition ( const K &  key)
inline

Get partition id for the given key.

Parameters
keyKey to get partition id for.
Returns
Partition id.

◆ GetPartitions()

template<typename K >
int32_t ignite::cache::CacheAffinity< K >::GetPartitions ( )
inline

Get number of partitions in cache according to configured affinity function.

Returns
Number of partitions.

◆ GetPrimaryPartitions()

template<typename K >
std::vector<int32_t> ignite::cache::CacheAffinity< K >::GetPrimaryPartitions ( cluster::ClusterNode  node)
inline

Get partition ids for which the given cluster node has primary ownership.

Parameters
nodeCluster node.
Returns
Container of partition ids for which the given cluster node has primary ownership.

◆ IsBackup()

template<typename K >
bool ignite::cache::CacheAffinity< K >::IsBackup ( cluster::ClusterNode  node,
const K &  key 
)
inline

Return true if local node is one of the backup nodes for given key.

Parameters
nodeCluster node.
keyKey to check.
Returns
True if local node is one of the backup nodes for given key.

◆ IsPrimary()

template<typename K >
bool ignite::cache::CacheAffinity< K >::IsPrimary ( cluster::ClusterNode  node,
const K &  key 
)
inline

Return true if given node is the primary node for given key.

Parameters
nodeCluster node.
keyKey to check.
Returns
True if given node is primary node for given key.

◆ IsPrimaryOrBackup()

template<typename K >
bool ignite::cache::CacheAffinity< K >::IsPrimaryOrBackup ( cluster::ClusterNode  node,
const K &  key 
)
inline

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.

Parameters
nodeCluster node.
keyKey to check.
Returns
True if local node is primary or one of the backup nodes.

◆ MapKeysToNodes()

template<typename K >
std::map<cluster::ClusterNode, std::vector<K> > ignite::cache::CacheAffinity< K >::MapKeysToNodes ( const std::vector< K > &  keys)
inline

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.

Parameters
keysKeys to map to nodes.
Returns
Map of nodes to keys or empty map if there are no alive nodes for this cache.

◆ MapKeyToNode()

template<typename K >
cluster::ClusterNode ignite::cache::CacheAffinity< K >::MapKeyToNode ( const K &  key)
inline

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.

Parameters
keyKey to map to node.
Returns
Primary node for the key.

◆ MapKeyToPrimaryAndBackups()

template<typename K >
std::vector<cluster::ClusterNode> ignite::cache::CacheAffinity< K >::MapKeyToPrimaryAndBackups ( const K &  key)
inline

Get primary and backup nodes for the key.

Note that primary node is always first in the returned collection.

Parameters
keyKey to map to nodes.
Returns
Collection of cluster nodes.

◆ MapPartitionsToNodes()

template<typename K >
std::map<int32_t, cluster::ClusterNode> ignite::cache::CacheAffinity< K >::MapPartitionsToNodes ( const std::vector< int32_t > &  parts)
inline

Get primary nodes for the given partitions.

Parameters
partsPartition ids.
Returns
Mapping of given partitions to their primary nodes.

◆ MapPartitionToNode()

template<typename K >
cluster::ClusterNode ignite::cache::CacheAffinity< K >::MapPartitionToNode ( int32_t  part)
inline

Get primary node for the given partition.

Parameters
partPartition id.
Returns
Primary node for the given partition.

◆ MapPartitionToPrimaryAndBackups()

template<typename K >
std::vector<cluster::ClusterNode> ignite::cache::CacheAffinity< K >::MapPartitionToPrimaryAndBackups ( int32_t  part)
inline

Get primary and backup nodes for partition.

Note that primary node is always first in the returned collection.

Parameters
partPartition to get affinity nodes for.
Returns
Collection of primary and backup nodes for partition with primary node always first.

The documentation for this class was generated from the following file: