Apache Solr open-source search software
tlog: ensure tlog so corrupted that constructor can't complete is closed so windows can remove the file after
Yonik Seeley3c95aa47d0dd
diff --git a/solr/core/src/java/org/apache/solr/update/TransactionLog.java b/solr/core/src/java/org/apache/solr/update/TransactionLog.javaindex c609a59861f..39ef39d6fc5 100644--- a/solr/core/src/java/org/apache/solr/update/TransactionLog.java+++ b/solr/core/src/java/org/apache/solr/update/TransactionLog.java@@ -141,6 +141,7 @@ public class TransactionLog {}TransactionLog(File tlogFile, Collection<String> globalStrings, boolean openExisting) {+ boolean success = false;try {if (debug) {log.debug("New TransactionLog file=" + tlogFile + ", exists=" + tlogFile.exists() + ", size=" + tlogFile.length() + ", openExisting=" + openExisting);@@ -175,8 +176,18 @@ public class TransactionLog {addGlobalStrings(globalStrings);}+ success = true;+} catch (IOException e) {throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);+ } finally {+ if (!success && raf != null) {+ try {+ raf.close();+ } catch (Exception e) {+ log.error("Error closing tlog file (after error opening)", e);+ }+ }}}diff --git a/solr/core/src/java/org/apache/solr/update/UpdateLog.java b/solr/core/src/java/org/apache/solr/update/UpdateLog.javaindex ea2f157b2a4..877daf38007 100644--- a/solr/core/src/java/org/apache/solr/update/UpdateLog.java+++ b/solr/core/src/java/org/apache/solr/update/UpdateLog.java@@ -205,7 +205,7 @@ public class UpdateLog implements PluginInfoInitialized {addOldLog(oldLog, false); // don't remove old logs on startup since more than one may be uncapped.} catch (Exception e) {SolrException.log(log, "Failure to open existing log file (non fatal) " + f, e);- f.delete();+ deleteFile(f);}}@@ -1346,6 +1346,26 @@ public class UpdateLog implements PluginInfoInitialized {Integer.MAX_VALUE, 1, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),new DefaultSolrThreadFactory("recoveryExecutor"));++ public static void deleteFile(File file) {+ boolean success = false;+ try {+ success = file.delete();+ if (!success) {+ log.error("Error deleting file: " + file);+ }+ } catch (Exception e) {+ log.error("Error deleting file: " + file, e);+ }++ if (!success) {+ try {+ file.deleteOnExit();+ } catch (Exception e) {+ log.error("Error deleting file on exit: " + file, e);+ }+ }+ }}diff --git a/solr/core/src/test/org/apache/solr/search/TestRecovery.java b/solr/core/src/test/org/apache/solr/search/TestRecovery.javaindex 4dd66ec3053..551769ef11a 100644--- a/solr/core/src/test/org/apache/solr/search/TestRecovery.java+++ b/solr/core/src/test/org/apache/solr/search/TestRecovery.java@@ -870,7 +870,6 @@ public class TestRecovery extends SolrTestCaseJ4 {// test that a corrupt tlog doesn't stop us from coming up//@Test- @Ignore // I have reproduced the failure on windows and am looking into fixes -yonikpublic void testCorruptLog() throws Exception {try {DirectUpdateHandler2.commitOnClose = false;@@ -885,6 +884,8 @@ public class TestRecovery extends SolrTestCaseJ4 {assertU(adoc("id","G3"));h.close();++String[] files = UpdateLog.getLogList(logDir);Arrays.sort(files);RandomAccessFile raf = new RandomAccessFile(new File(logDir, files[files.length-1]), "rw");@@ -1040,13 +1041,19 @@ public class TestRecovery extends SolrTestCaseJ4 {h.close();- String[] files = UpdateLog.getLogList(logDir);- for (String file : files) {- new File(logDir, file).delete();- }+ try {+ String[] files = UpdateLog.getLogList(logDir);+ for (String file : files) {+ new File(logDir, file).delete();+ }- assertEquals(0, UpdateLog.getLogList(logDir).length);- createCore();+ assertEquals(0, UpdateLog.getLogList(logDir).length);+ } finally {+ // make sure we create the core again, even if the assert fails so it won't mess+ // up the next test.+ createCore();+ assertJQ(req("q","*:*") ,"/response/numFound=="); // ensure it works+ }}private static Long getVer(SolrQueryRequest req) throws Exception {