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:25:48 UTC
lucene-solr:branch_6x: LUCENE-7662: throw CorruptIndexException if
index files are missing
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x f41fbb5da -> 8ad763555
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/8ad76355
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/8ad76355
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/8ad76355
Branch: refs/heads/branch_6x
Commit: 8ad763555012cd7637238380b6bfc5b4d7254325
Parents: f41fbb5
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:25:07 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/8ad76355/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 971ea54..9156a0c 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -71,6 +71,10 @@ Improvements
either points or doc values depending on which one is more efficient.
(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-7641: Optimized point range queries to compute documents that do not
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/8ad76355/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/8ad76355/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 8426686..bc4f9fd 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;
@@ -284,8 +286,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/8ad76355/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 5d2e383..53efab0 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
@@ -435,14 +435,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) {
@@ -476,14 +471,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;
}
}
}
@@ -492,16 +482,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) {
@@ -517,4 +502,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);
+ }
}