mirror of https://github.com/apache/lucene.git
LUCENE-5724: fix CompoundFileWriter to not suppress the incoming IOContext
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1599291 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b875c63fe0
commit
24d4a628c2
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue