Apache Lucene open-source search software
LUCENE-5724: fix CompoundFileWriter to not suppress the incoming IOContext
Michael McCandless24d4a628c2a3
diff --git a/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java b/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.javaindex b6459ea8e73..b9f1642f288 100644--- a/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java+++ b/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java@@ -91,11 +91,11 @@ final class CompoundFileWriter implements Closeable{}- private synchronized IndexOutput getOutput() throws IOException {+ private synchronized IndexOutput getOutput(IOContext context) throws IOException {if (dataOut == null) {boolean success = false;try {- dataOut = directory.createOutput(dataFileName, IOContext.DEFAULT);+ dataOut = directory.createOutput(dataFileName, context);CodecUtil.writeHeader(dataOut, DATA_CODEC, VERSION_CURRENT);success = true;} finally {@@ -138,8 +138,10 @@ final class CompoundFileWriter implements Closeable{throw new IllegalStateException("CFS has pending open files");}closed = true;- // open the compound stream- getOutput();+ // open the compound stream; we can safely use IOContext.DEFAULT+ // here because this will only open the output if no file was+ // added to the CFS+ getOutput(IOContext.DEFAULT);assert dataOut != null;CodecUtil.writeFooter(dataOut);success = true;@@ -232,7 +234,7 @@ final class CompoundFileWriter implements Closeable{final DirectCFSIndexOutput out;if ((outputLocked = outputTaken.compareAndSet(false, true))) {- out = new DirectCFSIndexOutput(getOutput(), entry, false);+ out = new DirectCFSIndexOutput(getOutput(context), entry, false);} else {entry.dir = this.directory;out = new DirectCFSIndexOutput(directory.createOutput(name, context), entry,@@ -261,7 +263,7 @@ final class CompoundFileWriter implements Closeable{try {while (!pendingEntries.isEmpty()) {FileEntry entry = pendingEntries.poll();- copyFileEntry(getOutput(), entry);+ copyFileEntry(getOutput(new IOContext(new FlushInfo(0, entry.length))), entry);entries.put(entry.file, entry);}} finally {diff --git a/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.javaindex b56324ab2c6..8e2d9d10a01 100644--- a/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java+++ b/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java@@ -122,4 +122,21 @@ public class TestNRTCachingDirectory extends BaseDirectoryTestCase {writer.close();cachedFSDir.close();}++ // LUCENE-5724+ public void testLargeCFS() throws IOException {+ Directory dir = new NRTCachingDirectory(newFSDirectory(createTempDir()), 2.0, 25.0);+ IOContext context = new IOContext(new FlushInfo(0, 512*1024*1024));+ IndexOutput out = dir.createOutput("big.bin", context);+ byte[] bytes = new byte[512];+ for(int i=0;i<1024*1024;i++) {+ out.writeBytes(bytes, 0, bytes.length);+ }+ out.close();++ Directory cfsDir = new CompoundFileDirectory(dir, "big.cfs", context, true);+ dir.copy(cfsDir, "big.bin", "big.bin", context);+ cfsDir.close();+ dir.close();+ }}