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:16:57 UTC

svn commit: r1599291 - in /lucene/dev/trunk: ./ lucene/ lucene/core/ lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java

Author: mikemccand
Date: Mon Jun  2 18:16:56 2014
New Revision: 1599291

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

Modified:
    lucene/dev/trunk/   (props changed)
    lucene/dev/trunk/lucene/   (props changed)
    lucene/dev/trunk/lucene/core/   (props changed)
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java?rev=1599291&r1=1599290&r2=1599291&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java Mon Jun  2 18:16:56 2014
@@ -91,11 +91,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 {
@@ -138,8 +138,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;
@@ -232,7 +234,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,
@@ -261,7 +263,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/trunk/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java?rev=1599291&r1=1599290&r2=1599291&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java Mon Jun  2 18:16:56 2014
@@ -122,4 +122,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();
+  }
 }