How to disable all operations on ignite cache when topology is not valid

Viewed 260

I have 2 server nodes and one client node. I am using TopologyValidator to validate the topology. If any server node left the cluster I want disable all operations. TopologyValidator disables only update operation not get operation. Can you help me to do this?

2 Answers

Currently TopologyValidator disables update operations only. You can use IgniteCache#close() operations to disable all operations on specific caches.

See: https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/IgniteCache.html#close--

If you do the following:

        IgniteCache cache = ignite.getOrCreateCache(config);
        cache.put(1L , new Person(1L, "A", "B"));
        cache.close();
        System.out.println(cache.get(1L)); //exception here.

you will get the following exception on the get call:

[INFO ][exchange-worker-#43%node1%][GridCacheProcessor] Finish proxy initialization, cacheName=test1, localNodeId=...
Exception in thread "main" java.lang.IllegalStateException: Cache has been closed: test1
    at org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.checkProxyIsValid(GatewayProtectedCacheProxy.java:1548)
    at org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.onEnter(GatewayProtectedCacheProxy.java:1580)
    at org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.get(GatewayProtectedCacheProxy.java:634)

In addition to Alex's answer, you might implement a custom analog of the TopologyValidator. All you need is to listen for the EVT_NODE_LEFT and EVT_NODE_JOINED events to trigger the custom logic, like stopping a cache or switching some application access validator.

Related