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 2015/02/28 18:16:47 UTC

svn commit: r1662967 - in /lucene/dev/trunk/lucene: ./ core/src/java/org/apache/lucene/store/ test-framework/src/java/org/apache/lucene/index/

Author: mikemccand
Date: Sat Feb 28 17:16:46 2015
New Revision: 1662967

URL: http://svn.apache.org/r1662967
Log:
LUCENE-6311: make sure IndexInput.toString confesses when it's within a compound file

Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/IndexInput.java
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NIOFSDirectory.java
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/RAMInputStream.java
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java
    lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1662967&r1=1662966&r2=1662967&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Sat Feb 28 17:16:46 2015
@@ -70,7 +70,11 @@ Bug Fixes
 * LUCENE-6001: DrillSideways hits NullPointerException for certain
   BooleanQuery searches.  (Dragan Jotannovic, jane chang via Mike
   McCandless)
-  
+
+* LUCENE-6311: Fix NIOFSDirectory and SimpleFSDirectory so that the
+  toString method of IndexInputs confess when they are from a compound
+  file. (Robert Muir, Mike McCandless)
+
 Optimizations
 
 * LUCENE-6183, LUCENE-5647: Avoid recompressing stored fields

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java?rev=1662967&r1=1662966&r2=1662967&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java Sat Feb 28 17:16:46 2015
@@ -281,10 +281,9 @@ abstract class ByteBufferIndexInput exte
     }
 
     final ByteBuffer newBuffers[] = buildSlice(buffers, offset, length);
-    final String newResourceDescription = (sliceDescription == null) ? toString() : (toString() + " [slice=" + sliceDescription + "]");
     final int ofs = (int) (offset & chunkSizeMask);
     
-    final ByteBufferIndexInput clone = newCloneInstance(newResourceDescription, newBuffers, ofs, length);
+    final ByteBufferIndexInput clone = newCloneInstance(getFullSliceDescription(sliceDescription), newBuffers, ofs, length);
     clone.isClone = true;
 
     // register the new clone in our clone list to clean it up on closing:

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/IndexInput.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/IndexInput.java?rev=1662967&r1=1662966&r2=1662967&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/IndexInput.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/IndexInput.java Sat Feb 28 17:16:46 2015
@@ -88,7 +88,17 @@ public abstract class IndexInput extends
    * The slice is seeked to the beginning.
    */
   public abstract IndexInput slice(String sliceDescription, long offset, long length) throws IOException;
-  
+
+  /** Subclasses call this to get the String for resourceDescription of a slice of this {@code IndexInput}. */
+  protected String getFullSliceDescription(String sliceDescription) {
+    if (sliceDescription == null) {
+      // Clones pass null sliceDescription:
+      return toString();
+    } else {
+      return toString() + " [slice=" + sliceDescription + "]";
+    }
+  }
+
   /**
    * Creates a random-access slice of this index input, with the given offset and length. 
    * <p>

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NIOFSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NIOFSDirectory.java?rev=1662967&r1=1662966&r2=1662967&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NIOFSDirectory.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NIOFSDirectory.java Sat Feb 28 17:16:46 2015
@@ -137,7 +137,7 @@ public class NIOFSDirectory extends FSDi
       if (offset < 0 || length < 0 || offset + length > this.length()) {
         throw new IllegalArgumentException("slice() " + sliceDescription + " out of bounds: "  + this);
       }
-      return new NIOFSIndexInput(sliceDescription, channel, off + offset, length, getBufferSize());
+      return new NIOFSIndexInput(getFullSliceDescription(sliceDescription), channel, off + offset, length, getBufferSize());
     }
 
     @Override

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/RAMInputStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/RAMInputStream.java?rev=1662967&r1=1662966&r2=1662967&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/RAMInputStream.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/RAMInputStream.java Sat Feb 28 17:16:46 2015
@@ -128,8 +128,7 @@ public class RAMInputStream extends Inde
     if (offset < 0 || length < 0 || offset + length > this.length) {
       throw new IllegalArgumentException("slice() " + sliceDescription + " out of bounds: "  + this);
     }
-    final String newResourceDescription = (sliceDescription == null) ? toString() : (toString() + " [slice=" + sliceDescription + "]");
-    return new RAMInputStream(newResourceDescription, file, offset + length) {
+    return new RAMInputStream(getFullSliceDescription(sliceDescription), file, offset + length) {
       {
         seek(0L);
       }

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java?rev=1662967&r1=1662966&r2=1662967&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java Sat Feb 28 17:16:46 2015
@@ -131,7 +131,7 @@ public class SimpleFSDirectory extends F
       if (offset < 0 || length < 0 || offset + length > this.length()) {
         throw new IllegalArgumentException("slice() " + sliceDescription + " out of bounds: "  + this);
       }
-      return new SimpleFSIndexInput(sliceDescription, channel, off + offset, length, getBufferSize());
+      return new SimpleFSIndexInput(getFullSliceDescription(sliceDescription), channel, off + offset, length, getBufferSize());
     }
 
     @Override

Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java?rev=1662967&r1=1662966&r2=1662967&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java Sat Feb 28 17:16:46 2015
@@ -765,4 +765,21 @@ public abstract class BaseCompoundFormat
   public void testMergeStability() throws Exception {
     assumeTrue("test does not work with CFS", true);
   }
+
+  // LUCENE-6311: make sure the resource name inside a compound file confesses that it's inside a compound file
+  public void testResourceNameInsideCompoundFile() throws Exception {
+    Directory dir = newDirectory();
+    String subFile = "_123.xyz";
+    createSequenceFile(dir, subFile, (byte) 0, 10);
+    
+    SegmentInfo si = newSegmentInfo(dir, "_123");
+    si.setFiles(Collections.singletonList(subFile));
+    si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
+    Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
+    IndexInput in = cfs.openInput(subFile, IOContext.DEFAULT);
+    String desc = in.toString();
+    assertTrue("resource description hides that it's inside a compound file: " + desc, desc.contains("[slice=" + subFile + "]"));
+    cfs.close();
+    dir.close();
+  }
 }