Apache Lucene open-source search software
LUCENE-5969: clean up unnecessary back compat and add segment header
Robert Muir31a5763f2dd0
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexReader.javaindex 62bef2632e5..bd7852081b9 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexReader.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexReader.java@@ -17,13 +17,11 @@ package org.apache.lucene.codecs.blockterms;* limitations under the License.*/-import org.apache.lucene.store.Directory;-import org.apache.lucene.store.IOContext;import org.apache.lucene.store.IndexInput;import org.apache.lucene.codecs.CodecUtil;import org.apache.lucene.index.CorruptIndexException;-import org.apache.lucene.index.FieldInfos;import org.apache.lucene.index.FieldInfo;+import org.apache.lucene.index.SegmentReadState;import org.apache.lucene.util.Accountable;import org.apache.lucene.util.Accountables;import org.apache.lucene.util.BytesRef;@@ -34,7 +32,6 @@ import org.apache.lucene.util.packed.MonotonicBlockPackedReader;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;-import java.util.Comparator;import java.util.List;import java.io.IOException;@@ -58,8 +55,6 @@ public class FixedGapTermsIndexReader extends TermsIndexReaderBase {private final int packedIntsVersion;private final int blocksize;- private final Comparator<BytesRef> termComp;-private final static int PAGED_BYTES_BITS = 15;// all fields share this single logical byte[]@@ -67,28 +62,24 @@ public class FixedGapTermsIndexReader extends TermsIndexReaderBase {final HashMap<String,FieldIndexData> fields = new HashMap<>();- // start of the field info data- private long dirOffset;-- private int version;-- public FixedGapTermsIndexReader(Directory dir, FieldInfos fieldInfos, String segment, Comparator<BytesRef> termComp, String segmentSuffix, IOContext context)- throws IOException {+ public FixedGapTermsIndexReader(SegmentReadState state) throws IOException {final PagedBytes termBytes = new PagedBytes(PAGED_BYTES_BITS);-- this.termComp = termComp;- final IndexInput in = dir.openInput(IndexFileNames.segmentFileName(segment, segmentSuffix, FixedGapTermsIndexWriter.TERMS_INDEX_EXTENSION), context);+ String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name,+ state.segmentSuffix,+ FixedGapTermsIndexWriter.TERMS_INDEX_EXTENSION);+ final IndexInput in = state.directory.openInput(fileName, state.context);boolean success = false;try {- readHeader(in);+ CodecUtil.checkSegmentHeader(in, FixedGapTermsIndexWriter.CODEC_NAME,+ FixedGapTermsIndexWriter.VERSION_CURRENT,+ FixedGapTermsIndexWriter.VERSION_CURRENT,+ state.segmentInfo.getId(), state.segmentSuffix);- if (version >= FixedGapTermsIndexWriter.VERSION_CHECKSUM) {- CodecUtil.checksumEntireFile(in);- }+ CodecUtil.checksumEntireFile(in);indexInterval = in.readVInt();if (indexInterval < 1) {@@ -97,7 +88,7 @@ public class FixedGapTermsIndexReader extends TermsIndexReaderBase {packedIntsVersion = in.readVInt();blocksize = in.readVInt();- seekDir(in, dirOffset);+ seekDir(in);// Read directoryfinal int numFields = in.readVInt();@@ -118,7 +109,7 @@ public class FixedGapTermsIndexReader extends TermsIndexReaderBase {if (packedIndexStart < indexStart) {throw new CorruptIndexException("invalid packedIndexStart: " + packedIndexStart + " indexStart: " + indexStart + "numIndexTerms: " + numIndexTerms, in);}- final FieldInfo fieldInfo = fieldInfos.fieldInfo(field);+ final FieldInfo fieldInfo = state.fieldInfos.fieldInfo(field);FieldIndexData previous = fields.put(fieldInfo.name, new FieldIndexData(in, termBytes, indexStart, termsStart, packedIndexStart, packedOffsetsStart, numIndexTerms));if (previous != null) {throw new CorruptIndexException("duplicate field: " + fieldInfo.name, in);@@ -135,11 +126,6 @@ public class FixedGapTermsIndexReader extends TermsIndexReaderBase {}}- private void readHeader(IndexInput input) throws IOException {- version = CodecUtil.checkHeader(input, FixedGapTermsIndexWriter.CODEC_NAME,- FixedGapTermsIndexWriter.VERSION_CURRENT, FixedGapTermsIndexWriter.VERSION_CURRENT);- }-private class IndexEnum extends FieldIndexEnum {private final FieldIndexData fieldIndex;private final BytesRef term = new BytesRef();@@ -166,7 +152,7 @@ public class FixedGapTermsIndexReader extends TermsIndexReaderBase {final int length = (int) (fieldIndex.termOffsets.get(1+mid) - offset);termBytesReader.fillSlice(term, fieldIndex.termBytesStart + offset, length);- int delta = termComp.compare(target, term);+ int delta = target.compareTo(term);if (delta < 0) {hi = mid - 1;} else if (delta > 0) {@@ -301,13 +287,9 @@ public class FixedGapTermsIndexReader extends TermsIndexReaderBase {@Overridepublic void close() throws IOException {}- private void seekDir(IndexInput input, long dirOffset) throws IOException {- if (version >= FixedGapTermsIndexWriter.VERSION_CHECKSUM) {- input.seek(input.length() - CodecUtil.footerLength() - 8);- } else {- input.seek(input.length() - 8);- }- dirOffset = input.readLong();+ private void seekDir(IndexInput input) throws IOException {+ input.seek(input.length() - CodecUtil.footerLength() - 8);+ long dirOffset = input.readLong();input.seek(dirOffset);}diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexWriter.java b/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexWriter.javaindex dda65307f76..dd2008ed234 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexWriter.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexWriter.java@@ -49,12 +49,9 @@ public class FixedGapTermsIndexWriter extends TermsIndexWriterBase {/** Extension of terms index file */static final String TERMS_INDEX_EXTENSION = "tii";- final static String CODEC_NAME = "SIMPLE_STANDARD_TERMS_INDEX";- final static int VERSION_START = 0;- final static int VERSION_APPEND_ONLY = 1;- final static int VERSION_MONOTONIC_ADDRESSING = 2;- final static int VERSION_CHECKSUM = 3;- final static int VERSION_CURRENT = VERSION_CHECKSUM;+ final static String CODEC_NAME = "FixedGapTermsIndex";+ final static int VERSION_START = 4;+ final static int VERSION_CURRENT = VERSION_START;final static int BLOCKSIZE = 4096;final private int termIndexInterval;@@ -75,7 +72,7 @@ public class FixedGapTermsIndexWriter extends TermsIndexWriterBase {out = state.directory.createOutput(indexFileName, state.context);boolean success = false;try {- writeHeader(out);+ CodecUtil.writeSegmentHeader(out, CODEC_NAME, VERSION_CURRENT, state.segmentInfo.getId(), state.segmentSuffix);out.writeVInt(termIndexInterval);out.writeVInt(PackedInts.VERSION_CURRENT);out.writeVInt(BLOCKSIZE);@@ -86,10 +83,6 @@ public class FixedGapTermsIndexWriter extends TermsIndexWriterBase {}}}-- private void writeHeader(IndexOutput out) throws IOException {- CodecUtil.writeHeader(out, CODEC_NAME, VERSION_CURRENT);- }@Overridepublic FieldWriter addField(FieldInfo field, long termsFilePointer) {diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41ords/Lucene41WithOrds.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41ords/Lucene41WithOrds.javaindex a6e42d5d001..f98ce8865fc 100644--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41ords/Lucene41WithOrds.java+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41ords/Lucene41WithOrds.java@@ -100,11 +100,7 @@ public final class Lucene41WithOrds extends PostingsFormat {boolean success = false;try {- indexReader = new FixedGapTermsIndexReader(state.directory,- state.fieldInfos,- state.segmentInfo.name,- BytesRef.getUTF8SortedAsUnicodeComparator(),- state.segmentSuffix, state.context);+ indexReader = new FixedGapTermsIndexReader(state);success = true;} finally {if (!success) {diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/mockrandom/MockRandomPostingsFormat.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/mockrandom/MockRandomPostingsFormat.javaindex 7a7e8cccb5c..30a150147a9 100644--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/mockrandom/MockRandomPostingsFormat.java+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/mockrandom/MockRandomPostingsFormat.java@@ -340,11 +340,7 @@ public final class MockRandomPostingsFormat extends PostingsFormat {if (LuceneTestCase.VERBOSE) {System.out.println("MockRandomCodec: fixed-gap terms index");}- indexReader = new FixedGapTermsIndexReader(state.directory,- state.fieldInfos,- state.segmentInfo.name,- BytesRef.getUTF8SortedAsUnicodeComparator(),- state.segmentSuffix, state.context);+ indexReader = new FixedGapTermsIndexReader(state);} else {final int n2 = random.nextInt(3);if (n2 == 1) {