mirror of https://github.com/apache/lucene.git
LUCENE-5969: correct TODOs
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5969@1633211 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
eee7825cef
commit
0f011fd97f
|
@ -50,7 +50,7 @@ import org.apache.lucene.util.Version;
|
|||
* <ul>
|
||||
* <li>Header --> {@link CodecUtil#writeHeader CodecHeader}</li>
|
||||
* <li>SegSize --> {@link DataOutput#writeInt Int32}</li>
|
||||
* <li>SegVersion --> {@link DataOutput#writeString String}</li>
|
||||
* <li>SegVersion --> {@link Version#write Version}</li>
|
||||
* <li>Files --> {@link DataOutput#writeStringSet Set<String>}</li>
|
||||
* <li>Diagnostics --> {@link DataOutput#writeStringStringMap Map<String,String>}</li>
|
||||
* <li>IsCompoundFile --> {@link DataOutput#writeByte Int8}</li>
|
||||
|
@ -61,7 +61,7 @@ import org.apache.lucene.util.Version;
|
|||
* Field Descriptions:
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>SegVersion is the code version that created the segment.</li>
|
||||
* <li>SegVersion is the code version that created the segment, written as 4 unsigned bytes (major, minor, bugfix, prerelease)</li>
|
||||
* <li>SegSize is the number of documents contained in the segment index.</li>
|
||||
* <li>IsCompoundFile records whether the segment is written as a compound file or
|
||||
* not. If this is -1, the segment is not a compound file. If it is 1, the segment
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
package org.apache.lucene.codecs.lucene50;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.lucene.codecs.CodecUtil;
|
||||
import org.apache.lucene.codecs.SegmentInfoReader;
|
||||
import org.apache.lucene.index.CorruptIndexException;
|
||||
import org.apache.lucene.index.IndexFileNames;
|
||||
import org.apache.lucene.index.SegmentInfo;
|
||||
import org.apache.lucene.store.ChecksumIndexInput;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.IOContext;
|
||||
import org.apache.lucene.util.StringHelper;
|
||||
import org.apache.lucene.util.Version;
|
||||
|
||||
/**
|
||||
* Lucene 5.0 implementation of {@link SegmentInfoReader}.
|
||||
*
|
||||
* @see Lucene50SegmentInfoFormat
|
||||
* @lucene.experimental
|
||||
*/
|
||||
public class Lucene50SegmentInfoReader extends SegmentInfoReader {
|
||||
|
||||
/** Sole constructor. */
|
||||
public Lucene50SegmentInfoReader() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SegmentInfo read(Directory dir, String segment, IOContext context) throws IOException {
|
||||
final String fileName = IndexFileNames.segmentFileName(segment, "", Lucene50SegmentInfoFormat.SI_EXTENSION);
|
||||
try (ChecksumIndexInput input = dir.openChecksumInput(fileName, context)) {
|
||||
Throwable priorE = null;
|
||||
SegmentInfo si = null;
|
||||
try {
|
||||
CodecUtil.checkHeader(input, Lucene50SegmentInfoFormat.CODEC_NAME,
|
||||
Lucene50SegmentInfoFormat.VERSION_START,
|
||||
Lucene50SegmentInfoFormat.VERSION_CURRENT);
|
||||
final Version version;
|
||||
try {
|
||||
version = Version.read(input);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
throw new CorruptIndexException("invalid version: " + iae.getMessage(), input, iae);
|
||||
}
|
||||
|
||||
final int docCount = input.readInt();
|
||||
if (docCount < 0) {
|
||||
throw new CorruptIndexException("invalid docCount: " + docCount, input);
|
||||
}
|
||||
final boolean isCompoundFile = input.readByte() == SegmentInfo.YES;
|
||||
final Map<String,String> diagnostics = input.readStringStringMap();
|
||||
final Set<String> files = input.readStringSet();
|
||||
|
||||
byte[] id = new byte[StringHelper.ID_LENGTH];
|
||||
input.readBytes(id, 0, id.length);
|
||||
|
||||
si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics, id);
|
||||
si.setFiles(files);
|
||||
} catch (Throwable exception) {
|
||||
priorE = exception;
|
||||
} finally {
|
||||
CodecUtil.checkFooter(input, priorE);
|
||||
}
|
||||
return si;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package org.apache.lucene.codecs.lucene50;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.lucene.codecs.CodecUtil;
|
||||
import org.apache.lucene.codecs.SegmentInfoWriter;
|
||||
import org.apache.lucene.index.FieldInfos;
|
||||
import org.apache.lucene.index.IndexFileNames;
|
||||
import org.apache.lucene.index.SegmentInfo;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.IOContext;
|
||||
import org.apache.lucene.store.IndexOutput;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.apache.lucene.util.StringHelper;
|
||||
import org.apache.lucene.util.Version;
|
||||
|
||||
/**
|
||||
* Lucene 5.0 implementation of {@link SegmentInfoWriter}.
|
||||
*
|
||||
* @see Lucene50SegmentInfoFormat
|
||||
* @lucene.experimental
|
||||
*/
|
||||
public class Lucene50SegmentInfoWriter extends SegmentInfoWriter {
|
||||
|
||||
/** Sole constructor. */
|
||||
public Lucene50SegmentInfoWriter() {
|
||||
}
|
||||
|
||||
/** Save a single segment's info. */
|
||||
@Override
|
||||
public void write(Directory dir, SegmentInfo si, FieldInfos fis, IOContext ioContext) throws IOException {
|
||||
final String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene50SegmentInfoFormat.SI_EXTENSION);
|
||||
si.addFile(fileName);
|
||||
|
||||
boolean success = false;
|
||||
try (IndexOutput output = dir.createOutput(fileName, ioContext)) {
|
||||
CodecUtil.writeHeader(output, Lucene50SegmentInfoFormat.CODEC_NAME, Lucene50SegmentInfoFormat.VERSION_CURRENT);
|
||||
Version version = si.getVersion();
|
||||
if (version.major < 5) {
|
||||
throw new IllegalArgumentException("invalid major version: should be >= 5 but got: " + version.major + " segment=" + si);
|
||||
}
|
||||
// Write the Lucene version that created this segment, since 3.1
|
||||
version.write(output);
|
||||
output.writeInt(si.getDocCount());
|
||||
|
||||
output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));
|
||||
output.writeStringStringMap(si.getDiagnostics());
|
||||
Set<String> files = si.files();
|
||||
for (String file : files) {
|
||||
if (!IndexFileNames.parseSegmentName(file).equals(si.name)) {
|
||||
throw new IllegalArgumentException("invalid files: expected segment=" + si.name + ", got=" + files);
|
||||
}
|
||||
}
|
||||
output.writeStringSet(files);
|
||||
byte[] id = si.getId();
|
||||
if (id.length != StringHelper.ID_LENGTH) {
|
||||
throw new IllegalArgumentException("invalid id, got=" + StringHelper.idToString(id));
|
||||
}
|
||||
output.writeBytes(id, 0, id.length);
|
||||
CodecUtil.writeFooter(output);
|
||||
success = true;
|
||||
} finally {
|
||||
if (!success) {
|
||||
// TODO: are we doing this outside of the tracking wrapper? why must SIWriter cleanup like this?
|
||||
IOUtils.deleteFilesIgnoringExceptions(si.dir, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,9 +18,13 @@ package org.apache.lucene.util;
|
|||
*/
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.lucene.store.DataInput;
|
||||
import org.apache.lucene.store.DataOutput;
|
||||
|
||||
/**
|
||||
* Use by certain classes to match version compatibility
|
||||
* across releases of Lucene.
|
||||
|
@ -457,4 +461,25 @@ public final class Version {
|
|||
public int hashCode() {
|
||||
return encodedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the version to the provided {@link DataOutput}.
|
||||
*/
|
||||
public void write(DataOutput out) throws IOException {
|
||||
out.writeByte((byte) major);
|
||||
out.writeByte((byte) minor);
|
||||
out.writeByte((byte) bugfix);
|
||||
out.writeByte((byte) prerelease);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a {@code Version} previously written with {@link #writeVersion}.
|
||||
*/
|
||||
public static Version read(DataInput in) throws IOException {
|
||||
int major = in.readByte()&0xFF;
|
||||
int minor = in.readByte()&0xFF;
|
||||
int bugfix = in.readByte()&0xFF;
|
||||
int prerelease = in.readByte()&0xFF;
|
||||
return new Version(major, minor, bugfix, prerelease);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,8 +36,8 @@ import org.apache.lucene.codecs.lucene50.Lucene50PostingsWriter;
|
|||
import org.apache.lucene.index.SegmentReadState;
|
||||
import org.apache.lucene.index.SegmentWriteState;
|
||||
|
||||
// TODO: we could make separate base class that can wrapp
|
||||
// any PostingsBaseFormat and make it ord-able...
|
||||
// TODO: we could make separate base class that can wrap
|
||||
// any PostingsFormat and make it ord-able...
|
||||
|
||||
/**
|
||||
* Customized version of {@link Lucene50PostingsFormat} that uses
|
||||
|
|
|
@ -37,8 +37,8 @@ import org.apache.lucene.codecs.lucene50.Lucene50PostingsWriter;
|
|||
import org.apache.lucene.index.SegmentReadState;
|
||||
import org.apache.lucene.index.SegmentWriteState;
|
||||
|
||||
// TODO: we could make separate base class that can wrapp
|
||||
// any PostingsBaseFormat and make it ord-able...
|
||||
// TODO: we could make separate base class that can wrap
|
||||
// any PostingsFormat and make it ord-able...
|
||||
|
||||
/**
|
||||
* Customized version of {@link Lucene50PostingsFormat} that uses
|
||||
|
|
|
@ -37,8 +37,8 @@ import org.apache.lucene.codecs.lucene50.Lucene50PostingsWriter;
|
|||
import org.apache.lucene.index.SegmentReadState;
|
||||
import org.apache.lucene.index.SegmentWriteState;
|
||||
|
||||
// TODO: we could make separate base class that can wrapp
|
||||
// any PostingsBaseFormat and make it ord-able...
|
||||
// TODO: we could make separate base class that can wrap
|
||||
// any PostingsFormat and make it ord-able...
|
||||
|
||||
/**
|
||||
* Customized version of {@link Lucene50PostingsFormat} that uses
|
||||
|
|
Loading…
Reference in New Issue