mirror of https://github.com/apache/lucene.git
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:
parent
e890c66c79
commit
c2516de262
|
@ -334,6 +334,9 @@ Bug Fixes
|
||||||
* SOLR-4168: Ensure we are using the absolute latest index dir when getting
|
* SOLR-4168: Ensure we are using the absolute latest index dir when getting
|
||||||
list of files for replication. (Mark Miller)
|
list of files for replication. (Mark Miller)
|
||||||
|
|
||||||
|
* SOLR-4171: CachingDirectoryFactory should not return any directories after it
|
||||||
|
has been closed. (Mark Miller)
|
||||||
|
|
||||||
Other Changes
|
Other Changes
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,8 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
|
||||||
private Double maxWriteMBPerSecRead;
|
private Double maxWriteMBPerSecRead;
|
||||||
|
|
||||||
private Double maxWriteMBPerSecDefault;
|
private Double maxWriteMBPerSecDefault;
|
||||||
|
|
||||||
|
private boolean closed;
|
||||||
|
|
||||||
public interface CloseListener {
|
public interface CloseListener {
|
||||||
public void postClose();
|
public void postClose();
|
||||||
|
@ -120,6 +122,7 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
this.closed = true;
|
||||||
for (CacheValue val : byDirectoryCache.values()) {
|
for (CacheValue val : byDirectoryCache.values()) {
|
||||||
try {
|
try {
|
||||||
// if there are still refs out, we have to wait for them
|
// 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;
|
assert val.refCnt == 0 : val.refCnt;
|
||||||
|
log.info("Closing directory when closing factory:" + val.path);
|
||||||
val.directory.close();
|
val.directory.close();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
SolrException.log(log, "Error closing directory", 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 {
|
private void close(Directory directory) throws IOException {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
|
||||||
CacheValue cacheValue = byDirectoryCache.get(directory);
|
CacheValue cacheValue = byDirectoryCache.get(directory);
|
||||||
if (cacheValue == null) {
|
if (cacheValue == null) {
|
||||||
throw new IllegalArgumentException("Unknown directory: " + directory
|
throw new IllegalArgumentException("Unknown directory: " + directory
|
||||||
|
@ -164,6 +169,7 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
log.info("Closing directory:" + cacheValue.path);
|
||||||
directory.close();
|
directory.close();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
SolrException.log(log, "Error closing directory", t);
|
SolrException.log(log, "Error closing directory", t);
|
||||||
|
@ -215,6 +221,10 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
|
||||||
throws IOException {
|
throws IOException {
|
||||||
String fullPath = new File(path).getAbsolutePath();
|
String fullPath = new File(path).getAbsolutePath();
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
if (closed) {
|
||||||
|
throw new RuntimeException("Already closed");
|
||||||
|
}
|
||||||
|
|
||||||
final CacheValue cacheValue = byPathCache.get(fullPath);
|
final CacheValue cacheValue = byPathCache.get(fullPath);
|
||||||
Directory directory = null;
|
Directory directory = null;
|
||||||
if (cacheValue != null) {
|
if (cacheValue != null) {
|
||||||
|
|
Loading…
Reference in New Issue