Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignite C++ and Cache Affinity

I am using Apache Ignite 1.8.0 for caching on a cluster. I am using the C++ API and am accessing the same cache from both Java and C++. This works fine but I would like to also use affinity collocation to execute tasks on the same node that has cached the data. I am creating the cache in Java, putting the data in C++ but then want to run tasks in Java on this data. The C++ API doesn't have Affinity support so I am now wondering what my options are.

This is how I am creating the cache:

final IgniteCache<Integer, ByteArray> cache = ignite.createCache("myCacheBinaryCpp")

Then I put data from C++. I have a simple byte array class for testing purposes.

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 don't know how to ensure that my Java tasks will execute locally to the data.

final Integer affKey = new Integer(9);
ignite.compute().affinityRun("myCacheBinaryCpp", affKey, () -> {
      cache.get(affKey);
      System.out.println("Got cache with affinity");
});

The issue is that the key in C++ is just an int and there is no associated AffinityKey. Therefore I don't know if the affKey I created in Java will always run with the correct node affinity.

Is this the correct approach? I have also considered restricting each of my caches to a pair of nodes to ensure that all operations are on the correct node at least 50% of the time (acceptable me for my use case).

like image 226
Sumit Avatar asked Nov 09 '22 01:11

Sumit


1 Answers

If your values serialized properly on the C++ side and can be reached from the Java (you can check it with Put on C++ and Get on Java) then affinityRun will do exactly what it should - it will run task on the primary node for the provided key.

So the answer is "yes, this is going to work".

like image 146
isapego Avatar answered Nov 15 '22 06:11

isapego