LUCENE-4055: use codec header instead

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4055@1342219 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-05-24 12:19:04 +00:00
parent 7703ce22bd
commit 4e457c6cb8
4 changed files with 14 additions and 20 deletions

View File

@ -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; // javadoc
import 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) --&gt; FNMVersion,FieldsCount, &lt;FieldName,FieldNumber,
* <p>FieldInfos (.fnm) --&gt; Header,FieldsCount, &lt;FieldName,FieldNumber,
* FieldBits,DocValuesBits,Attributes&gt; <sup>FieldsCount</sup></p>
* <p>Data types:
* <ul>
* <li>FNMVersion, FieldsCount --&gt; {@link DataOutput#writeVInt VInt}</li>
* <li>Header --&gt; {@link CodecUtil#checkHeader CodecHeader}</li>
* <li>FieldsCount --&gt; {@link DataOutput#writeVInt VInt}</li>
* <li>FieldName --&gt; {@link DataOutput#writeString String}</li>
* <li>FieldBits, DocValuesBits --&gt; {@link DataOutput#writeByte Byte}</li>
* <li>FieldNumber --&gt; {@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 of

View File

@ -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;
@Override
public 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 size
FieldInfo infos[] = new FieldInfo[size];

View File

@ -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();

View File

@ -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 {