SOLR-4555: improve solution

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1457475 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-03-17 16:11:15 +00:00
parent 3c5031804f
commit 0dece6b609
3 changed files with 15 additions and 11 deletions

View File

@ -82,7 +82,8 @@ Bug Fixes
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)
CachValue should give up it's path as it will be used by a new Directory
instance. (Mark Miller)
* SOLR-4361: DataImportHandler would throw UnsupportedOperationException if
handler-level parameters were specified containing periods in the name

View File

@ -48,6 +48,7 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
protected class CacheValue {
public Directory directory;
public int refCnt = 1;
public boolean closed;
public String path;
public boolean doneWithDir = false;
@Override
@ -178,7 +179,10 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
closeDirectory(cacheValue);
byDirectoryCache.remove(directory);
if (cacheValue.path != null) {
// if it's been closed, it's path is now
// owned by another Directory instance
if (!cacheValue.closed) {
byPathCache.remove(cacheValue.path);
}
}
@ -273,9 +277,9 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
}
}
// kill the path, it will be owned by the new dir
// close the entry, it will be owned by the new dir
// we count on it being released by directory
cacheValue.path = null;
cacheValue.closed = true;
}
}

View File

@ -60,16 +60,15 @@ public class StandardDirectoryFactory extends CachingDirectoryFactory {
@Override
public void remove(Directory dir) throws IOException {
CacheValue val;
synchronized (this) {
val = byDirectoryCache.get(dir);
}
if (val == null) {
throw new IllegalArgumentException("Unknown directory " + dir);
}
if (val.path != null) {
CacheValue val = byDirectoryCache.get(dir);
if (val == null) {
throw new IllegalArgumentException("Unknown directory " + dir);
}
File dirFile = new File(val.path);
FileUtils.deleteDirectory(dirFile);
}
}