SOLR-4555: When forceNew is used with CachingDirectoryFactory#get, the old CachValue should have it's path set to null.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1454993 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-03-11 04:20:14 +00:00
parent c97a94e020
commit 5ea281a9d6
5 changed files with 39 additions and 5 deletions

View File

@ -67,6 +67,9 @@ Bug Fixes
* SOLR-4551: CachingDirectoryFactory needs to create CacheEntry's with the
fullpath not path. (Mark Miller)
* SOLR-4555: When forceNew is used with CachingDirectoryFactory#get, the old
CachValue should have it's path set to null. (Mark Miller)
Other Changes
----------------------

View File

@ -166,7 +166,9 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
closeDirectory(cacheValue);
byDirectoryCache.remove(directory);
byPathCache.remove(cacheValue.path);
if (cacheValue.path != null) {
byPathCache.remove(cacheValue.path);
}
}
}
}
@ -259,6 +261,10 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
}
}
// kill the path, it will be owned by the new dir
// we count on it being released by directory
cacheValue.path = null;
}
}

View File

@ -64,8 +64,10 @@ public class StandardDirectoryFactory extends CachingDirectoryFactory {
if (val == null) {
throw new IllegalArgumentException("Unknown directory " + dir);
}
File dirFile = new File(val.path);
FileUtils.deleteDirectory(dirFile);
if (val.path != null) {
File dirFile = new File(val.path);
FileUtils.deleteDirectory(dirFile);
}
}
@Override

View File

@ -32,6 +32,7 @@ import org.junit.Test;
public class CachingDirectoryFactoryTest extends SolrTestCaseJ4 {
private Map<String,Tracker> dirs = new HashMap<String,Tracker>();
private List<Tracker> oldDirs = new ArrayList<Tracker>();
private volatile boolean stop = false;
private class Tracker {
@ -84,6 +85,17 @@ public class CachingDirectoryFactoryTest extends SolrTestCaseJ4 {
}
}
}
sz = oldDirs.size();
if (sz > 0) {
for (Tracker tracker : oldDirs) {
int cnt = tracker.refCnt.get();
for (int i = 0; i < cnt; i++) {
tracker.refCnt.decrementAndGet();
df.release(tracker.dir);
}
}
}
}
df.close();
@ -157,7 +169,18 @@ public class CachingDirectoryFactoryTest extends SolrTestCaseJ4 {
tracker.dir = df.get(path, DirContext.DEFAULT, null);
dirs.put(path, tracker);
} else {
tracker.dir = df.get(path, DirContext.DEFAULT, null);
if (random.nextInt(10) > 6) {
Tracker oldTracker = new Tracker();
oldTracker.refCnt = new AtomicInteger(tracker.refCnt.get());
oldTracker.path = tracker.path;
oldTracker.dir = tracker.dir;
oldDirs.add(oldTracker);
tracker.dir = df.get(path, DirContext.DEFAULT, null, true);
tracker.refCnt = new AtomicInteger(0);
} else {
tracker.dir = df.get(path, DirContext.DEFAULT, null);
}
}
tracker.refCnt.incrementAndGet();
}

View File

@ -1316,7 +1316,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
retry = true;
}
cnt++;
if (cnt > 10) break;
if (cnt > 20) break;
Thread.sleep(2000);
} while (retry);
}