Apache Lucene open-source search software
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
Mark Robert Miller02854d4054f1
diff --git a/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/DirectoryFactory.javaindex 16c0f3405ee..4ac0f2d4ba7 100644--- a/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java@@ -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.*diff --git a/solr/core/src/java/org/apache/solr/core/EphemeralDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/EphemeralDirectoryFactory.javaindex 4a4d87c37b8..1924e877a56 100644--- a/solr/core/src/java/org/apache/solr/core/EphemeralDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/EphemeralDirectoryFactory.java@@ -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+ }+@Overridepublic String normalize(String path) throws IOException {return path;diff --git a/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.javaindex 8c02c0cca77..c5c07cc7e8a 100644--- a/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java@@ -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);}+}diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.javaindex 4aa4cc14cac..931c6ac72db 100644--- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java@@ -614,26 +614,10 @@ public class CoreAdminHandler extends RequestHandlerBase {@Overridepublic 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);}}});