GridGain C++
cache_affinity.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 GridGain Systems, Inc. and Contributors.
3  *
4  * Licensed under the GridGain Community Edition License (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
22 #ifndef _IGNITE_CACHE_AFFINITY
23 #define _IGNITE_CACHE_AFFINITY
24 
26 
27 #include <ignite/impl/cache/cache_affinity_impl.h>
28 
29 namespace ignite
30 {
31  namespace cache
32  {
40  template<typename K>
41  class IGNITE_IMPORT_EXPORT CacheAffinity
42  {
43  public:
49  CacheAffinity(impl::cache::SP_CacheAffinityImpl impl) :
50  impl(impl)
51  {
52  // No-op.
53  }
54 
60  int32_t GetPartitions()
61  {
62  return impl.Get()->GetPartitions();
63  }
64 
71  int32_t GetPartition(const K& key)
72  {
73  return impl.Get()->GetPartition(key);
74  }
75 
83  bool IsPrimary(cluster::ClusterNode node, const K& key)
84  {
85  return impl.Get()->IsPrimary(node, key);
86  }
87 
95  bool IsBackup(cluster::ClusterNode node, const K& key)
96  {
97  return impl.Get()->IsBackup(node, key);
98  }
99 
110  bool IsPrimaryOrBackup(cluster::ClusterNode node, const K& key)
111  {
112  return impl.Get()->IsPrimaryOrBackup(node, key);
113  }
114 
121  std::vector<int32_t> GetPrimaryPartitions(cluster::ClusterNode node)
122  {
123  return impl.Get()->GetPrimaryPartitions(node);
124  }
125 
132  std::vector<int32_t> GetBackupPartitions(cluster::ClusterNode node)
133  {
134  return impl.Get()->GetBackupPartitions(node);
135  }
136 
143  std::vector<int32_t> GetAllPartitions(cluster::ClusterNode node)
144  {
145  return impl.Get()->GetAllPartitions(node);
146  }
147 
156  template <typename TR>
157  TR GetAffinityKey(const K& key)
158  {
159  return impl.Get()->template GetAffinityKey<K, TR>(key);
160  }
161 
170  std::map<cluster::ClusterNode, std::vector<K> > MapKeysToNodes(const std::vector<K>& keys)
171  {
172  return impl.Get()->MapKeysToNodes(keys);
173  }
174 
184  {
185  return impl.Get()->MapKeyToNode(key);
186  }
187 
195  std::vector<cluster::ClusterNode> MapKeyToPrimaryAndBackups(const K& key)
196  {
197  return impl.Get()->MapKeyToPrimaryAndBackups(key);
198  }
199 
207  {
208  return impl.Get()->MapPartitionToNode(part);
209  }
210 
217  std::map<int32_t, cluster::ClusterNode> MapPartitionsToNodes(const std::vector<int32_t>& parts)
218  {
219  return impl.Get()->MapPartitionsToNodes(parts);
220  }
221 
229  std::vector<cluster::ClusterNode> MapPartitionToPrimaryAndBackups(int32_t part)
230  {
231  return impl.Get()->MapPartitionToPrimaryAndBackups(part);
232  }
233 
234  private:
235  impl::cache::SP_CacheAffinityImpl impl;
236  };
237  }
238 }
239 
240 #endif //_IGNITE_CACHE_AFFINITY
ignite::cache::CacheAffinity::IsBackup
bool IsBackup(cluster::ClusterNode node, const K &key)
Return true if local node is one of the backup nodes for given key.
Definition: cache_affinity.h:95
ignite
Ignite API.
Definition: cache.h:47
ignite::cache::CacheAffinity::GetAllPartitions
std::vector< int32_t > GetAllPartitions(cluster::ClusterNode node)
Get partition ids for which given cluster node has any ownership (either primary or backup).
Definition: cache_affinity.h:143
ignite::cache::CacheAffinity::IsPrimary
bool IsPrimary(cluster::ClusterNode node, const K &key)
Return true if given node is the primary node for given key.
Definition: cache_affinity.h:83
ignite::cache::CacheAffinity::GetPrimaryPartitions
std::vector< int32_t > GetPrimaryPartitions(cluster::ClusterNode node)
Get partition ids for which the given cluster node has primary ownership.
Definition: cache_affinity.h:121
ignite::cache::CacheAffinity::MapKeyToPrimaryAndBackups
std::vector< cluster::ClusterNode > MapKeyToPrimaryAndBackups(const K &key)
Get primary and backup nodes for the key.
Definition: cache_affinity.h:195
ignite::cache::CacheAffinity::GetPartition
int32_t GetPartition(const K &key)
Get partition id for the given key.
Definition: cache_affinity.h:71
cluster_group.h
ignite::cache::CacheAffinity::GetBackupPartitions
std::vector< int32_t > GetBackupPartitions(cluster::ClusterNode node)
Get partition ids for which given cluster node has backup ownership.
Definition: cache_affinity.h:132
ignite::cache::CacheAffinity::MapPartitionToPrimaryAndBackups
std::vector< cluster::ClusterNode > MapPartitionToPrimaryAndBackups(int32_t part)
Get primary and backup nodes for partition.
Definition: cache_affinity.h:229
ignite::cache::CacheAffinity::GetPartitions
int32_t GetPartitions()
Get number of partitions in cache according to configured affinity function.
Definition: cache_affinity.h:60
ignite::cache::CacheAffinity::MapKeysToNodes
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.
Definition: cache_affinity.h:170
ignite::cache::CacheAffinity
Provides affinity information to detect which node is primary and which nodes are backups for a parti...
Definition: cache_affinity.h:41
ignite::cache::CacheAffinity::MapPartitionToNode
cluster::ClusterNode MapPartitionToNode(int32_t part)
Get primary node for the given partition.
Definition: cache_affinity.h:206
ignite::cache::CacheAffinity::GetAffinityKey
TR GetAffinityKey(const K &key)
Map passed in key to a key which will be used for node affinity.
Definition: cache_affinity.h:157
ignite::cache::CacheAffinity::IsPrimaryOrBackup
bool IsPrimaryOrBackup(cluster::ClusterNode node, const K &key)
Returns true if local node is primary or one of the backup nodes.
Definition: cache_affinity.h:110
ignite::cache::CacheAffinity::CacheAffinity
CacheAffinity(impl::cache::SP_CacheAffinityImpl impl)
Constructor.
Definition: cache_affinity.h:49
ignite::cache::CacheAffinity::MapPartitionsToNodes
std::map< int32_t, cluster::ClusterNode > MapPartitionsToNodes(const std::vector< int32_t > &parts)
Get primary nodes for the given partitions.
Definition: cache_affinity.h:217
ignite::cluster::ClusterNode
Interface representing a single cluster node.
Definition: cluster_node.h:35
ignite::cache::CacheAffinity::MapKeyToNode
cluster::ClusterNode MapKeyToNode(const K &key)
This method provides ability to detect to which primary node the given key is mapped.
Definition: cache_affinity.h:183