SOLR-4171: add a new release(path) method that can be called after factory shutdown and have unload core use it to remove a directory after a core has been shutdown

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1420911 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2012-12-12 18:49:00 +00:00
parent 9a74a588da
commit 02854d4054
4 changed files with 26 additions and 18 deletions

View File

@ -88,6 +88,16 @@ public abstract class DirectoryFactory implements NamedListInitializedPlugin,
*/
public abstract void remove(Directory dir) throws IOException;
/**
* This remove is special in that it may be called even after
* the factory has been closed. Remove only makes sense for
* peristent directory factories.
*
* @param path to remove
* @throws IOException If there is a low-level I/O error.
*/
public abstract void remove(String path) throws IOException;
/**
* Override for more efficient moves.
*

View File

@ -49,6 +49,11 @@ public abstract class EphemeralDirectoryFactory extends CachingDirectoryFactory
// ram dir does not persist its dir anywhere
}
@Override
public void remove(String path) throws IOException {
// ram dir does not persist its dir anywhere
}
@Override
public String normalize(String path) throws IOException {
return path;

View File

@ -48,12 +48,20 @@ public class StandardDirectoryFactory extends CachingDirectoryFactory {
public void remove(Directory dir) throws IOException {
CacheValue val = byDirectoryCache.get(dir);
if (val == null) {
throw new NullPointerException("Unknown directory " + dir);
throw new IllegalArgumentException("Unknown directory " + dir);
}
File dirFile = new File(val.path);
FileUtils.deleteDirectory(dirFile);
}
@Override
public void remove(String path) throws IOException {
String fullPath = new File(path).getAbsolutePath();
File dirFile = new File(fullPath);
FileUtils.deleteDirectory(dirFile);
}
/**
* Override for more efficient moves.
*
@ -76,4 +84,5 @@ public class StandardDirectoryFactory extends CachingDirectoryFactory {
super.move(fromDir, toDir, fileName, ioContext);
}
}

View File

@ -614,26 +614,10 @@ public class CoreAdminHandler extends RequestHandlerBase {
@Override
public void postClose(SolrCore core) {
Directory dir = null;
try {
dir = core.getDirectoryFactory().get(core.getIndexDir(), core.getSolrConfig().indexConfig.lockType);
core.getDirectoryFactory().remove(dir);
core.getDirectoryFactory().doneWithDirectory(dir);
core.getDirectoryFactory().remove(core.getIndexDir());
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (dir != null) {
try {
core.getDirectoryFactory().release(dir);
} catch (IOException e) {
log.error("IOException trying to release directory", e);
}
}
}
try {
core.getDirectoryFactory().remove(dir);
} catch (IOException e) {
log.error("IOException trying to remove directory", e);
}
}
});