| Apache Ignite C++

cache_affinity.h
Go to the documentation of this file.
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
23 #ifndef _IGNITE_CACHE_AFFINITY
24 #define _IGNITE_CACHE_AFFINITY
25
26 #include <ignite/cluster/cluster_group.h>
27
28 #include <ignite/impl/cache/cache_affinity_impl.h>
29
30 namespace ignite
31 {
32 namespace cache
33 {
41 template<typename K>
42 class IGNITE_IMPORT_EXPORT CacheAffinity
43 {
44 public:
50 CacheAffinity(impl::cache::SP_CacheAffinityImpl impl) :
51 impl(impl)
52 {
53 // No-op.
54 }
55
61 int32_t GetPartitions()
62 {
63 return impl.Get()->GetPartitions();
64 }
65
72 int32_t GetPartition(const K& key)
73 {
74 return impl.Get()->GetPartition(key);
75 }
76
84 bool IsPrimary(cluster::ClusterNode node, const K& key)
85 {
86 return impl.Get()->IsPrimary(node, key);
87 }
88
96 bool IsBackup(cluster::ClusterNode node, const K& key)
97 {
98 return impl.Get()->IsBackup(node, key);
99 }
100
111 bool IsPrimaryOrBackup(cluster::ClusterNode node, const K& key)
112 {
113 return impl.Get()->IsPrimaryOrBackup(node, key);
114 }
115
122 std::vector<int32_t> GetPrimaryPartitions(cluster::ClusterNode node)
123 {
124 return impl.Get()->GetPrimaryPartitions(node);
125 }
126
133 std::vector<int32_t> GetBackupPartitions(cluster::ClusterNode node)
134 {
135 return impl.Get()->GetBackupPartitions(node);
136 }
137
144 std::vector<int32_t> GetAllPartitions(cluster::ClusterNode node)
145 {
146 return impl.Get()->GetAllPartitions(node);
147 }
148
157 template <typename TR>
158 TR GetAffinityKey(const K& key)
159 {
160 return impl.Get()->template GetAffinityKey<K, TR>(key);
161 }
162
171 std::map<cluster::ClusterNode, std::vector<K> > MapKeysToNodes(const std::vector<K>& keys)
172 {
173 return impl.Get()->MapKeysToNodes(keys);
174 }
175
184 cluster::ClusterNode MapKeyToNode(const K& key)
185 {
186 return impl.Get()->MapKeyToNode(key);
187 }
188
196 std::vector<cluster::ClusterNode> MapKeyToPrimaryAndBackups(const K& key)
197 {
198 return impl.Get()->MapKeyToPrimaryAndBackups(key);
199 }
200
207 cluster::ClusterNode MapPartitionToNode(int32_t part)
208 {
209 return impl.Get()->MapPartitionToNode(part);
210 }
211
218 std::map<int32_t, cluster::ClusterNode> MapPartitionsToNodes(const std::vector<int32_t>& parts)
219 {
220 return impl.Get()->MapPartitionsToNodes(parts);
221 }
222
230 std::vector<cluster::ClusterNode> MapPartitionToPrimaryAndBackups(int32_t part)
231 {
232 return impl.Get()->MapPartitionToPrimaryAndBackups(part);
233 }
234
235 private:
236 impl::cache::SP_CacheAffinityImpl impl;
237 };
238 }
239 }
240
241 #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:96
ignite
Apache Ignite API.
Definition: cache.h:48
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:144
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:84
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:122
ignite::cache::CacheAffinity::MapKeyToPrimaryAndBackups
std::vector< cluster::ClusterNode > MapKeyToPrimaryAndBackups(const K &key)
Get primary and backup nodes for the key.
Definition: cache_affinity.h:196
ignite::cache::CacheAffinity::GetPartition
int32_t GetPartition(const K &key)
Get partition id for the given key.
Definition: cache_affinity.h:72
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:133
ignite::cache::CacheAffinity::MapPartitionToPrimaryAndBackups
std::vector< cluster::ClusterNode > MapPartitionToPrimaryAndBackups(int32_t part)
Get primary and backup nodes for partition.
Definition: cache_affinity.h:230
ignite::cache::CacheAffinity::GetPartitions
int32_t GetPartitions()
Get number of partitions in cache according to configured affinity function.
Definition: cache_affinity.h:61
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:171
ignite::cache::CacheAffinity
Provides affinity information to detect which node is primary and which nodes are backups for a parti...
Definition: cache_affinity.h:42
ignite::cache::CacheAffinity::MapPartitionToNode
cluster::ClusterNode MapPartitionToNode(int32_t part)
Get primary node for the given partition.
Definition: cache_affinity.h:207
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:158
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:111
ignite::cache::CacheAffinity::CacheAffinity
CacheAffinity(impl::cache::SP_CacheAffinityImpl impl)
Constructor.
Definition: cache_affinity.h:50
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:218
ignite::cluster::ClusterNode
Interface representing a single cluster node.
Definition: cluster_node.h:36
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:184