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

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1420779 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2012-12-12 15:43:03 +00:00
parent e890c66c79
commit c2516de262
2 changed files with 13 additions and 0 deletions

View File

@ -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
----------------------

View File

@ -72,6 +72,8 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
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) {