blob: d633b4b10b54db52e7416d0d43de5b3d878a67d4 [file] [log] [blame]
Index: lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java (revision 1598971)
+++ lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java (working copy)
@@ -123,4 +123,21 @@
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();
+ }
}
Index: lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java (revision 1598971)
+++ lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java (working copy)
@@ -97,11 +97,11 @@
}
- 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 {
@@ -144,8 +144,10 @@
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;
@@ -238,7 +240,7 @@
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,
@@ -267,7 +269,7 @@
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 {