Search code examples
performancecluster-computingload-balancingignitegridgain

Apache Ignite CollisionSpi configuration


I have a requirement like "Only allow cache updates on same cache to run in sequence". Our client node is written in .net.

Every cache has affinity key and we use computeJob.AffinityCallAsync("cacheName", "affinityKey", job) to submit the compute job for execution.

Now If I use collisionSpi then, can I achieve "Sync jobs running on same node for same cache"? What configuration do I need to use?

Do I need to write same configuration for all the nodes(server and client)? I saw collisionSpi has no implementation for .net, so what can I do for .net client node?


Solution

  • Wrap your job logic in a lock to make it run in sequence:

    public class MyJob : IComputeFunc<string>
    {
        private static readonly object SyncRoot = new object();
    
        public string Invoke()
        {
            lock (SyncRoot)
            {
                // Update cache
            }
        }
    }
    

    Notes:

    • ICache.Invoke may be a better fit for your use case
    • The requirement for sequential update sounds weird and may cause suboptimal performance: Ignite caches are safe to update concurrently. Please make sure this requirement makes sense.

    UPDATE

    Adding a lock will ensure that one update happens at a time on a given node. Other nodes may perform updates in parallel. The order of updates is not guaranteed as well.