Hi, I ran into a problem with using cache expiry and cache locks.
In my event listener for the expiry, I acquire/release a lock on the key
being expired.
This works fine unless something else waits on the lock after I've acquired
it, then they would be stuck in a deadlock.
The follow code snippet should reproduce this problem.
Should I not be trying to lock the cache object being expired in my
listener?
IgniteConfiguration igniteConfig = new IgniteConfiguration();
igniteConfig.setIncludeEventTypes(EventType.EVT_CACHE_OBJECT_EXPIRED);
Ignite ignite = Ignition.start(igniteConfig);
CacheConfiguration<Integer, Integer> cfg = new
CacheConfiguration<>();
cfg.setName("test1");
cfg.setCacheMode(CacheMode.PARTITIONED);
cfg.setRebalanceMode(CacheRebalanceMode.SYNC);
cfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
IgniteCache<Integer, Integer> cache1 = ignite.getOrCreateCache(cfg);
IgniteCache<Integer, Integer> cache2 = cache1.withExpiryPolicy(
new AccessedExpiryPolicy(new Duration(TimeUnit.SECONDS,
1)));
IgnitePredicate<CacheEvent> locallistener = (evt) -> {
try {
Lock lock = cache1.lock(evt.key());
lock.lock();
Thread.sleep(3000); // give some time for other thread to
try to acquire lock
/* -- critical section */
lock.unlock();
} catch (InterruptedException e) {
e.printStackTrace();
}
return true;
};
ignite.events().localListen(locallistener,
EventType.EVT_CACHE_OBJECT_EXPIRED);
cache2.put(1, 1);
Thread.sleep(2000); // wait for cache entry to expire and listener
to run
Lock lock = cache1.lock(1);
lock.lock();
/* -- critical section */
lock.unlock();
--
View this message in context:
http://apache-ignite-users.70518.x6.nabble.com/Problem-with-cache-expiry-and-lock-tp2363.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.