Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-4555: improve solution

Mark Robert Miller0dece6b60947
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index ec3260ba1e1..61984fa894c 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -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
diff --git a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java
index 33a53b67dbe..71dcb212768 100644
--- a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java
+++ b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java
@@ -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;
}
}
diff --git a/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java
index 7499208857f..1d265392c56 100644
--- a/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java
+++ b/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java
@@ -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);
+
}
}