[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
File lock held on cache persisted to disk after CacheManager.shutdown()  XML
Forum Index -> Ehcache
Author Message
upo

neo

Joined: 01/27/2014 09:38:27
Messages: 5
Offline

Hi all,

I'm trying to run the following simple piece of code in a JUnit test under Windows:

CacheManager cacheManager = CacheManager.newInstance(configFile);
cacheManager.addCache("test");
Cache cache = cacheManager.getCache("test");
cache.put(new Element("e1", new Integer(42)));
cacheManager.shutdown();

CacheManager cacheManager2 = CacheManager.newInstance(configFile);
Cache cache2 = cacheManager2.getCache("test");
Element element = cache2.get("e1");
Object objectValue = element.getObjectValue();
System.out.println(objectValue);
cacheManager2.shutdown();

Using the attached config file for the creation of the CacheManager caches are persisted to disk.

Steps are:
(1) create first CacheManager, store an element in cache "test" and shutdown the first CacheManager
(2) create second CacheManager, retrieve the element from cache "test" and shutdown the second CacheManager
(3) then the test tries to delete the folder containing the disk store and fails

It looks to me like there are file handles kept open due to (2). Deleting the disk store after (1) works fine.

Looks to me like a bug!

Regards
Uli
 Filename MAXIMUM_STRONG.xml [Disk] Download
 Description
 Filesize 532 bytes
 Downloaded:  122 time(s)

cdennis

master

Joined: 01/19/2009 10:03:26
Messages: 89
Offline

I believe I know whats going on here:

When you create the second cache manager the manager will run recovery over the data files created by the first cache manager instance. This recovery process create file mappings the unmapping of which is handled by the garbage collector. Since Windows doesn't allow the deletion of files with a mapped region open you won't be able to delete these files until after the GC runs and unmaps the mapped files. You don't quote the exception you get but I'm guessing it complains about not being able to delete a file with a mapped region open.

You really have two ways of getting round this:

1. Call System.gc() a bunch of times and wait for the GC to unmap the file.
2. Use unique file names - you might also be able to use deleteOnExit(...) successfully here.

Hope this helps/explains,

Chris

Chris Dennis (Terracotta Engineer)
upo

neo

Joined: 01/27/2014 09:38:27
Messages: 5
Offline

Hi Chris,

great - calling System.gc() expliocitly before deleting the files helped!

Many thanks
Uli
 
Forum Index -> Ehcache
Go to:   
Powered by JForum 2.1.7 © JForum Team