Apache Solr open-source search software
LUCENE-7898: Remove hasSegID from SegmentInfos.
Adrien Grand708462eded31
diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.javaindex e3761ccc2f6..a00a470a249 100644--- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java@@ -65,7 +65,7 @@ import org.apache.lucene.util.Version;* Files:* <ul>* <li><tt>segments_N</tt>: Header, LuceneVersion, Version, NameCounter, SegCount, MinSegmentLuceneVersion, <SegName,- * HasSegID, SegID, SegCodec, DelGen, DeletionCount, FieldInfosGen, DocValuesGen,+ * SegID, SegCodec, DelGen, DeletionCount, FieldInfosGen, DocValuesGen,* UpdatesFiles><sup>SegCount</sup>, CommitUserData, Footer* </ul>* Data types:@@ -78,7 +78,6 @@ import org.apache.lucene.util.Version;* {@link DataOutput#writeInt Int32}</li>* <li>Generation, Version, DelGen, Checksum, FieldInfosGen, DocValuesGen -->* {@link DataOutput#writeLong Int64}</li>- * <li>HasSegID --> {@link DataOutput#writeByte Int8}</li>* <li>SegID --> {@link DataOutput#writeByte Int8<sup>ID_LENGTH</sup>}</li>* <li>SegName, SegCodec --> {@link DataOutput#writeString String}</li>* <li>CommitUserData --> {@link DataOutput#writeMapOfStrings@@ -100,9 +99,6 @@ import org.apache.lucene.util.Version;* <li>DeletionCount records the number of deleted documents in this segment.</li>* <li>SegCodec is the {@link Codec#getName() name} of the Codec that encoded* this segment.</li>- * <li>HasSegID is nonzero if the segment has an identifier. Otherwise, when it is 0- * the identifier is {@code null} and no SegID is written. Null only happens for Lucene- * 4.x segments referenced in commits.</li>* <li>SegID is the identifier of the Codec that encoded this segment. </li>* <li>CommitUserData stores an optional user-supplied opaque* Map<String,String> that was passed to@@ -345,17 +341,17 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfolong totalDocs = 0;for (int seg = 0; seg < numSegments; seg++) {String segName = input.readString();- final byte segmentID[];- byte hasID = input.readByte();- if (hasID == 1) {- segmentID = new byte[StringHelper.ID_LENGTH];- input.readBytes(segmentID, 0, segmentID.length);- } else if (hasID == 0) {- throw new IndexFormatTooOldException(input, "Segment is from Lucene 4.x");- } else {- throw new CorruptIndexException("invalid hasID byte, got: " + hasID, input);+ if (format < VERSION_70) {+ byte hasID = input.readByte();+ if (hasID == 0) {+ throw new IndexFormatTooOldException(input, "Segment is from Lucene 4.x");+ } else if (hasID != 1) {+ throw new CorruptIndexException("invalid hasID byte, got: " + hasID, input);+ }}- Codec codec = readCodec(input, format < VERSION_53);+ 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);info.setCodec(codec);totalDocs += info.maxDoc();@@ -409,24 +405,12 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInforeturn infos;}- private static final List<String> unsupportedCodecs = Arrays.asList(- "Lucene3x", "Lucene40", "Lucene41", "Lucene42", "Lucene45", "Lucene46", "Lucene49", "Lucene410"- );-- private static Codec readCodec(DataInput input, boolean unsupportedAllowed) throws IOException {+ private static Codec readCodec(DataInput input) throws IOException {final String name = input.readString();try {return Codec.forName(name);} catch (IllegalArgumentException e) {- // give better error messages if we can, first check if this is a legacy codec- if (unsupportedCodecs.contains(name)) {- // We should only get here on pre-5.3 indices, but we can't test this until 7.0 when 5.x indices become too old:- assert unsupportedAllowed;- IOException newExc = new IndexFormatTooOldException(input, "Codec '" + name + "' is too old");- newExc.initCause(e);- throw newExc;- }- // or maybe it's an old default codec that moved+ // maybe it's an old default codec that movedif (name.startsWith("Lucene")) {throw new IllegalArgumentException("Could not load codec '" + name + "'. Did you forget to add lucene-backward-codecs.jar?", e);}@@ -523,16 +507,10 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo}out.writeString(si.name);byte segmentID[] = si.getId();- // TODO: remove this in lucene 6, we don't need to include 4.x segments in commits anymore- if (segmentID == null) {- out.writeByte((byte)0);- } else {- if (segmentID.length != StringHelper.ID_LENGTH) {- throw new IllegalStateException("cannot write segment: invalid id segment=" + si.name + "id=" + StringHelper.idToString(segmentID));- }- out.writeByte((byte)1);- out.writeBytes(segmentID, segmentID.length);+ if (segmentID.length != StringHelper.ID_LENGTH) {+ throw new IllegalStateException("cannot write segment: invalid id segment=" + si.name + "id=" + StringHelper.idToString(segmentID));}+ out.writeBytes(segmentID, segmentID.length);out.writeString(si.getCodec().getName());out.writeLong(siPerCommit.getDelGen());int delCount = siPerCommit.getDelCount();