mikemccand commented on code in PR #12872:
URL: https://github.com/apache/lucene/pull/12872#discussion_r1435749878


##########
lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java:
##########
@@ -389,13 +389,26 @@ private static void parseSegmentInfos(
     }
 
     long totalDocs = 0;
+    SegmentInfo info;
     for (int seg = 0; seg < numSegments; seg++) {
       String segName = input.readString();
       byte[] segmentID = new byte[StringHelper.ID_LENGTH];
       input.readBytes(segmentID, 0, segmentID.length);
       Codec codec = readCodec(input);
-      SegmentInfo info =
-          codec.segmentInfoFormat().read(directory, segName, segmentID, 
IOContext.READ);
+      try {
+        info = codec.segmentInfoFormat().read(directory, segName, segmentID, 
IOContext.READ);
+      } catch (Throwable t) {
+        if (infoStream != null) {
+          message(t.getMessage());
+        }
+        if (t instanceof NoSuchFileException || t instanceof 
FileNotFoundException) {
+          throw new CorruptSegmentInfoException(
+              "segment info file: " + segName + ".si cannot be read - it may 
be missing or corrupt",
+              input);
+        } else {
+          throw t;

Review Comment:
   Hmm why not also `CorruptSegmentInfoException` in this case too?



##########
lucene/core/src/java/org/apache/lucene/index/CorruptSegmentInfoException.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.index;
+
+import org.apache.lucene.store.DataInput;
+import org.apache.lucene.store.DataOutput;
+
+/** This exception is thrown when Lucene detects an inconsistency in the 
index. */

Review Comment:
   Can we improve the javadoc to state when this particular class is used (to 
express corruption when loading a single `_N.si` file?).



##########
lucene/core/src/java/org/apache/lucene/index/CorruptSegmentInfoException.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.index;
+
+import org.apache.lucene.store.DataInput;
+import org.apache.lucene.store.DataOutput;
+
+/** This exception is thrown when Lucene detects an inconsistency in the 
index. */
+public class CorruptSegmentInfoException extends CorruptIndexException {
+
+  /** Create exception with a message only */
+  public CorruptSegmentInfoException(String message, DataInput input) {

Review Comment:
   Shouldn't this class also take the `segmentName` so `CheckIndex` can do 
something interesting with it (know which segment to exorcise, report which 
segment's `.si` is broken, etc.)?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to