mirror of https://github.com/apache/lucene.git
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:
parent
65fdeb7900
commit
98bd7cc831
|
@ -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
|
||||
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue