LUCENE-5969: don't use indexfilenames in these codecs

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5969@1629105 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-10-03 02:46:23 +00:00
parent 5893b1da29
commit 0dbccd144f
9 changed files with 33 additions and 24 deletions

View File

@ -36,13 +36,13 @@ public final class Lucene40CompoundFormat extends CompoundFormat {
@Override
public Directory getCompoundReader(Directory dir, SegmentInfo si, IOContext context) throws IOException {
String fileName = IndexFileNames.segmentFileName(si.name, "", IndexFileNames.COMPOUND_FILE_EXTENSION);
String fileName = IndexFileNames.segmentFileName(si.name, "", COMPOUND_FILE_EXTENSION);
return new Lucene40CompoundReader(dir, fileName, context, false);
}
@Override
public void write(Directory dir, SegmentInfo si, Collection<String> files, CheckAbort checkAbort, IOContext context) throws IOException {
String fileName = IndexFileNames.segmentFileName(si.name, "", IndexFileNames.COMPOUND_FILE_EXTENSION);
String fileName = IndexFileNames.segmentFileName(si.name, "", COMPOUND_FILE_EXTENSION);
try (Directory cfs = new Lucene40CompoundReader(dir, fileName, context, true)) {
for (String file : files) {
dir.copy(cfs, file, file, context);
@ -50,4 +50,9 @@ public final class Lucene40CompoundFormat extends CompoundFormat {
}
}
}
/** Extension of compound file */
static final String COMPOUND_FILE_EXTENSION = "cfs";
/** Extension of compound file entries */
static final String COMPOUND_FILE_ENTRIES_EXTENSION = "cfe";
}

View File

@ -109,7 +109,7 @@ final class Lucene40CompoundReader extends BaseDirectory {
try {
final String entriesFileName = IndexFileNames.segmentFileName(
IndexFileNames.stripExtension(name), "",
IndexFileNames.COMPOUND_FILE_ENTRIES_EXTENSION);
Lucene40CompoundFormat.COMPOUND_FILE_ENTRIES_EXTENSION);
entriesStream = dir.openChecksumInput(entriesFileName, IOContext.READONCE);
version = CodecUtil.checkHeader(entriesStream, Lucene40CompoundWriter.ENTRY_CODEC, Lucene40CompoundWriter.VERSION_START, Lucene40CompoundWriter.VERSION_CURRENT);
final int numEntries = entriesStream.readVInt();

View File

@ -91,7 +91,7 @@ final class Lucene40CompoundWriter implements Closeable{
directory = dir;
entryTableName = IndexFileNames.segmentFileName(
IndexFileNames.stripExtension(name), "",
IndexFileNames.COMPOUND_FILE_ENTRIES_EXTENSION);
Lucene40CompoundFormat.COMPOUND_FILE_ENTRIES_EXTENSION);
dataFileName = name;
}

View File

@ -50,7 +50,7 @@ public class Lucene40DocValuesFormat extends DocValuesFormat {
public final DocValuesProducer fieldsProducer(SegmentReadState state) throws IOException {
String filename = IndexFileNames.segmentFileName(state.segmentInfo.name,
"dv",
IndexFileNames.COMPOUND_FILE_EXTENSION);
Lucene40CompoundFormat.COMPOUND_FILE_EXTENSION);
return new Lucene40DocValuesReader(state, filename, Lucene40FieldInfosReader.LEGACY_DV_TYPE_KEY);
}

View File

@ -45,7 +45,7 @@ public class Lucene40NormsFormat extends NormsFormat {
public NormsProducer normsProducer(SegmentReadState state) throws IOException {
String filename = IndexFileNames.segmentFileName(state.segmentInfo.name,
"nrm",
IndexFileNames.COMPOUND_FILE_EXTENSION);
Lucene40CompoundFormat.COMPOUND_FILE_EXTENSION);
return new Lucene40NormsReader(state, filename);
}
}

View File

@ -34,7 +34,7 @@ public final class Lucene40RWDocValuesFormat extends Lucene40DocValuesFormat {
public DocValuesConsumer fieldsConsumer(SegmentWriteState state) throws IOException {
String filename = IndexFileNames.segmentFileName(state.segmentInfo.name,
"dv",
IndexFileNames.COMPOUND_FILE_EXTENSION);
Lucene40CompoundFormat.COMPOUND_FILE_EXTENSION);
return new Lucene40DocValuesWriter(state, filename, Lucene40FieldInfosReader.LEGACY_DV_TYPE_KEY);
}
}

View File

