LUCENE-6208: Remove unnecessary parameter from CompoundFormat.write

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1655520 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2015-01-29 03:40:15 +00:00
parent 65fdeb7900
commit 98bd7cc831
7 changed files with 42 additions and 31 deletions

View File

@ -48,7 +48,8 @@ Optimizations
API Changes
* LUCENE-6204: Remove CompoundFileFormat.files(). (Robert Muir)
* LUCENE-6204, LUCENE-6208: Simplify CompoundFormat: remove files()
and remove files parameter to write(). (Robert Muir)
Other

View File

@ -156,11 +156,11 @@ public class SimpleTextCompoundFormat extends CompoundFormat {
}
@Override
public void write(Directory dir, SegmentInfo si, Collection<String> files, IOContext context) throws IOException {
public void write(Directory dir, SegmentInfo si, IOContext context) throws IOException {
String dataFile = IndexFileNames.segmentFileName(si.name, "", DATA_EXTENSION);
int numFiles = files.size();
String names[] = files.toArray(new String[numFiles]);
int numFiles = si.files().size();
String names[] = si.files().toArray(new String[numFiles]);
Arrays.sort(names);
long startOffsets[] = new long[numFiles];
long endOffsets[] = new long[numFiles];

View File

@ -18,7 +18,6 @@ package org.apache.lucene.codecs;
*/
import java.io.IOException;
import java.util.Collection;
import org.apache.lucene.index.SegmentInfo;
import org.apache.lucene.store.Directory;
@ -44,7 +43,7 @@ public abstract class CompoundFormat {
public abstract Directory getCompoundReader(Directory dir, SegmentInfo si, IOContext context) throws IOException;
/**
* Packs the provided files into a compound format.
* Packs the provided segment's files into a compound format.
*/
public abstract void write(Directory dir, SegmentInfo si, Collection<String> files, IOContext context) throws IOException;
public abstract void write(Directory dir, SegmentInfo si, IOContext context) throws IOException;
}

View File

@ -72,7 +72,7 @@ public final class Lucene50CompoundFormat extends CompoundFormat {
}
@Override
public void write(Directory dir, SegmentInfo si, Collection<String> files, IOContext context) throws IOException {
public void write(Directory dir, SegmentInfo si, IOContext context) throws IOException {
String dataFile = IndexFileNames.segmentFileName(si.name, "", DATA_EXTENSION);
String entriesFile = IndexFileNames.segmentFileName(si.name, "", ENTRIES_EXTENSION);
@ -82,8 +82,8 @@ public final class Lucene50CompoundFormat extends CompoundFormat {
CodecUtil.writeIndexHeader(entries, ENTRY_CODEC, VERSION_CURRENT, si.getId(), "");
// write number of files
entries.writeVInt(files.size());
for (String file : files) {
entries.writeVInt(si.files().size());
for (String file : si.files()) {
// write bytes for file
long startOffset = data.getFilePointer();

View File

@ -4543,12 +4543,10 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
if (infoStream.isEnabled("IW")) {
infoStream.message("IW", "create compound file");
}
// Now merge all added files
Collection<String> files = info.files();
// Now merge all added files
boolean success = false;
try {
info.getCodec().compoundFormat().write(directory, info, files, context);
info.getCodec().compoundFormat().write(directory, info, context);
success = true;
} finally {
if (!success) {

View File

@ -18,7 +18,6 @@ package org.apache.lucene.codecs.cranky;
*/
import java.io.IOException;
import java.util.Collection;
import java.util.Random;
import org.apache.lucene.codecs.CompoundFormat;
@ -41,10 +40,10 @@ class CrankyCompoundFormat extends CompoundFormat {
}
@Override
public void write(Directory dir, SegmentInfo si, Collection<String> files, IOContext context) throws IOException {
public void write(Directory dir, SegmentInfo si, IOContext context) throws IOException {
if (random.nextInt(100) == 0) {
throw new IOException("Fake IOException from CompoundFormat.write()");
}
delegate.write(dir, si, files, context);
delegate.write(dir, si, context);
}
}

View File

@ -55,7 +55,8 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest
Directory dir = newDirectory();
SegmentInfo si = newSegmentInfo(dir, "_123");
si.getCodec().compoundFormat().write(dir, si, Collections.<String>emptyList(), IOContext.DEFAULT);
si.setFiles(Collections.emptySet());
si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
assertEquals(0, cfs.listAll().length);
cfs.close();
@ -74,7 +75,8 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest
createSequenceFile(dir, testfile, (byte) 0, data[i]);
SegmentInfo si = newSegmentInfo(dir, "_" + i);
si.getCodec().compoundFormat().write(dir, si, Collections.singleton(testfile), IOContext.DEFAULT);
si.setFiles(Collections.singleton(testfile));
si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
IndexInput expected = dir.openInput(testfile, newIOContext(random()));
@ -98,7 +100,8 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest
createSequenceFile(dir, files[1], (byte) 0, 114);
SegmentInfo si = newSegmentInfo(dir, "_123");
si.getCodec().compoundFormat().write(dir, si, Arrays.asList(files), IOContext.DEFAULT);
si.setFiles(Arrays.asList(files));
si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
for (String file : files) {
@ -124,7 +127,8 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest
out.close();
SegmentInfo si = newSegmentInfo(dir, "_123");
si.getCodec().compoundFormat().write(dir, si, Collections.singleton(testfile), IOContext.DEFAULT);
si.setFiles(Collections.singleton(testfile));
si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
assertEquals(1, cfs.listAll().length);
cfs.close();
@ -149,7 +153,8 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest
out.close();
SegmentInfo si = newSegmentInfo(dir, "_123");
si.getCodec().compoundFormat().write(dir, si, Collections.singleton(testfile), myContext);
si.setFiles(Collections.singleton(testfile));
si.getCodec().compoundFormat().write(dir, si, myContext);
dir.close();
}
@ -168,7 +173,8 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest
out.close();
SegmentInfo si = newSegmentInfo(dir, "_123");
si.getCodec().compoundFormat().write(dir, si, Collections.singleton(testfile), context);
si.setFiles(Collections.singleton(testfile));
si.getCodec().compoundFormat().write(dir, si, context);
dir.close();
}
@ -218,7 +224,8 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest
Directory dir = newDirectory();
SegmentInfo si = newSegmentInfo(dir, "_123");
si.getCodec().compoundFormat().write(dir, si, Collections.<String>emptyList(), IOContext.DEFAULT);
si.setFiles(Collections.emptyList());
si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
try {
cfs.createOutput("bogus", IOContext.DEFAULT);
@ -240,7 +247,8 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest
out.close();
SegmentInfo si = newSegmentInfo(dir, "_123");
si.getCodec().compoundFormat().write(dir, si, Collections.<String>emptyList(), IOContext.DEFAULT);
si.setFiles(Collections.emptyList());
si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
try {
cfs.deleteFile(testfile);
@ -262,7 +270,8 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest
out.close();
SegmentInfo si = newSegmentInfo(dir, "_123");
si.getCodec().compoundFormat().write(dir, si, Collections.<String>emptyList(), IOContext.DEFAULT);
si.setFiles(Collections.emptyList());
si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
try {
cfs.renameFile(testfile, "bogus");
@ -284,7 +293,8 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest
out.close();
SegmentInfo si = newSegmentInfo(dir, "_123");
si.getCodec().compoundFormat().write(dir, si, Collections.<String>emptyList(), IOContext.DEFAULT);
si.setFiles(Collections.emptyList());
si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
try {
cfs.sync(Collections.singleton(testfile));
@ -306,7 +316,8 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest
out.close();
SegmentInfo si = newSegmentInfo(dir, "_123");
si.getCodec().compoundFormat().write(dir, si, Collections.<String>emptyList(), IOContext.DEFAULT);
si.setFiles(Collections.emptyList());
si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
try {
cfs.makeLock("foobar");
@ -345,7 +356,8 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest
String files[] = dir.listAll();
SegmentInfo si = newSegmentInfo(dir, "_123");
si.getCodec().compoundFormat().write(dir, si, Arrays.asList(files), IOContext.DEFAULT);
si.setFiles(Arrays.asList(files));
si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
for (int i = 0; i < files.length; i++) {
@ -376,7 +388,8 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest
assertEquals(0, dir.getFileHandleCount());
SegmentInfo si = newSegmentInfo(dir, "_123");
si.getCodec().compoundFormat().write(dir, si, Arrays.asList(dir.listAll()), IOContext.DEFAULT);
si.setFiles(Arrays.asList(dir.listAll()));
si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
final IndexInput[] ins = new IndexInput[FILE_COUNT];
@ -729,7 +742,8 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest
}
SegmentInfo si = newSegmentInfo(dir, "_123");
si.getCodec().compoundFormat().write(dir, si, files, IOContext.DEFAULT);
si.setFiles(files);
si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
return cfs;
}