LUCENE-5969: clean up unnecessary back compat and add segment header

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5969@1628684 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-10-01 12:03:40 +00:00
parent c6c603ace5
commit 31a5763f2d
4 changed files with 23 additions and 56 deletions

View File

@ -17,13 +17,11 @@ package org.apache.lucene.codecs.blockterms;
* limitations under the License. * 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.store.IndexInput;
import org.apache.lucene.codecs.CodecUtil; import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.util.Accountable; import org.apache.lucene.util.Accountable;
import org.apache.lucene.util.Accountables; import org.apache.lucene.util.Accountables;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
@ -34,7 +32,6 @@ import org.apache.lucene.util.packed.MonotonicBlockPackedReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.io.IOException; import java.io.IOException;
@ -58,8 +55,6 @@ public class FixedGapTermsIndexReader extends TermsIndexReaderBase {
private final int packedIntsVersion; private final int packedIntsVersion;
private final int blocksize; private final int blocksize;
private final Comparator<BytesRef> termComp;
private final static int PAGED_BYTES_BITS = 15; private final static int PAGED_BYTES_BITS = 15;
// all fields share this single logical byte[] // all fields share this single logical byte[]
@ -67,28 +62,24 @@ public class FixedGapTermsIndexReader extends TermsIndexReaderBase {
final HashMap<String,FieldIndexData> fields = new HashMap<>(); final HashMap<String,FieldIndexData> fields = new HashMap<>();
// start of the field info data public FixedGapTermsIndexReader(SegmentReadState state) throws IOException {
private long dirOffset;
private int version;
public FixedGapTermsIndexReader(Directory dir, FieldInfos fieldInfos, String segment, Comparator<BytesRef> termComp, String segmentSuffix, IOContext context)
throws IOException {
final PagedBytes termBytes = new PagedBytes(PAGED_BYTES_BITS); 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; boolean success = false;
try { 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(); indexInterval = in.readVInt();
if (indexInterval < 1) { if (indexInterval < 1) {
@ -97,7 +88,7 @@ public class FixedGapTermsIndexReader extends TermsIndexReaderBase {
packedIntsVersion = in.readVInt(); packedIntsVersion = in.readVInt();
blocksize = in.readVInt(); blocksize = in.readVInt();
seekDir(in, dirOffset); seekDir(in);
// Read directory // Read directory
final int numFields = in.readVInt(); final int numFields = in.readVInt();
@ -118,7 +109,7 @@ public class FixedGapTermsIndexReader extends TermsIndexReaderBase {
if (packedIndexStart < indexStart) { if (packedIndexStart < indexStart) {
throw new CorruptIndexException("invalid packedIndexStart: " + packedIndexStart + " indexStart: " + indexStart + "numIndexTerms: " + numIndexTerms, in); 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)); FieldIndexData previous = fields.put(fieldInfo.name, new FieldIndexData(in, termBytes, indexStart, termsStart, packedIndexStart, packedOffsetsStart, numIndexTerms));
if (previous != null) { if (previous != null) {
throw new CorruptIndexException("duplicate field: " + fieldInfo.name, in); 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 class IndexEnum extends FieldIndexEnum {
private final FieldIndexData fieldIndex; private final FieldIndexData fieldIndex;
private final BytesRef term = new BytesRef(); 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); final int length = (int) (fieldIndex.termOffsets.get(1+mid) - offset);
termBytesReader.fillSlice(term, fieldIndex.termBytesStart + offset, length); termBytesReader.fillSlice(term, fieldIndex.termBytesStart + offset, length);
int delta = termComp.compare(target, term); int delta = target.compareTo(term);
if (delta < 0) { if (delta < 0) {
hi = mid - 1; hi = mid - 1;
} else if (delta > 0) { } else if (delta > 0) {
@ -301,13 +287,9 @@ public class FixedGapTermsIndexReader extends TermsIndexReaderBase {
@Override @Override
public void close() throws IOException {} public void close() throws IOException {}
private void seekDir(IndexInput input, long dirOffset) throws IOException { private void seekDir(IndexInput input) throws IOException {
if (version >= FixedGapTermsIndexWriter.VERSION_CHECKSUM) { input.seek(input.length() - CodecUtil.footerLength() - 8);
input.seek(input.length() - CodecUtil.footerLength() - 8); long dirOffset = input.readLong();
} else {
input.seek(input.length() - 8);
}
dirOffset = input.readLong();
input.seek(dirOffset); input.seek(dirOffset);
} }

View File

@ -49,12 +49,9 @@ public class FixedGapTermsIndexWriter extends TermsIndexWriterBase {
/** Extension of terms index file */ /** Extension of terms index file */
static final String TERMS_INDEX_EXTENSION = "tii"; static final String TERMS_INDEX_EXTENSION = "tii";
final static String CODEC_NAME = "SIMPLE_STANDARD_TERMS_INDEX"; final static String CODEC_NAME = "FixedGapTermsIndex";
final static int VERSION_START = 0; final static int VERSION_START = 4;
final static int VERSION_APPEND_ONLY = 1; final static int VERSION_CURRENT = VERSION_START;
final static int VERSION_MONOTONIC_ADDRESSING = 2;
final static int VERSION_CHECKSUM = 3;
final static int VERSION_CURRENT = VERSION_CHECKSUM;
final static int BLOCKSIZE = 4096; final static int BLOCKSIZE = 4096;
final private int termIndexInterval; final private int termIndexInterval;
@ -75,7 +72,7 @@ public class FixedGapTermsIndexWriter extends TermsIndexWriterBase {
out = state.directory.createOutput(indexFileName, state.context); out = state.directory.createOutput(indexFileName, state.context);
boolean success = false; boolean success = false;
try { try {
writeHeader(out); CodecUtil.writeSegmentHeader(out, CODEC_NAME, VERSION_CURRENT, state.segmentInfo.getId(), state.segmentSuffix);
out.writeVInt(termIndexInterval); out.writeVInt(termIndexInterval);
out.writeVInt(PackedInts.VERSION_CURRENT); out.writeVInt(PackedInts.VERSION_CURRENT);
out.writeVInt(BLOCKSIZE); 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);
}
@Override @Override
public FieldWriter addField(FieldInfo field, long termsFilePointer) { public FieldWriter addField(FieldInfo field, long termsFilePointer) {

View File

@ -100,11 +100,7 @@ public final class Lucene41WithOrds extends PostingsFormat {
boolean success = false; boolean success = false;
try { try {
indexReader = new FixedGapTermsIndexReader(state.directory, indexReader = new FixedGapTermsIndexReader(state);
state.fieldInfos,
state.segmentInfo.name,
BytesRef.getUTF8SortedAsUnicodeComparator(),
state.segmentSuffix, state.context);
success = true; success = true;
} finally { } finally {
if (!success) { if (!success) {

View File

@ -340,11 +340,7 @@ public final class MockRandomPostingsFormat extends PostingsFormat {
if (LuceneTestCase.VERBOSE) { if (LuceneTestCase.VERBOSE) {
System.out.println("MockRandomCodec: fixed-gap terms index"); System.out.println("MockRandomCodec: fixed-gap terms index");
} }
indexReader = new FixedGapTermsIndexReader(state.directory, indexReader = new FixedGapTermsIndexReader(state);
state.fieldInfos,
state.segmentInfo.name,
BytesRef.getUTF8SortedAsUnicodeComparator(),
state.segmentSuffix, state.context);
} else { } else {
final int n2 = random.nextInt(3); final int n2 = random.nextInt(3);
if (n2 == 1) { if (n2 == 1) {