I am using Apache Ignite 1.8.0 for caching in a cluster. I use the C ++ API and have access to the same cache from Java and C ++. This works fine, but I would also like to use affinity mapping to perform tasks on the same node that cached the data. I create a cache in Java by putting data in C ++, but then I want to run tasks in Java using that data. The C ++ API does not support Affinity support, so now I wonder what my options are.
This is how I create the cache:
final IgniteCache<Integer, ByteArray> cache = ignite.createCache("myCacheBinaryCpp")
Then I put the data from C ++. I have a simple class of byte arrays for testing.
int8_t* byteArr= new int8_t[3]; byteArr[0] = 0; byteArr[1] = 2; byteArr[2] = 2; cacheCppJ.Put(i, ByteArray(3,byteArr));
Now I would like to do something like the following, but I donβt know how to ensure that my Java tasks are executed locally for the data.
final Integer affKey = new Integer(9); ignite.compute().affinityRun("myCacheBinaryCpp", affKey, () -> { cache.get(affKey); System.out.println("Got cache with affinity"); });
The problem is that the C ++ key is just int and there is no associated AffinityKey. So I donβt know if the affKey I created in Java will always work with the correct affinity for the node.
Is this the right approach? I also considered limiting each of my caches to a couple of nodes to ensure that all operations are on the correct node for at least 50% of the time (valid for my use case).
Sumit source share