mirror of https://github.com/apache/lucene.git
LUCENE-6311: make sure IndexInput.toString confesses when it's within a compound file
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1662967 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
99a16fc2dc
commit
f4011cfc51
|
@ -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
|
||||
|
|
|
@ -281,10 +281,9 @@ abstract class ByteBufferIndexInput extends IndexInput implements RandomAccessIn
|
|||
}
|
||||
|
||||
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:
|
||||
|
|
|
@ -88,7 +88,17 @@ public abstract class IndexInput extends DataInput implements Cloneable,Closeabl
|
|||
* 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>
|
||||
|
|
|
@ -137,7 +137,7 @@ public class NIOFSDirectory extends FSDirectory {
|
|||
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
|
||||
|
|
|
@ -128,8 +128,7 @@ public class RAMInputStream extends IndexInput implements Cloneable {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ public class SimpleFSDirectory extends FSDirectory {
|
|||
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
|
||||
|
|
|
@ -765,4 +765,21 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue