Skip to content

Apache Lucene open-source search software

SOLR-4171: CachingDirectoryFactory should not return any directories after it has been closed.

Mark Robert Millerc2516de26244
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index bb5f0f7aed3..995667364b5 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -334,6 +334,9 @@ Bug Fixes
* SOLR-4168: Ensure we are using the absolute latest index dir when getting
list of files for replication. (Mark Miller)
+* SOLR-4171: CachingDirectoryFactory should not return any directories after it
+ has been closed. (Mark Miller)
+
Other Changes
----------------------
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 b4e9eace9c3..ee0d68397f7 100644
--- a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java
+++ b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java
@@ -71,6 +71,8 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
private Double maxWriteMBPerSecRead;
private Double maxWriteMBPerSecDefault;
+
+ private boolean closed;
public interface CloseListener {
public void postClose();
@@ -120,6 +122,7 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
@Override
public void close() throws IOException {
synchronized (this) {
+ this.closed = true;
for (CacheValue val : byDirectoryCache.values()) {
try {
// if there are still refs out, we have to wait for them
@@ -134,6 +137,7 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
}
assert val.refCnt == 0 : val.refCnt;
+ log.info("Closing directory when closing factory:" + val.path);
val.directory.close();
} catch (Throwable t) {
SolrException.log(log, "Error closing directory", t);
@@ -146,6 +150,7 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
private void close(Directory directory) throws IOException {
synchronized (this) {
+
CacheValue cacheValue = byDirectoryCache.get(directory);
if (cacheValue == null) {
throw new IllegalArgumentException("Unknown directory: " + directory
@@ -164,6 +169,7 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
}
}
try {
+ log.info("Closing directory:" + cacheValue.path);
directory.close();
} catch (Throwable t) {
SolrException.log(log, "Error closing directory", t);
@@ -215,6 +221,10 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
throws IOException {
String fullPath = new File(path).getAbsolutePath();
synchronized (this) {
+ if (closed) {
+ throw new RuntimeException("Already closed");
+ }
+
final CacheValue cacheValue = byPathCache.get(fullPath);
Directory directory = null;
if (cacheValue != null) {