Apache Lucene open-source search software
LUCENE-4055: use codec header instead
Robert Muir4e457c6cb89b
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosFormat.javaindex 8e5067a8a80..ee1e276676b 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosFormat.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosFormat.java@@ -18,25 +18,25 @@ package org.apache.lucene.codecs.lucene40;*/import java.io.IOException;-import java.util.Set;import org.apache.lucene.codecs.FieldInfosFormat;import org.apache.lucene.codecs.FieldInfosReader;import org.apache.lucene.codecs.FieldInfosWriter;import org.apache.lucene.index.DocValues; // javadocimport org.apache.lucene.index.DocValues.Type; // javadoc-import org.apache.lucene.index.SegmentInfo;import org.apache.lucene.store.DataOutput; // javadoc+import org.apache.lucene.util.CodecUtil; // javadoc/*** Lucene 4.0 Field Infos format.* <p>* <p>Field names are stored in the field info file, with suffix <tt>.fnm</tt>.</p>- * <p>FieldInfos (.fnm) --> FNMVersion,FieldsCount, <FieldName,FieldNumber,+ * <p>FieldInfos (.fnm) --> Header,FieldsCount, <FieldName,FieldNumber,* FieldBits,DocValuesBits,Attributes> <sup>FieldsCount</sup></p>* <p>Data types:* <ul>- * <li>FNMVersion, FieldsCount --> {@link DataOutput#writeVInt VInt}</li>+ * <li>Header --> {@link CodecUtil#checkHeader CodecHeader}</li>+ * <li>FieldsCount --> {@link DataOutput#writeVInt VInt}</li>* <li>FieldName --> {@link DataOutput#writeString String}</li>* <li>FieldBits, DocValuesBits --> {@link DataOutput#writeByte Byte}</li>* <li>FieldNumber --> {@link DataOutput#writeInt VInt}</li>@@ -45,7 +45,6 @@ import org.apache.lucene.store.DataOutput; // javadoc* </p>* Field Descriptions:* <ul>- * <li>FNMVersion is <code>Lucene40FieldInfosWriter.FORMAT_CURRENT</code>.</li>* <li>FieldsCount: the number of fields in this file.</li>* <li>FieldName: name of the field as a UTF-8 String.</li>* <li>FieldNumber: the field's number. Note that unlike previous versions ofdiff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.javaindex b396cd0a2b0..ab09da2c24c 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java@@ -18,6 +18,7 @@ import org.apache.lucene.index.DocValues;import org.apache.lucene.store.Directory;import org.apache.lucene.store.IOContext;import org.apache.lucene.store.IndexInput;+import org.apache.lucene.util.CodecUtil;/*** Licensed to the Apache Software Foundation (ASF) under one or more@@ -44,22 +45,15 @@ import org.apache.lucene.store.IndexInput;*/public class Lucene40FieldInfosReader extends FieldInfosReader {- static final int FORMAT_MINIMUM = Lucene40FieldInfosWriter.FORMAT_START;-@Overridepublic FieldInfos read(Directory directory, String segmentName, IOContext iocontext) throws IOException {final String fileName = IndexFileNames.segmentFileName(segmentName, "", Lucene40FieldInfosWriter.FIELD_INFOS_EXTENSION);IndexInput input = directory.openInput(fileName, iocontext);try {- final int format = input.readVInt();-- if (format > FORMAT_MINIMUM) {- throw new IndexFormatTooOldException(input, format, FORMAT_MINIMUM, Lucene40FieldInfosWriter.FORMAT_CURRENT);- }- if (format < Lucene40FieldInfosWriter.FORMAT_CURRENT) {- throw new IndexFormatTooNewException(input, format, FORMAT_MINIMUM, Lucene40FieldInfosWriter.FORMAT_CURRENT);- }+ CodecUtil.checkHeader(input, Lucene40FieldInfosWriter.CODEC_NAME,+ Lucene40FieldInfosWriter.FORMAT_START,+ Lucene40FieldInfosWriter.FORMAT_CURRENT);final int size = input.readVInt(); //read in the sizeFieldInfo infos[] = new FieldInfo[size];diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosWriter.javaindex f5bc7870b3d..f0a3cbe156a 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosWriter.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosWriter.java@@ -27,6 +27,7 @@ import org.apache.lucene.index.FieldInfo.IndexOptions;import org.apache.lucene.store.Directory;import org.apache.lucene.store.IOContext;import org.apache.lucene.store.IndexOutput;+import org.apache.lucene.util.CodecUtil;/*** Lucene 4.0 FieldInfos writer.@@ -39,10 +40,8 @@ public class Lucene40FieldInfosWriter extends FieldInfosWriter {/** Extension of field infos */static final String FIELD_INFOS_EXTENSION = "fnm";- // per-field codec support, records index values for fields- static final int FORMAT_START = -4;-- // whenever you add a new format, make it 1 smaller (negative version logic)!+ static final String CODEC_NAME = "Lucene40FieldInfos";+ static final int FORMAT_START = 0;static final int FORMAT_CURRENT = FORMAT_START;static final byte IS_INDEXED = 0x1;@@ -58,7 +57,7 @@ public class Lucene40FieldInfosWriter extends FieldInfosWriter {final String fileName = IndexFileNames.segmentFileName(segmentName, "", FIELD_INFOS_EXTENSION);IndexOutput output = directory.createOutput(fileName, context);try {- output.writeVInt(FORMAT_CURRENT);+ CodecUtil.writeHeader(output, CODEC_NAME, FORMAT_CURRENT);output.writeVInt(infos.size());for (FieldInfo fi : infos) {IndexOptions indexOptions = fi.getIndexOptions();diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.javaindex 0ed13292aeb..2a7a3079434 100644--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java@@ -2386,6 +2386,8 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {// only violate the codec this way if it's preflex &// shares doc stores// nocommit what to do....+ // cant we determine a file is a 3.x shared doc store file if hasSharedDocStore=true+ // and the segment prefix != info.info.name instead of this stuff?if (Lucene3xSegmentInfoFormat.getDocStoreIsCompoundFile(info.info)) {codecDocStoreFiles.add(IndexFileNames.segmentFileName(dsName, "", "cfx"));} else {