You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2017/02/11 01:21:05 UTC
lucene-solr:master: LUCENE-7662: throw CorruptIndexException if index
files are missing
Repository: lucene-solr
Updated Branches:
refs/heads/master 015382257 -> be007a6c1
LUCENE-7662: throw CorruptIndexException if index files are missing
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/be007a6c
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/be007a6c
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/be007a6c
Branch: refs/heads/master
Commit: be007a6c1124103ed4b21051a4ec98d94a2f7efa
Parents: 0153822
Author: Mike McCandless <mi...@apache.org>
Authored: Fri Feb 10 20:20:53 2017 -0500
Committer: Mike McCandless <mi...@apache.org>
Committed: Fri Feb 10 20:20:53 2017 -0500
----------------------------------------------------------------------
lucene/CHANGES.txt | 4 ++
.../apache/lucene/index/SegmentCoreReaders.java | 7 +++
.../org/apache/lucene/index/SegmentInfos.java | 6 ++-
.../index/BaseIndexFileFormatTestCase.java | 51 ++++++++++----------
4 files changed, 40 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/be007a6c/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index b439b46..88a1629 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -37,6 +37,10 @@ Improvements
* LUCENE-7489: Better storage of sparse doc-values fields with the default
codec. (Adrien Grand)
+* LUCENE-7662: If index files are missing, throw CorruptIndexException instead
+ of the less descriptive FileNotFound or NoSuchFileException (Mike Drob via
+ Mike McCandless, Erick Erickson)
+
Optimizations
* LUCENE-7416: BooleanQuery optimizes queries that have queries that occur both
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/be007a6c/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java b/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java
index 21ac4a1..270a2d5 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java
@@ -17,7 +17,10 @@
package org.apache.lucene.index;
+import java.io.EOFException;
+import java.io.FileNotFoundException;
import java.io.IOException;
+import java.nio.file.NoSuchFileException;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
@@ -133,6 +136,10 @@ final class SegmentCoreReaders {
pointsReader = null;
}
success = true;
+ } catch (EOFException | FileNotFoundException e) {
+ throw new CorruptIndexException("Problem reading index from " + dir, dir.toString(), e);
+ } catch (NoSuchFileException e) {
+ throw new CorruptIndexException("Problem reading index.", e.getFile(), e);
} finally {
if (!success) {
decRef();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/be007a6c/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
index 3e8b1f8..aaa1d89 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
@@ -18,8 +18,10 @@ package org.apache.lucene.index;
import java.io.EOFException;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
+import java.nio.file.NoSuchFileException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -280,8 +282,8 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
try (ChecksumIndexInput input = directory.openChecksumInput(segmentFileName, IOContext.READ)) {
try {
return readCommit(directory, input, generation);
- } catch (EOFException e) {
- throw new CorruptIndexException("Unexpected end of file while reading index.", input, e);
+ } catch (EOFException | NoSuchFileException | FileNotFoundException e) {
+ throw new CorruptIndexException("Unexpected file read error while reading index.", input, e);
}
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/be007a6c/lucene/test-framework/src/java/org/apache/lucene/index/BaseIndexFileFormatTestCase.java
----------------------------------------------------------------------
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseIndexFileFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseIndexFileFormatTestCase.java
index 7a7abc0..3097cdf 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseIndexFileFormatTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseIndexFileFormatTestCase.java
@@ -544,14 +544,9 @@ abstract class BaseIndexFileFormatTestCase extends LuceneTestCase {
conf.setMergeScheduler(new SerialMergeScheduler());
conf.setCodec(getCodec());
iw = new IndexWriter(dir, conf);
- } catch (Exception e) {
- if (e.getMessage() != null && e.getMessage().startsWith("a random IOException")) {
- exceptionStream.println("\nTEST: got expected fake exc:" + e.getMessage());
- e.printStackTrace(exceptionStream);
- allowAlreadyClosed = true;
- } else {
- Rethrow.rethrow(e);
- }
+ } catch (IOException e) {
+ handleFakeIOException(e, exceptionStream);
+ allowAlreadyClosed = true;
}
if (random().nextInt(10) == 0) {
@@ -585,14 +580,9 @@ abstract class BaseIndexFileFormatTestCase extends LuceneTestCase {
conf.setMergeScheduler(new SerialMergeScheduler());
conf.setCodec(getCodec());
iw = new IndexWriter(dir, conf);
- } catch (Exception e) {
- if (e.getMessage() != null && e.getMessage().startsWith("a random IOException")) {
- exceptionStream.println("\nTEST: got expected fake exc:" + e.getMessage());
- e.printStackTrace(exceptionStream);
- allowAlreadyClosed = true;
- } else {
- Rethrow.rethrow(e);
- }
+ } catch (IOException e) {
+ handleFakeIOException(e, exceptionStream);
+ allowAlreadyClosed = true;
}
}
}
@@ -601,16 +591,11 @@ abstract class BaseIndexFileFormatTestCase extends LuceneTestCase {
dir.setRandomIOExceptionRateOnOpen(0.0); // disable exceptions on openInput until next iteration:
// or we make slowExists angry and trip a scarier assert!
iw.close();
- } catch (Exception e) {
- if (e.getMessage() != null && e.getMessage().startsWith("a random IOException")) {
- exceptionStream.println("\nTEST: got expected fake exc:" + e.getMessage());
- e.printStackTrace(exceptionStream);
- try {
- iw.rollback();
- } catch (Throwable t) {}
- } else {
- Rethrow.rethrow(e);
- }
+ } catch (IOException e) {
+ handleFakeIOException(e, exceptionStream);
+ try {
+ iw.rollback();
+ } catch (Throwable t) {}
}
dir.close();
} catch (Throwable t) {
@@ -626,4 +611,18 @@ abstract class BaseIndexFileFormatTestCase extends LuceneTestCase {
System.out.println(exceptionLog.toString("UTF-8"));
}
}
+
+ private void handleFakeIOException(IOException e, PrintStream exceptionStream) {
+ Throwable ex = e;
+ while (ex != null) {
+ if (ex.getMessage() != null && ex.getMessage().startsWith("a random IOException")) {
+ exceptionStream.println("\nTEST: got expected fake exc:" + ex.getMessage());
+ ex.printStackTrace(exceptionStream);
+ return;
+ }
+ ex = ex.getCause();
+ }
+
+ Rethrow.rethrow(e);
+ }
}