• Task
  • Status: Closed
  • 2 Major
  • Resolution: Fixed
  • ehcache-core
  • hsingh
  • Reporter: alexsnaps
  • October 13, 2009
  • 0
  • Watchers: 0
  • January 17, 2013
  • February 11, 2010

Attachments

Description

While removing the Mutex approach to BlockingCache, replacing it with a RRWL, the follwing problem appeared: When EhCache is backed up by TC’s DistributedStore, inline eviction of an element requires the read lock to be “upgraded”, which obviously fails. This could easily be solved by not acquiring the read lock in BlockingCache, as DistributedCache will take care of it for us :

public Element get(final Object key) throws RuntimeException, LockTimeoutException {

    Sync lock = getLockForKey(key);
    Element element;
    boolean tcClustered = cache.getCacheConfiguration().isTerracottaClustered();
    if (!tcClustered) {
        acquiredLockForKey(key, lock, LockType.READ);
    }
    element = cache.get(key);
    if (!tcClustered) {
        lock.unlock(LockType.READ);
    }
    if (element == null) {
        acquiredLockForKey(key, lock, LockType.WRITE);
        element = cache.get(key);
        if (element != null) {
            lock.unlock(LockType.WRITE);
        }
    }
    return element;
}

The issue with this is that the acquireLockForKey method can be doing a tryLock(mSec) rather than a plain lock(), should BlockingCache.timeoutMillis > 0 Yet, DistributedCache would then also need to try to do so in timed fashion within that same BlockingCache.timeoutMillis… Which it currently doesn’t. Potential hack would be to release any readlock before trying to acquire the writelock and evict… yet, that might be a not so nice solution…

Comments

Alexander Snaps 2009-12-16

Here are 3 patches wrt EHC-420/EHC-554, for ehcache, tdc and tim-ehcache:

  • tim-ehcache patch extends BlockingCacheTest to test the inline eviction issue
  • ehcache patch enables BlockingCache for concurrent read on keys of a same stripe (and has the test above fail, as it would try to upgrade the read lock)
  • tim-distributed-cache has the DistributedCacheImpl.getNonExpiredEntry only removing expired entry if not under a read lock (avoiding the upgrade)

Fiona OShea 2010-01-26

What is the current status of this?

Alexander Snaps 2010-01-28

Li Ma wanted to test these patches with the customer… Haven’t heard anything since.

Alexander Snaps 2010-02-11

Solved on ehcache trunk as of r1866 And on both trunk and tc-3.2 r20572

Himadri Singh 2010-02-23

BlockingCacheTest covers this issue.