You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/06/02 20:12:24 UTC

svn commit: r1599288 - in /lucene/dev/branches/branch_4x/lucene/core/src: java/org/apache/lucene/store/CompoundFileWriter.java test/org/apache/lucene/store/TestNRTCachingDirectory.java

Author: mikemccand
Date: Mon Jun  2 18:12:24 2014
New Revision: 1599288

URL: http://svn.apache.org/r1599288
Log:
LUCENE-5724: fix CompoundFileWriter to not suppress the incoming IOContext

Modified:
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java?rev=1599288&r1=1599287&r2=1599288&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java Mon Jun  2 18:12:24 2014
@@ -97,11 +97,11 @@ final class CompoundFileWriter implement
     
   }
   
-  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 @@ final class CompoundFileWriter implement
         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 class CompoundFileWriter implement
       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 @@ final class CompoundFileWriter implement
       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 {

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java?rev=1599288&r1=1599287&r2=1599288&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java Mon Jun  2 18:12:24 2014
@@ -123,4 +123,21 @@ public class TestNRTCachingDirectory ext
     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();
+  }
 }