@ -35,7 +35,7 @@ public final class Lucene40RWNormsFormat extends Lucene40NormsFormat {
public NormsConsumer normsConsumer(SegmentWriteState state) throws IOException {
String filename = IndexFileNames.segmentFileName(state.segmentInfo.name,
"nrm",
IndexFileNames.COMPOUND_FILE_EXTENSION);
Lucene40CompoundFormat.COMPOUND_FILE_EXTENSION);
final Lucene40DocValuesWriter impl = new Lucene40DocValuesWriter(state, filename, Lucene40FieldInfosReader.LEGACY_NORM_TYPE_KEY);
return new NormsConsumer() {
@Override

View File

@ -65,14 +65,13 @@ public final class Lucene50CompoundFormat extends CompoundFormat {
@Override
public Directory getCompoundReader(Directory dir, SegmentInfo si, IOContext context) throws IOException {
String fileName = IndexFileNames.segmentFileName(si.name, "", IndexFileNames.COMPOUND_FILE_EXTENSION);
return new Lucene50CompoundReader(si.getId(), dir, fileName, context);
return new Lucene50CompoundReader(dir, si, context);
}
@Override
public void write(Directory dir, SegmentInfo si, Collection<String> files, CheckAbort checkAbort, IOContext context) throws IOException {
String dataFile = IndexFileNames.segmentFileName(si.name, "", IndexFileNames.COMPOUND_FILE_EXTENSION);
String entriesFile = IndexFileNames.segmentFileName(si.name, "", IndexFileNames.COMPOUND_FILE_ENTRIES_EXTENSION);
String dataFile = IndexFileNames.segmentFileName(si.name, "", DATA_EXTENSION);
String entriesFile = IndexFileNames.segmentFileName(si.name, "", ENTRIES_EXTENSION);
try (IndexOutput data = dir.createOutput(dataFile, context);
IndexOutput entries = dir.createOutput(entriesFile, context)) {
@ -105,6 +104,11 @@ public final class Lucene50CompoundFormat extends CompoundFormat {
}
}
/** Extension of compound file */
static final String DATA_EXTENSION = "cfs";
/** Extension of compound file entries */
static final String ENTRIES_EXTENSION = "cfe";
static final String DATA_CODEC = "Lucene50CompoundData";
static final String ENTRY_CODEC = "Lucene50CompoundEntries";
static final int VERSION_START = 0;

View File

@ -20,6 +20,7 @@ package org.apache.lucene.codecs.lucene50;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.index.SegmentInfo;
import org.apache.lucene.store.BaseDirectory;
import org.apache.lucene.store.ChecksumIndexInput;
import org.apache.lucene.store.Directory;
@ -51,7 +52,7 @@ final class Lucene50CompoundReader extends BaseDirectory {
}
private final Directory directory;
private final String fileName;
private final String segmentName;
private final Map<String,FileEntry> entries;
private final IndexInput handle;
private int version;
@ -59,14 +60,16 @@ final class Lucene50CompoundReader extends BaseDirectory {
/**
* Create a new CompoundFileDirectory.
*/
public Lucene50CompoundReader(byte[] segmentID, Directory directory, String fileName, IOContext context) throws IOException {
public Lucene50CompoundReader(Directory directory, SegmentInfo si, IOContext context) throws IOException {
this.directory = directory;
this.fileName = fileName;
this.entries = readEntries(segmentID, directory, fileName);
this.segmentName = si.name;
String dataFileName = IndexFileNames.segmentFileName(segmentName, "", Lucene50CompoundFormat.DATA_EXTENSION);
String entriesFileName = IndexFileNames.segmentFileName(segmentName, "", Lucene50CompoundFormat.ENTRIES_EXTENSION);
this.entries = readEntries(si.getId(), directory, entriesFileName);
boolean success = false;
handle = directory.openInput(fileName, context);
handle = directory.openInput(dataFileName, context);
try {
CodecUtil.checkSegmentHeader(handle, Lucene50CompoundFormat.DATA_CODEC, version, version, segmentID, "");
CodecUtil.checkSegmentHeader(handle, Lucene50CompoundFormat.DATA_CODEC, version, version, si.getId(), "");
// NOTE: data file is too costly to verify checksum against all the bytes on open,
// but for now we at least verify proper structure of the checksum footer: which looks
@ -83,10 +86,8 @@ final class Lucene50CompoundReader extends BaseDirectory {
}
/** Helper method that reads CFS entries from an input stream */
private final Map<String, FileEntry> readEntries(byte[] segmentID, Directory dir, String name) throws IOException {
private final Map<String, FileEntry> readEntries(byte[] segmentID, Directory dir, String entriesFileName) throws IOException {
Map<String,FileEntry> mapping = null;
final String entriesFileName = IndexFileNames.segmentFileName(IndexFileNames.stripExtension(name), "",
IndexFileNames.COMPOUND_FILE_ENTRIES_EXTENSION);
try (ChecksumIndexInput entriesStream = dir.openChecksumInput(entriesFileName, IOContext.READONCE)) {
Throwable priorE = null;
try {
@ -138,9 +139,8 @@ final class Lucene50CompoundReader extends BaseDirectory {
String[] res = entries.keySet().toArray(new String[entries.size()]);
// Add the segment name
String seg = IndexFileNames.parseSegmentName(fileName);
for (int i = 0; i < res.length; i++) {
res[i] = seg + res[i];
res[i] = segmentName + res[i];
}
return res;
}
@ -188,6 +188,6 @@ final class Lucene50CompoundReader extends BaseDirectory {
@Override
public String toString() {
return "CompoundFileDirectory(file=\"" + fileName + "\" in dir=" + directory + ")";
return "CompoundFileDirectory(segment=\"" + segmentName + "\" in dir=" + directory + ")";
}
}