mirror of https://github.com/apache/lucene.git
tlog: ensure tlog so corrupted that constructor can't complete is closed so windows can remove the file after
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1384958 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ff7c8d0217
commit
3c95aa47d0
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 -yonik
|
||||
public 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 {
|
||||
|
|
Loading…
Reference in New Issue