Skip to content

Apache Lucene open-source search software

LUCENE-6208: Remove unnecessary parameter from CompoundFormat.write

Robert Muir98bd7cc831b3
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 509610b59e6..c51603f3cad 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -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
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextCompoundFormat.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextCompoundFormat.java
index b6802baaa5f..bcc42b9ed4a 100644
--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextCompoundFormat.java
+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextCompoundFormat.java
@@ -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];
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/CompoundFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/CompoundFormat.java
index 75d0c51efee..042a9b15e4c 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/CompoundFormat.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/CompoundFormat.java
@@ -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;
}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50CompoundFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50CompoundFormat.java
index 67cb01f7a14..921fdaa73b1 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50CompoundFormat.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50CompoundFormat.java
@@ -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();
diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
index 324ce96b2ab..63733171e35 100644
--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
@@ -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) {
diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyCompoundFormat.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyCompoundFormat.java
index 51186a1647f..221a1896445 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyCompoundFormat.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyCompoundFormat.java
@@ -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);
}
}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java
index 82c943f354e..b7191d0c5d3 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java
@@ -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;
}