• Bug
  • Status: New
  • Resolution:
  • drb
  • Reporter: riccardo
  • December 03, 2014
  • 0
  • Watchers: 1
  • December 03, 2014

Description

A cache configured for overflowToDisk invokes MemoryStore.flush() from Cache.dispose() when CacheManager.shutdown() is invoked. This causes all in-memory entries to be flushed to disk. However when DiskStore is disposed of unless this store is marked as persistent the data files are deleted. This causes unnecessary delay to the shutdown process. MemoryStore.dispose() needs to bypass the call to flush() unless the cache.isDiskPersistent().

Sourceforge Ticket ID: 1888993 - Opened By: nobody - 7 Feb 2008 18:56 UTC

Comments

Riccardo Boscolo 2014-12-03

Cloned this issue from EHC-292 as I do not have permissions to re-open that ticket. I can confirm that this issue still exists as of release +2.9.0+.

It is actually very easy to spot the issue in the code. When {{CacheManager#shutdown}} is invoked on a +*non-persistent*+ cached, backed by a {{DiskStore}} (just like it would occur when choosing a _localTempSwap_ persistence strategy), the entire contents of the cache are flushed to disk when the cache is shut down.

From _net.sf.ehcache.store.CacheStore_:

334    @Override
335    public synchronized void dispose() {
336        if (status == Status.STATUS_SHUTDOWN) {
337            return;
338        }
339        if (cacheConfiguration != null && cacheConfiguration.isClearOnFlush()) {
340            cachingTier.clear();
341        }
342        authoritativeTier.dispose();
343        status = Status.STATUS_SHUTDOWN;
344    }

and _net.sf.ehcache.store.disk.DiskStore_:

661    public void dispose() {
662        if (status.compareAndSet(Status.STATUS_ALIVE, Status.STATUS_SHUTDOWN)) {
663            clearFaultedBit();
664            disk.unbind();
665            onHeapPoolAccessor.unlink();
666            onDiskPoolAccessor.unlink();
667        }
668    }

and _net.sf.ehcache.store.disk.DiskStorageFactory_:

919    public void unbind() {
920        try {
921            flushTask.call();
922        } catch (Throwable t) {
923            LOG.error("Could not flush disk cache. Initial cause was " + t.getMessage(), t);
924        }
925
926        try {
927            shutdown();
928            if (diskStorePathManager.isAutoCreated()) {
929                deleteFile(indexFile);
930                delete();
931            }
932        } catch (IOException e) {
933            LOG.error("Could not shut down disk cache. Initial cause was " + e.getMessage(), e);
934        }
935    }

There is clearly no test on whether the cache is persistent or not, hence the inefficient shutdown.