mirror of https://github.com/apache/lucene.git
LUCENE-3539: try to include resource desc (file path for Dir impls based on file system) when we throw IOExc, for better transparency/debugging
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1197690 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fa6500fa6c
commit
f014029aa5
|
@ -245,6 +245,7 @@ public class DirectIOLinuxDirectory extends FSDirectory {
|
||||||
|
|
||||||
public DirectIOLinuxIndexInput(File path, int bufferSize) throws IOException {
|
public DirectIOLinuxIndexInput(File path, int bufferSize) throws IOException {
|
||||||
// TODO make use of IOContext
|
// TODO make use of IOContext
|
||||||
|
super("DirectIOLinuxIndexInput(path=\"" + path.getPath() + "\")");
|
||||||
FileDescriptor fd = NativePosixUtil.open_direct(path.toString(), true);
|
FileDescriptor fd = NativePosixUtil.open_direct(path.toString(), true);
|
||||||
fis = new FileInputStream(fd);
|
fis = new FileInputStream(fd);
|
||||||
channel = fis.getChannel();
|
channel = fis.getChannel();
|
||||||
|
@ -259,6 +260,7 @@ public class DirectIOLinuxDirectory extends FSDirectory {
|
||||||
|
|
||||||
// for clone
|
// for clone
|
||||||
public DirectIOLinuxIndexInput(DirectIOLinuxIndexInput other) throws IOException {
|
public DirectIOLinuxIndexInput(DirectIOLinuxIndexInput other) throws IOException {
|
||||||
|
super(other.toString());
|
||||||
this.fis = null;
|
this.fis = null;
|
||||||
channel = other.channel;
|
channel = other.channel;
|
||||||
this.bufferSize = other.bufferSize;
|
this.bufferSize = other.bufferSize;
|
||||||
|
@ -308,7 +310,7 @@ public class DirectIOLinuxDirectory extends FSDirectory {
|
||||||
try {
|
try {
|
||||||
return channel.size();
|
return channel.size();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new RuntimeException(ioe);
|
throw new RuntimeException("IOException during length(): " + this, ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,9 +333,14 @@ public class DirectIOLinuxDirectory extends FSDirectory {
|
||||||
bufferPos = 0;
|
bufferPos = 0;
|
||||||
assert (filePos & ALIGN_NOT_MASK) == filePos : "filePos=" + filePos + " anded=" + (filePos & ALIGN_NOT_MASK);
|
assert (filePos & ALIGN_NOT_MASK) == filePos : "filePos=" + filePos + " anded=" + (filePos & ALIGN_NOT_MASK);
|
||||||
//System.out.println("X refill filePos=" + filePos);
|
//System.out.println("X refill filePos=" + filePos);
|
||||||
int n = channel.read(buffer, filePos);
|
int n;
|
||||||
|
try {
|
||||||
|
n = channel.read(buffer, filePos);
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
throw new IOException(ioe.getMessage() + ": " + this, ioe);
|
||||||
|
}
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
throw new IOException("eof");
|
throw new IOException("eof: " + this);
|
||||||
}
|
}
|
||||||
buffer.rewind();
|
buffer.rewind();
|
||||||
}
|
}
|
||||||
|
@ -365,7 +372,7 @@ public class DirectIOLinuxDirectory extends FSDirectory {
|
||||||
try {
|
try {
|
||||||
return new DirectIOLinuxIndexInput(this);
|
return new DirectIOLinuxIndexInput(this);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new RuntimeException(ioe);
|
throw new RuntimeException("IOException during clone: " + this, ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.lucene.store;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.EOFException;
|
||||||
|
|
||||||
import org.apache.lucene.store.Directory; // javadoc
|
import org.apache.lucene.store.Directory; // javadoc
|
||||||
import org.apache.lucene.store.NativeFSLockFactory; // javadoc
|
import org.apache.lucene.store.NativeFSLockFactory; // javadoc
|
||||||
|
@ -80,7 +81,7 @@ public class WindowsDirectory extends FSDirectory {
|
||||||
boolean isOpen;
|
boolean isOpen;
|
||||||
|
|
||||||
public WindowsIndexInput(File file, int bufferSize) throws IOException {
|
public WindowsIndexInput(File file, int bufferSize) throws IOException {
|
||||||
super(bufferSize);
|
super("WindowsIndexInput(path=\"" + file.getPath() + "\")", bufferSize);
|
||||||
fd = WindowsDirectory.open(file.getPath());
|
fd = WindowsDirectory.open(file.getPath());
|
||||||
length = WindowsDirectory.length(fd);
|
length = WindowsDirectory.length(fd);
|
||||||
isOpen = true;
|
isOpen = true;
|
||||||
|
@ -88,8 +89,16 @@ public class WindowsDirectory extends FSDirectory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void readInternal(byte[] b, int offset, int length) throws IOException {
|
protected void readInternal(byte[] b, int offset, int length) throws IOException {
|
||||||
if (WindowsDirectory.read(fd, b, offset, length, getFilePointer()) != length)
|
int bytesRead;
|
||||||
throw new IOException("Read past EOF");
|
try {
|
||||||
|
bytesRead = WindowsDirectory.read(fd, b, offset, length, getFilePointer());
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
throw new IOException(ioe.getMessage() + ": " + this, ioe);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bytesRead != length) {
|
||||||
|
throw new EOFException("Read past EOF: " + this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -650,10 +650,10 @@ public final class FieldInfos implements Iterable<FieldInfo> {
|
||||||
format = input.readVInt();
|
format = input.readVInt();
|
||||||
|
|
||||||
if (format > FORMAT_MINIMUM) {
|
if (format > FORMAT_MINIMUM) {
|
||||||
throw new IndexFormatTooOldException(fileName, format, FORMAT_MINIMUM, FORMAT_CURRENT);
|
throw new IndexFormatTooOldException(input, format, FORMAT_MINIMUM, FORMAT_CURRENT);
|
||||||
}
|
}
|
||||||
if (format < FORMAT_CURRENT) {
|
if (format < FORMAT_CURRENT) {
|
||||||
throw new IndexFormatTooNewException(fileName, format, FORMAT_MINIMUM, FORMAT_CURRENT);
|
throw new IndexFormatTooNewException(input, format, FORMAT_MINIMUM, FORMAT_CURRENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
final int size = input.readVInt(); //read in the size
|
final int size = input.readVInt(); //read in the size
|
||||||
|
@ -675,7 +675,7 @@ public final class FieldInfos implements Iterable<FieldInfo> {
|
||||||
if (format <= FORMAT_OMIT_POSITIONS) {
|
if (format <= FORMAT_OMIT_POSITIONS) {
|
||||||
indexOptions = IndexOptions.DOCS_AND_FREQS;
|
indexOptions = IndexOptions.DOCS_AND_FREQS;
|
||||||
} else {
|
} else {
|
||||||
throw new CorruptIndexException("Corrupt fieldinfos, OMIT_POSITIONS set but format=" + format);
|
throw new CorruptIndexException("Corrupt fieldinfos, OMIT_POSITIONS set but format=" + format + " (resource: " + input + ")");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
|
indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
|
||||||
|
@ -745,7 +745,7 @@ public final class FieldInfos implements Iterable<FieldInfo> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.getFilePointer() != input.length()) {
|
if (input.getFilePointer() != input.length()) {
|
||||||
throw new CorruptIndexException("did not read all bytes from file \"" + fileName + "\": read " + input.getFilePointer() + " vs size " + input.length());
|
throw new CorruptIndexException("did not read all bytes from file \"" + fileName + "\": read " + input.getFilePointer() + " vs size " + input.length() + " (resource: " + input + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,15 +17,24 @@
|
||||||
|
|
||||||
package org.apache.lucene.index;
|
package org.apache.lucene.index;
|
||||||
|
|
||||||
|
import org.apache.lucene.store.DataInput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This exception is thrown when Lucene detects
|
* This exception is thrown when Lucene detects
|
||||||
* an index that is newer than this Lucene version.
|
* an index that is newer than this Lucene version.
|
||||||
*/
|
*/
|
||||||
public class IndexFormatTooNewException extends CorruptIndexException {
|
public class IndexFormatTooNewException extends CorruptIndexException {
|
||||||
|
|
||||||
public IndexFormatTooNewException(String filename, int version, int minVersion, int maxVersion) {
|
/** @lucene.internal */
|
||||||
super("Format version is not supported" + (filename!=null ? (" in file '" + filename + "'") : "") +
|
public IndexFormatTooNewException(String resourceDesc, int version, int minVersion, int maxVersion) {
|
||||||
": " + version + " (needs to be between " + minVersion + " and " + maxVersion + ")");
|
super("Format version is not supported (resource: " + resourceDesc + "): "
|
||||||
|
+ version + " (needs to be between " + minVersion + " and " + maxVersion + ")");
|
||||||
|
assert resourceDesc != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @lucene.internal */
|
||||||
|
public IndexFormatTooNewException(DataInput in, int version, int minVersion, int maxVersion) {
|
||||||
|
this(in.toString(), version, minVersion, maxVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,21 +17,36 @@
|
||||||
|
|
||||||
package org.apache.lucene.index;
|
package org.apache.lucene.index;
|
||||||
|
|
||||||
|
import org.apache.lucene.store.DataInput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This exception is thrown when Lucene detects
|
* This exception is thrown when Lucene detects
|
||||||
* an index that is too old for this Lucene version
|
* an index that is too old for this Lucene version
|
||||||
*/
|
*/
|
||||||
public class IndexFormatTooOldException extends CorruptIndexException {
|
public class IndexFormatTooOldException extends CorruptIndexException {
|
||||||
|
|
||||||
public IndexFormatTooOldException(String filename, String version) {
|
/** @lucene.internal */
|
||||||
super("Format version is not supported" + (filename!=null ? (" in file '" + filename + "'") : "") +
|
public IndexFormatTooOldException(String resourceDesc, String version) {
|
||||||
": " + version + ". This version of Lucene only supports indexes created with release 3.0 and later.");
|
super("Format version is not supported (resource: " + resourceDesc + "): " +
|
||||||
|
version + ". This version of Lucene only supports indexes created with release 3.0 and later.");
|
||||||
|
assert resourceDesc != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IndexFormatTooOldException(String filename, int version, int minVersion, int maxVersion) {
|
/** @lucene.internal */
|
||||||
super("Format version is not supported" + (filename!=null ? (" in file '" + filename + "'") : "") +
|
public IndexFormatTooOldException(DataInput in, String version) {
|
||||||
": " + version + " (needs to be between " + minVersion + " and " + maxVersion +
|
this(in.toString(), version);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @lucene.internal */
|
||||||
|
public IndexFormatTooOldException(String resourceDesc, int version, int minVersion, int maxVersion) {
|
||||||
|
super("Format version is not supported (resource: " + resourceDesc + "): " +
|
||||||
|
version + " (needs to be between " + minVersion + " and " + maxVersion +
|
||||||
"). This version of Lucene only supports indexes created with release 3.0 and later.");
|
"). This version of Lucene only supports indexes created with release 3.0 and later.");
|
||||||
|
assert resourceDesc != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @lucene.internal */
|
||||||
|
public IndexFormatTooOldException(DataInput in, int version, int minVersion, int maxVersion) {
|
||||||
|
this(in.toString(), version, minVersion, maxVersion);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.lucene.index;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.apache.lucene.index.Term;
|
|
||||||
import org.apache.lucene.store.IndexInput;
|
import org.apache.lucene.store.IndexInput;
|
||||||
import org.apache.lucene.store.RAMFile;
|
import org.apache.lucene.store.RAMFile;
|
||||||
import org.apache.lucene.store.RAMInputStream;
|
import org.apache.lucene.store.RAMInputStream;
|
||||||
|
@ -56,7 +55,7 @@ class PrefixCodedTerms implements Iterable<Term> {
|
||||||
|
|
||||||
PrefixCodedTermsIterator() {
|
PrefixCodedTermsIterator() {
|
||||||
try {
|
try {
|
||||||
input = new RAMInputStream(buffer);
|
input = new RAMInputStream("PrefixCodedTermsIterator", buffer);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,10 +255,10 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentInfo> {
|
||||||
|
|
||||||
// check that it is a format we can understand
|
// check that it is a format we can understand
|
||||||
if (format > DefaultSegmentInfosWriter.FORMAT_MINIMUM)
|
if (format > DefaultSegmentInfosWriter.FORMAT_MINIMUM)
|
||||||
throw new IndexFormatTooOldException(segmentFileName, format,
|
throw new IndexFormatTooOldException(input, format,
|
||||||
DefaultSegmentInfosWriter.FORMAT_MINIMUM, DefaultSegmentInfosWriter.FORMAT_CURRENT);
|
DefaultSegmentInfosWriter.FORMAT_MINIMUM, DefaultSegmentInfosWriter.FORMAT_CURRENT);
|
||||||
if (format < DefaultSegmentInfosWriter.FORMAT_CURRENT)
|
if (format < DefaultSegmentInfosWriter.FORMAT_CURRENT)
|
||||||
throw new IndexFormatTooNewException(segmentFileName, format,
|
throw new IndexFormatTooNewException(input, format,
|
||||||
DefaultSegmentInfosWriter.FORMAT_MINIMUM, DefaultSegmentInfosWriter.FORMAT_CURRENT);
|
DefaultSegmentInfosWriter.FORMAT_MINIMUM, DefaultSegmentInfosWriter.FORMAT_CURRENT);
|
||||||
|
|
||||||
if (format <= DefaultSegmentInfosWriter.FORMAT_4_0) {
|
if (format <= DefaultSegmentInfosWriter.FORMAT_4_0) {
|
||||||
|
@ -271,7 +271,7 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentInfo> {
|
||||||
final long checksumNow = input.getChecksum();
|
final long checksumNow = input.getChecksum();
|
||||||
final long checksumThen = input.readLong();
|
final long checksumThen = input.readLong();
|
||||||
if (checksumNow != checksumThen)
|
if (checksumNow != checksumThen)
|
||||||
throw new CorruptIndexException("checksum mismatch in segments file");
|
throw new CorruptIndexException("checksum mismatch in segments file (resource: " + input + ")");
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
@ -634,8 +634,7 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentInfo> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* TODO: Investigate this!
|
/* TODO: Investigate this!
|
||||||
throw new IndexFormatTooNewException("segments.gen version number invalid: " + version +
|
throw new IndexFormatTooNewException(genInput, version, FORMAT_SEGMENTS_GEN_CURRENT, FORMAT_SEGMENTS_GEN_CURRENT);
|
||||||
" (must be " + FORMAT_SEGMENTS_GEN_CURRENT + ")");
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
} catch (IOException err2) {
|
} catch (IOException err2) {
|
||||||
|
|
|
@ -17,12 +17,9 @@ package org.apache.lucene.index;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.lucene.index.MergePolicy.OneMerge;
|
|
||||||
import org.apache.lucene.store.BufferedIndexInput;
|
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
import org.apache.lucene.store.IOContext;
|
import org.apache.lucene.store.IOContext;
|
||||||
import org.apache.lucene.store.IndexInput;
|
import org.apache.lucene.store.IndexInput;
|
||||||
import org.apache.lucene.store.IOContext.Context;
|
|
||||||
import org.apache.lucene.util.ArrayUtil;
|
import org.apache.lucene.util.ArrayUtil;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.apache.lucene.util.IOUtils;
|
import org.apache.lucene.util.IOUtils;
|
||||||
|
@ -186,9 +183,9 @@ class TermVectorsReader implements Cloneable, Closeable {
|
||||||
{
|
{
|
||||||
int format = in.readInt();
|
int format = in.readInt();
|
||||||
if (format < FORMAT_MINIMUM)
|
if (format < FORMAT_MINIMUM)
|
||||||
throw new IndexFormatTooOldException(fn, format, FORMAT_MINIMUM, FORMAT_CURRENT);
|
throw new IndexFormatTooOldException(in, format, FORMAT_MINIMUM, FORMAT_CURRENT);
|
||||||
if (format > FORMAT_CURRENT)
|
if (format > FORMAT_CURRENT)
|
||||||
throw new IndexFormatTooNewException(fn, format, FORMAT_MINIMUM, FORMAT_CURRENT);
|
throw new IndexFormatTooNewException(in, format, FORMAT_MINIMUM, FORMAT_CURRENT);
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,9 +88,9 @@ public final class DefaultFieldsReader extends FieldsReader implements Cloneable
|
||||||
try {
|
try {
|
||||||
int format = idxStream.readInt();
|
int format = idxStream.readInt();
|
||||||
if (format < DefaultFieldsWriter.FORMAT_MINIMUM)
|
if (format < DefaultFieldsWriter.FORMAT_MINIMUM)
|
||||||
throw new IndexFormatTooOldException(indexStreamFN, format, DefaultFieldsWriter.FORMAT_MINIMUM, DefaultFieldsWriter.FORMAT_CURRENT);
|
throw new IndexFormatTooOldException(idxStream, format, DefaultFieldsWriter.FORMAT_MINIMUM, DefaultFieldsWriter.FORMAT_CURRENT);
|
||||||
if (format > DefaultFieldsWriter.FORMAT_CURRENT)
|
if (format > DefaultFieldsWriter.FORMAT_CURRENT)
|
||||||
throw new IndexFormatTooNewException(indexStreamFN, format, DefaultFieldsWriter.FORMAT_MINIMUM, DefaultFieldsWriter.FORMAT_CURRENT);
|
throw new IndexFormatTooNewException(idxStream, format, DefaultFieldsWriter.FORMAT_MINIMUM, DefaultFieldsWriter.FORMAT_CURRENT);
|
||||||
} finally {
|
} finally {
|
||||||
idxStream.close();
|
idxStream.close();
|
||||||
}
|
}
|
||||||
|
@ -128,9 +128,9 @@ public final class DefaultFieldsReader extends FieldsReader implements Cloneable
|
||||||
format = cloneableIndexStream.readInt();
|
format = cloneableIndexStream.readInt();
|
||||||
|
|
||||||
if (format < DefaultFieldsWriter.FORMAT_MINIMUM)
|
if (format < DefaultFieldsWriter.FORMAT_MINIMUM)
|
||||||
throw new IndexFormatTooOldException(indexStreamFN, format, DefaultFieldsWriter.FORMAT_MINIMUM, DefaultFieldsWriter.FORMAT_CURRENT);
|
throw new IndexFormatTooOldException(cloneableIndexStream, format, DefaultFieldsWriter.FORMAT_MINIMUM, DefaultFieldsWriter.FORMAT_CURRENT);
|
||||||
if (format > DefaultFieldsWriter.FORMAT_CURRENT)
|
if (format > DefaultFieldsWriter.FORMAT_CURRENT)
|
||||||
throw new IndexFormatTooNewException(indexStreamFN, format, DefaultFieldsWriter.FORMAT_MINIMUM, DefaultFieldsWriter.FORMAT_CURRENT);
|
throw new IndexFormatTooNewException(cloneableIndexStream, format, DefaultFieldsWriter.FORMAT_MINIMUM, DefaultFieldsWriter.FORMAT_CURRENT);
|
||||||
|
|
||||||
fieldsStream = (IndexInput) cloneableFieldsStream.clone();
|
fieldsStream = (IndexInput) cloneableFieldsStream.clone();
|
||||||
|
|
||||||
|
@ -271,33 +271,4 @@ public final class DefaultFieldsReader extends FieldsReader implements Cloneable
|
||||||
|
|
||||||
return fieldsStream;
|
return fieldsStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Skip the field. We still have to read some of the information about the field, but can skip past the actual content.
|
|
||||||
* This will have the most payoff on large fields.
|
|
||||||
*/
|
|
||||||
private void skipField(int numeric) throws IOException {
|
|
||||||
final int numBytes;
|
|
||||||
switch(numeric) {
|
|
||||||
case 0:
|
|
||||||
numBytes = fieldsStream.readVInt();
|
|
||||||
break;
|
|
||||||
case DefaultFieldsWriter.FIELD_IS_NUMERIC_INT:
|
|
||||||
case DefaultFieldsWriter.FIELD_IS_NUMERIC_FLOAT:
|
|
||||||
numBytes = 4;
|
|
||||||
break;
|
|
||||||
case DefaultFieldsWriter.FIELD_IS_NUMERIC_LONG:
|
|
||||||
case DefaultFieldsWriter.FIELD_IS_NUMERIC_DOUBLE:
|
|
||||||
numBytes = 8;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new FieldReaderException("Invalid numeric type: " + Integer.toHexString(numeric));
|
|
||||||
}
|
|
||||||
|
|
||||||
skipFieldBytes(numBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void skipFieldBytes(int toRead) throws IOException {
|
|
||||||
fieldsStream.seek(fieldsStream.getFilePointer() + toRead);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class DefaultSegmentInfosReader extends SegmentInfosReader {
|
||||||
IndexFileNames.COMPOUND_FILE_STORE_EXTENSION), context, false);
|
IndexFileNames.COMPOUND_FILE_STORE_EXTENSION), context, false);
|
||||||
}
|
}
|
||||||
} else if (si.getUseCompoundFile()) {
|
} else if (si.getUseCompoundFile()) {
|
||||||
dir = new CompoundFileDirectory(dir,IndexFileNames.segmentFileName(
|
dir = new CompoundFileDirectory(dir, IndexFileNames.segmentFileName(
|
||||||
si.name, "", IndexFileNames.COMPOUND_FILE_EXTENSION), context, false);
|
si.name, "", IndexFileNames.COMPOUND_FILE_EXTENSION), context, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ public class DefaultSegmentInfosReader extends SegmentInfosReader {
|
||||||
// If it's a 3x index touched by 3.1+ code, then segments record their
|
// If it's a 3x index touched by 3.1+ code, then segments record their
|
||||||
// version, whether they are 2.x ones or not. We detect that and throw
|
// version, whether they are 2.x ones or not. We detect that and throw
|
||||||
// appropriate exception.
|
// appropriate exception.
|
||||||
throw new IndexFormatTooOldException(si.name, si.getVersion());
|
throw new IndexFormatTooOldException("segment " + si.name + " in resource " + input, si.getVersion());
|
||||||
}
|
}
|
||||||
infos.add(si);
|
infos.add(si);
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,6 +255,7 @@ public abstract class MultiLevelSkipListReader {
|
||||||
private int pos;
|
private int pos;
|
||||||
|
|
||||||
SkipBuffer(IndexInput input, int length) throws IOException {
|
SkipBuffer(IndexInput input, int length) throws IOException {
|
||||||
|
super("SkipBuffer on " + input);
|
||||||
data = new byte[length];
|
data = new byte[length];
|
||||||
pointer = input.getFilePointer();
|
pointer = input.getFilePointer();
|
||||||
input.readBytes(data, 0, length);
|
input.readBytes(data, 0, length);
|
||||||
|
|
|
@ -85,9 +85,9 @@ public final class SegmentTermEnum implements Cloneable {
|
||||||
|
|
||||||
// check that it is a format we can understand
|
// check that it is a format we can understand
|
||||||
if (format > FORMAT_MINIMUM)
|
if (format > FORMAT_MINIMUM)
|
||||||
throw new IndexFormatTooOldException(null, format, FORMAT_MINIMUM, FORMAT_CURRENT);
|
throw new IndexFormatTooOldException(input, format, FORMAT_MINIMUM, FORMAT_CURRENT);
|
||||||
if (format < FORMAT_CURRENT)
|
if (format < FORMAT_CURRENT)
|
||||||
throw new IndexFormatTooNewException(null, format, FORMAT_MINIMUM, FORMAT_CURRENT);
|
throw new IndexFormatTooNewException(input, format, FORMAT_MINIMUM, FORMAT_CURRENT);
|
||||||
|
|
||||||
size = input.readLong(); // read the size
|
size = input.readLong(); // read the size
|
||||||
|
|
||||||
|
|
|
@ -163,7 +163,7 @@ public final class Lucene40PostingsWriter extends PostingsWriterBase {
|
||||||
final int delta = docID - lastDocID;
|
final int delta = docID - lastDocID;
|
||||||
|
|
||||||
if (docID < 0 || (df > 0 && delta <= 0)) {
|
if (docID < 0 || (df > 0 && delta <= 0)) {
|
||||||
throw new CorruptIndexException("docs out of order (" + docID + " <= " + lastDocID + " )");
|
throw new CorruptIndexException("docs out of order (" + docID + " <= " + lastDocID + " ) (freqOut: " + freqOut + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((++df % skipInterval) == 0) {
|
if ((++df % skipInterval) == 0) {
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.lucene.index.codecs.sep;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.lucene.index.CorruptIndexException;
|
import org.apache.lucene.index.CorruptIndexException;
|
||||||
import org.apache.lucene.index.DocsEnum;
|
import org.apache.lucene.index.DocsEnum;
|
||||||
|
@ -203,7 +202,7 @@ public final class SepPostingsWriter extends PostingsWriterBase {
|
||||||
//System.out.println("SEPW: startDoc: write doc=" + docID + " delta=" + delta + " out.fp=" + docOut);
|
//System.out.println("SEPW: startDoc: write doc=" + docID + " delta=" + delta + " out.fp=" + docOut);
|
||||||
|
|
||||||
if (docID < 0 || (df > 0 && delta <= 0)) {
|
if (docID < 0 || (df > 0 && delta <= 0)) {
|
||||||
throw new CorruptIndexException("docs out of order (" + docID + " <= " + lastDocID + " )");
|
throw new CorruptIndexException("docs out of order (" + docID + " <= " + lastDocID + " ) (docOut: " + docOut + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((++df % skipInterval) == 0) {
|
if ((++df % skipInterval) == 0) {
|
||||||
|
|
|
@ -51,14 +51,17 @@ public abstract class BufferedIndexInput extends IndexInput {
|
||||||
return buffer[bufferPosition++];
|
return buffer[bufferPosition++];
|
||||||
}
|
}
|
||||||
|
|
||||||
public BufferedIndexInput() {}
|
public BufferedIndexInput(String resourceDesc) {
|
||||||
|
this(resourceDesc, BUFFER_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
public BufferedIndexInput(IOContext context) {
|
public BufferedIndexInput(String resourceDesc, IOContext context) {
|
||||||
this(bufferSize(context));
|
this(resourceDesc, bufferSize(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Inits BufferedIndexInput with a specific bufferSize */
|
/** Inits BufferedIndexInput with a specific bufferSize */
|
||||||
public BufferedIndexInput(int bufferSize) {
|
public BufferedIndexInput(String resourceDesc, int bufferSize) {
|
||||||
|
super(resourceDesc);
|
||||||
checkBufferSize(bufferSize);
|
checkBufferSize(bufferSize);
|
||||||
this.bufferSize = bufferSize;
|
this.bufferSize = bufferSize;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ public class ChecksumIndexInput extends IndexInput {
|
||||||
Checksum digest;
|
Checksum digest;
|
||||||
|
|
||||||
public ChecksumIndexInput(IndexInput main) {
|
public ChecksumIndexInput(IndexInput main) {
|
||||||
|
super("ChecksumIndexInput(" + main + ")");
|
||||||
this.main = main;
|
this.main = main;
|
||||||
digest = new CRC32();
|
digest = new CRC32();
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,7 +139,7 @@ public final class CompoundFileDirectory extends Directory {
|
||||||
if (firstInt < CompoundFileWriter.FORMAT_PRE_VERSION) {
|
if (firstInt < CompoundFileWriter.FORMAT_PRE_VERSION) {
|
||||||
if (firstInt < CompoundFileWriter.FORMAT_CURRENT) {
|
if (firstInt < CompoundFileWriter.FORMAT_CURRENT) {
|
||||||
throw new CorruptIndexException("Incompatible format version: "
|
throw new CorruptIndexException("Incompatible format version: "
|
||||||
+ firstInt + " expected " + CompoundFileWriter.FORMAT_CURRENT);
|
+ firstInt + " expected " + CompoundFileWriter.FORMAT_CURRENT + " (resource: " + stream + ")");
|
||||||
}
|
}
|
||||||
// It's a post-3.1 index, read the count.
|
// It's a post-3.1 index, read the count.
|
||||||
count = stream.readVInt();
|
count = stream.readVInt();
|
||||||
|
@ -155,7 +155,7 @@ public final class CompoundFileDirectory extends Directory {
|
||||||
for (int i=0; i<count; i++) {
|
for (int i=0; i<count; i++) {
|
||||||
long offset = stream.readLong();
|
long offset = stream.readLong();
|
||||||
if (offset < 0 || offset > streamLength) {
|
if (offset < 0 || offset > streamLength) {
|
||||||
throw new CorruptIndexException("Invalid CFS entry offset: " + offset);
|
throw new CorruptIndexException("Invalid CFS entry offset: " + offset + " (resource: " + stream + ")");
|
||||||
}
|
}
|
||||||
String id = stream.readString();
|
String id = stream.readString();
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ public final class CompoundFileDirectory extends Directory {
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
throw new IOException("No sub-file with id " + id + " found (fileName=" + name + " files: " + entries.keySet() + ")");
|
throw new IOException("No sub-file with id " + id + " found (fileName=" + name + " files: " + entries.keySet() + ")");
|
||||||
}
|
}
|
||||||
return handle.openSlice(entry.offset, entry.length);
|
return handle.openSlice(name, entry.offset, entry.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns an array of strings, one for each file in the directory. */
|
/** Returns an array of strings, one for each file in the directory. */
|
||||||
|
@ -318,13 +318,13 @@ public final class CompoundFileDirectory extends Directory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndexInput openSlice(long offset, long length) throws IOException {
|
public IndexInput openSlice(String sliceDescription, long offset, long length) throws IOException {
|
||||||
return handle.openSlice(entry.offset + offset, length);
|
return handle.openSlice(sliceDescription, entry.offset + offset, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndexInput openFullSlice() throws IOException {
|
public IndexInput openFullSlice() throws IOException {
|
||||||
return openSlice(0, entry.length);
|
return openSlice("full-slice", 0, entry.length);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,8 +225,8 @@ public abstract class Directory implements Closeable {
|
||||||
return new IndexInputSlicer() {
|
return new IndexInputSlicer() {
|
||||||
private final IndexInput base = Directory.this.openInput(name, context);
|
private final IndexInput base = Directory.this.openInput(name, context);
|
||||||
@Override
|
@Override
|
||||||
public IndexInput openSlice(long offset, long length) {
|
public IndexInput openSlice(String sliceDescription, long offset, long length) {
|
||||||
return new SlicedIndexInput(base, offset, length);
|
return new SlicedIndexInput("SlicedIndexInput(" + sliceDescription + " in " + base + ")", base, offset, length);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
|
@ -258,7 +258,7 @@ public abstract class Directory implements Closeable {
|
||||||
/**
|
/**
|
||||||
* Returns an {@link IndexInput} slice starting at the given offset with the given length.
|
* Returns an {@link IndexInput} slice starting at the given offset with the given length.
|
||||||
*/
|
*/
|
||||||
public abstract IndexInput openSlice(long offset, long length) throws IOException;
|
public abstract IndexInput openSlice(String sliceDescription, long offset, long length) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an {@link IndexInput} slice starting at offset <i>0</i> with a
|
* Returns an {@link IndexInput} slice starting at offset <i>0</i> with a
|
||||||
|
@ -275,12 +275,12 @@ public abstract class Directory implements Closeable {
|
||||||
long fileOffset;
|
long fileOffset;
|
||||||
long length;
|
long length;
|
||||||
|
|
||||||
SlicedIndexInput(final IndexInput base, final long fileOffset, final long length) {
|
SlicedIndexInput(final String sliceDescription, final IndexInput base, final long fileOffset, final long length) {
|
||||||
this(base, fileOffset, length, BufferedIndexInput.BUFFER_SIZE);
|
this(sliceDescription, base, fileOffset, length, BufferedIndexInput.BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
SlicedIndexInput(final IndexInput base, final long fileOffset, final long length, int readBufferSize) {
|
SlicedIndexInput(final String sliceDescription, final IndexInput base, final long fileOffset, final long length, int readBufferSize) {
|
||||||
super(readBufferSize);
|
super("SlicedIndexInput(" + sliceDescription + " in " + base + " slice=" + fileOffset + ":" + (fileOffset+length) + ")", readBufferSize);
|
||||||
this.base = (IndexInput) base.clone();
|
this.base = (IndexInput) base.clone();
|
||||||
this.fileOffset = fileOffset;
|
this.fileOffset = fileOffset;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
|
|
|
@ -26,6 +26,18 @@ import java.io.IOException;
|
||||||
*/
|
*/
|
||||||
public abstract class IndexInput extends DataInput implements Cloneable,Closeable {
|
public abstract class IndexInput extends DataInput implements Cloneable,Closeable {
|
||||||
|
|
||||||
|
private final String resourceDescription;
|
||||||
|
|
||||||
|
/** resourceDescription should be a non-null, opaque string
|
||||||
|
* describing this resource; it's returned from
|
||||||
|
* {@link #toString}. */
|
||||||
|
protected IndexInput(String resourceDescription) {
|
||||||
|
if (resourceDescription == null) {
|
||||||
|
throw new IllegalArgumentException("resourceDescription must not be null");
|
||||||
|
}
|
||||||
|
this.resourceDescription = resourceDescription;
|
||||||
|
}
|
||||||
|
|
||||||
/** Closes the stream to further operations. */
|
/** Closes the stream to further operations. */
|
||||||
public abstract void close() throws IOException;
|
public abstract void close() throws IOException;
|
||||||
|
|
||||||
|
@ -67,4 +79,8 @@ public abstract class IndexInput extends DataInput implements Cloneable,Closeabl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return resourceDescription;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,7 +213,7 @@ public class MMapDirectory extends FSDirectory {
|
||||||
File f = new File(getDirectory(), name);
|
File f = new File(getDirectory(), name);
|
||||||
RandomAccessFile raf = new RandomAccessFile(f, "r");
|
RandomAccessFile raf = new RandomAccessFile(f, "r");
|
||||||
try {
|
try {
|
||||||
return new MMapIndexInput(raf, 0, raf.length(), chunkSizePower);
|
return new MMapIndexInput("MMapIndexInput(path=\"" + f + "\")", raf, 0, raf.length(), chunkSizePower);
|
||||||
} finally {
|
} finally {
|
||||||
raf.close();
|
raf.close();
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ public class MMapDirectory extends FSDirectory {
|
||||||
|
|
||||||
public IndexInputSlicer createSlicer(final String name, final IOContext context) throws IOException {
|
public IndexInputSlicer createSlicer(final String name, final IOContext context) throws IOException {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
File f = new File(getDirectory(), name);
|
final File f = new File(getDirectory(), name);
|
||||||
final RandomAccessFile raf = new RandomAccessFile(f, "r");
|
final RandomAccessFile raf = new RandomAccessFile(f, "r");
|
||||||
return new IndexInputSlicer() {
|
return new IndexInputSlicer() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -230,13 +230,13 @@ public class MMapDirectory extends FSDirectory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndexInput openSlice(long offset, long length) throws IOException {
|
public IndexInput openSlice(String sliceDescription, long offset, long length) throws IOException {
|
||||||
return new MMapIndexInput(raf, offset, length, chunkSizePower);
|
return new MMapIndexInput("MMapIndexInput(" + sliceDescription + " in path=\"" + f + "\" slice=" + offset + ":" + (offset+length) + ")", raf, offset, length, chunkSizePower);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndexInput openFullSlice() throws IOException {
|
public IndexInput openFullSlice() throws IOException {
|
||||||
return openSlice(0, raf.length());
|
return openSlice("full-slice", 0, raf.length());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,8 @@ public class MMapDirectory extends FSDirectory {
|
||||||
|
|
||||||
private boolean isClone = false;
|
private boolean isClone = false;
|
||||||
|
|
||||||
MMapIndexInput(RandomAccessFile raf, long offset, long length, int chunkSizePower) throws IOException {
|
MMapIndexInput(String resourceDescription, RandomAccessFile raf, long offset, long length, int chunkSizePower) throws IOException {
|
||||||
|
super(resourceDescription);
|
||||||
this.length = length;
|
this.length = length;
|
||||||
this.chunkSizePower = chunkSizePower;
|
this.chunkSizePower = chunkSizePower;
|
||||||
this.chunkSize = 1L << chunkSizePower;
|
this.chunkSize = 1L << chunkSizePower;
|
||||||
|
@ -296,8 +297,9 @@ public class MMapDirectory extends FSDirectory {
|
||||||
} catch (BufferUnderflowException e) {
|
} catch (BufferUnderflowException e) {
|
||||||
do {
|
do {
|
||||||
curBufIndex++;
|
curBufIndex++;
|
||||||
if (curBufIndex >= buffers.length)
|
if (curBufIndex >= buffers.length) {
|
||||||
throw new IOException("read past EOF");
|
throw new IOException("read past EOF: " + this);
|
||||||
|
}
|
||||||
curBuf = buffers[curBufIndex];
|
curBuf = buffers[curBufIndex];
|
||||||
curBuf.position(0);
|
curBuf.position(0);
|
||||||
} while (!curBuf.hasRemaining());
|
} while (!curBuf.hasRemaining());
|
||||||
|
@ -316,8 +318,9 @@ public class MMapDirectory extends FSDirectory {
|
||||||
len -= curAvail;
|
len -= curAvail;
|
||||||
offset += curAvail;
|
offset += curAvail;
|
||||||
curBufIndex++;
|
curBufIndex++;
|
||||||
if (curBufIndex >= buffers.length)
|
if (curBufIndex >= buffers.length) {
|
||||||
throw new IOException("read past EOF");
|
throw new IOException("read past EOF: " + this);
|
||||||
|
}
|
||||||
curBuf = buffers[curBufIndex];
|
curBuf = buffers[curBufIndex];
|
||||||
curBuf.position(0);
|
curBuf.position(0);
|
||||||
curAvail = curBuf.remaining();
|
curAvail = curBuf.remaining();
|
||||||
|
@ -369,13 +372,15 @@ public class MMapDirectory extends FSDirectory {
|
||||||
this.curBufIndex = bi;
|
this.curBufIndex = bi;
|
||||||
this.curBuf = b;
|
this.curBuf = b;
|
||||||
} catch (ArrayIndexOutOfBoundsException aioobe) {
|
} catch (ArrayIndexOutOfBoundsException aioobe) {
|
||||||
if (pos < 0L)
|
if (pos < 0L) {
|
||||||
throw new IllegalArgumentException("Seeking to negative position");
|
throw new IllegalArgumentException("Seeking to negative position: " + this);
|
||||||
|
}
|
||||||
throw new IOException("seek past EOF");
|
throw new IOException("seek past EOF");
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (IllegalArgumentException iae) {
|
||||||
if (pos < 0L)
|
if (pos < 0L) {
|
||||||
throw new IllegalArgumentException("Seeking to negative position");
|
throw new IllegalArgumentException("Seeking to negative position: " + this);
|
||||||
throw new IOException("seek past EOF");
|
}
|
||||||
|
throw new IOException("seek past EOF: " + this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,8 +391,9 @@ public class MMapDirectory extends FSDirectory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
if (buffers == null)
|
if (buffers == null) {
|
||||||
throw new AlreadyClosedException("MMapIndexInput already closed");
|
throw new AlreadyClosedException("MMapIndexInput already closed: " + this);
|
||||||
|
}
|
||||||
final MMapIndexInput clone = (MMapIndexInput)super.clone();
|
final MMapIndexInput clone = (MMapIndexInput)super.clone();
|
||||||
clone.isClone = true;
|
clone.isClone = true;
|
||||||
clone.buffers = new ByteBuffer[buffers.length];
|
clone.buffers = new ByteBuffer[buffers.length];
|
||||||
|
@ -399,7 +405,7 @@ public class MMapDirectory extends FSDirectory {
|
||||||
try {
|
try {
|
||||||
clone.seek(getFilePointer());
|
clone.seek(getFilePointer());
|
||||||
} catch(IOException ioe) {
|
} catch(IOException ioe) {
|
||||||
throw new RuntimeException("Should never happen", ioe);
|
throw new RuntimeException("Should never happen: " + this, ioe);
|
||||||
}
|
}
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,8 +83,8 @@ public class NIOFSDirectory extends FSDirectory {
|
||||||
public IndexInputSlicer createSlicer(final String name,
|
public IndexInputSlicer createSlicer(final String name,
|
||||||
final IOContext context) throws IOException {
|
final IOContext context) throws IOException {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
final File file = new File(getDirectory(), name);
|
final File path = new File(getDirectory(), name);
|
||||||
final Descriptor descriptor = new Descriptor(file, "r");
|
final Descriptor descriptor = new Descriptor(path, "r");
|
||||||
return new Directory.IndexInputSlicer() {
|
return new Directory.IndexInputSlicer() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -93,14 +93,14 @@ public class NIOFSDirectory extends FSDirectory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndexInput openSlice(long offset, long length) throws IOException {
|
public IndexInput openSlice(String sliceDescription, long offset, long length) throws IOException {
|
||||||
return new NIOFSIndexInput(descriptor, descriptor.getChannel(), offset,
|
return new NIOFSIndexInput(sliceDescription, path, descriptor, descriptor.getChannel(), offset,
|
||||||
length, BufferedIndexInput.bufferSize(context), getReadChunkSize());
|
length, BufferedIndexInput.bufferSize(context), getReadChunkSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndexInput openFullSlice() throws IOException {
|
public IndexInput openFullSlice() throws IOException {
|
||||||
return openSlice(0, descriptor.length);
|
return openSlice("full-slice", 0, descriptor.length);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -115,12 +115,12 @@ public class NIOFSDirectory extends FSDirectory {
|
||||||
final FileChannel channel;
|
final FileChannel channel;
|
||||||
|
|
||||||
public NIOFSIndexInput(File path, IOContext context, int chunkSize) throws IOException {
|
public NIOFSIndexInput(File path, IOContext context, int chunkSize) throws IOException {
|
||||||
super(path, context, chunkSize);
|
super("NIOFSIndexInput(path=\"" + path + "\")", path, context, chunkSize);
|
||||||
channel = file.getChannel();
|
channel = file.getChannel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public NIOFSIndexInput(Descriptor file, FileChannel fc, long off, long length, int bufferSize, int chunkSize) throws IOException {
|
public NIOFSIndexInput(String sliceDescription, File path, Descriptor file, FileChannel fc, long off, long length, int bufferSize, int chunkSize) throws IOException {
|
||||||
super(file, off, length, bufferSize, chunkSize);
|
super("NIOFSIndexInput(" + sliceDescription + " in path=\"" + path + "\" slice=" + off + ":" + (off+length) + ")", file, off, length, bufferSize, chunkSize);
|
||||||
channel = fc;
|
channel = fc;
|
||||||
isClone = true;
|
isClone = true;
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ public class NIOFSDirectory extends FSDirectory {
|
||||||
long pos = getFilePointer() + off;
|
long pos = getFilePointer() + off;
|
||||||
|
|
||||||
if (pos + len > end) {
|
if (pos + len > end) {
|
||||||
throw new IOException("read past EOF");
|
throw new IOException("read past EOF: " + this);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -209,6 +209,8 @@ public class NIOFSDirectory extends FSDirectory {
|
||||||
+ "with a value smaller than the current chunk size (" + chunkSize + ")");
|
+ "with a value smaller than the current chunk size (" + chunkSize + ")");
|
||||||
outOfMemoryError.initCause(e);
|
outOfMemoryError.initCause(e);
|
||||||
throw outOfMemoryError;
|
throw outOfMemoryError;
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
throw new IOException(ioe.getMessage() + ": " + this, ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,7 +183,7 @@ public class RAMDirectory extends Directory {
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
throw new FileNotFoundException(name);
|
throw new FileNotFoundException(name);
|
||||||
}
|
}
|
||||||
return new RAMInputStream(file);
|
return new RAMInputStream(name, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Closes the store to future operations, releasing associated memory. */
|
/** Closes the store to future operations, releasing associated memory. */
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.lucene.store;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.EOFException;
|
||||||
|
|
||||||
/** A memory-resident {@link IndexInput} implementation.
|
/** A memory-resident {@link IndexInput} implementation.
|
||||||
*
|
*
|
||||||
|
@ -35,11 +36,12 @@ public class RAMInputStream extends IndexInput implements Cloneable {
|
||||||
private long bufferStart;
|
private long bufferStart;
|
||||||
private int bufferLength;
|
private int bufferLength;
|
||||||
|
|
||||||
public RAMInputStream(RAMFile f) throws IOException {
|
public RAMInputStream(String name, RAMFile f) throws IOException {
|
||||||
|
super("RAMInputStream(name=" + name + ")");
|
||||||
file = f;
|
file = f;
|
||||||
length = file.length;
|
length = file.length;
|
||||||
if (length/BUFFER_SIZE >= Integer.MAX_VALUE) {
|
if (length/BUFFER_SIZE >= Integer.MAX_VALUE) {
|
||||||
throw new IOException("Too large RAMFile! "+length);
|
throw new IOException("RAMInputStream too large length=" + length + ": " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure that we switch to the
|
// make sure that we switch to the
|
||||||
|
@ -88,9 +90,9 @@ public class RAMInputStream extends IndexInput implements Cloneable {
|
||||||
bufferStart = (long) BUFFER_SIZE * (long) currentBufferIndex;
|
bufferStart = (long) BUFFER_SIZE * (long) currentBufferIndex;
|
||||||
if (currentBufferIndex >= file.numBuffers()) {
|
if (currentBufferIndex >= file.numBuffers()) {
|
||||||
// end of file reached, no more buffers left
|
// end of file reached, no more buffers left
|
||||||
if (enforceEOF)
|
if (enforceEOF) {
|
||||||
throw new IOException("Read past EOF");
|
throw new EOFException("Read past EOF: " + this);
|
||||||
else {
|
} else {
|
||||||
// Force EOF if a read takes place at this position
|
// Force EOF if a read takes place at this position
|
||||||
currentBufferIndex--;
|
currentBufferIndex--;
|
||||||
bufferPosition = BUFFER_SIZE;
|
bufferPosition = BUFFER_SIZE;
|
||||||
|
|
|
@ -55,11 +55,10 @@ public class SimpleFSDirectory extends FSDirectory {
|
||||||
@Override
|
@Override
|
||||||
public IndexInput openInput(String name, IOContext context) throws IOException {
|
public IndexInput openInput(String name, IOContext context) throws IOException {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
return new SimpleFSIndexInput(new File(directory, name), context, getReadChunkSize());
|
final File path = new File(directory, name);
|
||||||
|
return new SimpleFSIndexInput("SimpleFSIndexInput(path=\"" + path.getPath() + "\")", path, context, getReadChunkSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public IndexInputSlicer createSlicer(final String name,
|
public IndexInputSlicer createSlicer(final String name,
|
||||||
final IOContext context) throws IOException {
|
final IOContext context) throws IOException {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
|
@ -73,19 +72,18 @@ public class SimpleFSDirectory extends FSDirectory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndexInput openSlice(long offset, long length) throws IOException {
|
public IndexInput openSlice(String sliceDescription, long offset, long length) throws IOException {
|
||||||
return new SimpleFSIndexInput(descriptor, offset,
|
return new SimpleFSIndexInput("SimpleFSIndexInput(" + sliceDescription + " in path=\"" + file.getPath() + "\" slice=" + offset + ":" + (offset+length) + ")", descriptor, offset,
|
||||||
length, BufferedIndexInput.bufferSize(context), getReadChunkSize());
|
length, BufferedIndexInput.bufferSize(context), getReadChunkSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndexInput openFullSlice() throws IOException {
|
public IndexInput openFullSlice() throws IOException {
|
||||||
return openSlice(0, descriptor.length);
|
return openSlice("full-slice", 0, descriptor.length);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static class SimpleFSIndexInput extends BufferedIndexInput {
|
protected static class SimpleFSIndexInput extends BufferedIndexInput {
|
||||||
|
|
||||||
protected static class Descriptor extends RandomAccessFile {
|
protected static class Descriptor extends RandomAccessFile {
|
||||||
|
@ -117,16 +115,16 @@ public class SimpleFSDirectory extends FSDirectory {
|
||||||
protected final long off;
|
protected final long off;
|
||||||
protected final long end;
|
protected final long end;
|
||||||
|
|
||||||
public SimpleFSIndexInput(File path, IOContext context, int chunkSize) throws IOException {
|
public SimpleFSIndexInput(String resourceDesc, File path, IOContext context, int chunkSize) throws IOException {
|
||||||
super(context);
|
super(resourceDesc, context);
|
||||||
this.file = new Descriptor(path, "r");
|
this.file = new Descriptor(path, "r");
|
||||||
this.chunkSize = chunkSize;
|
this.chunkSize = chunkSize;
|
||||||
this.off = 0L;
|
this.off = 0L;
|
||||||
this.end = file.length;
|
this.end = file.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleFSIndexInput(Descriptor file, long off, long length, int bufferSize, int chunkSize) throws IOException {
|
public SimpleFSIndexInput(String resourceDesc, Descriptor file, long off, long length, int bufferSize, int chunkSize) throws IOException {
|
||||||
super(bufferSize);
|
super(resourceDesc, bufferSize);
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.chunkSize = chunkSize;
|
this.chunkSize = chunkSize;
|
||||||
this.off = off;
|
this.off = off;
|
||||||
|
@ -147,7 +145,7 @@ public class SimpleFSDirectory extends FSDirectory {
|
||||||
int total = 0;
|
int total = 0;
|
||||||
|
|
||||||
if (position + len > end) {
|
if (position + len > end) {
|
||||||
throw new IOException("read past EOF");
|
throw new IOException("read past EOF: " + this);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -172,6 +170,8 @@ public class SimpleFSDirectory extends FSDirectory {
|
||||||
+ "with a value smaller than the current chunk size (" + chunkSize + ")");
|
+ "with a value smaller than the current chunk size (" + chunkSize + ")");
|
||||||
outOfMemoryError.initCause(e);
|
outOfMemoryError.initCause(e);
|
||||||
throw outOfMemoryError;
|
throw outOfMemoryError;
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
throw new IOException(ioe.getMessage() + ": " + this, ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,13 @@ package org.apache.lucene.util;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import org.apache.lucene.store.DataInput;
|
import java.io.IOException;
|
||||||
import org.apache.lucene.store.DataOutput;
|
|
||||||
import org.apache.lucene.index.CorruptIndexException;
|
import org.apache.lucene.index.CorruptIndexException;
|
||||||
import org.apache.lucene.index.IndexFormatTooNewException;
|
import org.apache.lucene.index.IndexFormatTooNewException;
|
||||||
import org.apache.lucene.index.IndexFormatTooOldException;
|
import org.apache.lucene.index.IndexFormatTooOldException;
|
||||||
|
import org.apache.lucene.store.DataInput;
|
||||||
import java.io.IOException;
|
import org.apache.lucene.store.DataOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @lucene.experimental
|
* @lucene.experimental
|
||||||
|
@ -56,20 +56,20 @@ public final class CodecUtil {
|
||||||
// Safety to guard against reading a bogus string:
|
// Safety to guard against reading a bogus string:
|
||||||
final int actualHeader = in.readInt();
|
final int actualHeader = in.readInt();
|
||||||
if (actualHeader != CODEC_MAGIC) {
|
if (actualHeader != CODEC_MAGIC) {
|
||||||
throw new CorruptIndexException("codec header mismatch: actual header=" + actualHeader + " vs expected header=" + CODEC_MAGIC);
|
throw new CorruptIndexException("codec header mismatch: actual header=" + actualHeader + " vs expected header=" + CODEC_MAGIC + " (resource: " + in + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
final String actualCodec = in.readString();
|
final String actualCodec = in.readString();
|
||||||
if (!actualCodec.equals(codec)) {
|
if (!actualCodec.equals(codec)) {
|
||||||
throw new CorruptIndexException("codec mismatch: actual codec=" + actualCodec + " vs expected codec=" + codec);
|
throw new CorruptIndexException("codec mismatch: actual codec=" + actualCodec + " vs expected codec=" + codec + " (resource: " + in + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
final int actualVersion = in.readInt();
|
final int actualVersion = in.readInt();
|
||||||
if (actualVersion < minVersion) {
|
if (actualVersion < minVersion) {
|
||||||
throw new IndexFormatTooOldException(null, actualVersion, minVersion, maxVersion);
|
throw new IndexFormatTooOldException(in, actualVersion, minVersion, maxVersion);
|
||||||
}
|
}
|
||||||
if (actualVersion > maxVersion) {
|
if (actualVersion > maxVersion) {
|
||||||
throw new IndexFormatTooNewException(null, actualVersion, minVersion, maxVersion);
|
throw new IndexFormatTooNewException(in, actualVersion, minVersion, maxVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
return actualVersion;
|
return actualVersion;
|
||||||
|
|
|
@ -25,6 +25,7 @@ public class MockIndexInput extends BufferedIndexInput {
|
||||||
private long length;
|
private long length;
|
||||||
|
|
||||||
public MockIndexInput(byte[] bytes) {
|
public MockIndexInput(byte[] bytes) {
|
||||||
|
super("MockIndexInput", BufferedIndexInput.BUFFER_SIZE);
|
||||||
buffer = bytes;
|
buffer = bytes;
|
||||||
length = bytes.length;
|
length = bytes.length;
|
||||||
}
|
}
|
||||||
|
|
|
@ -673,9 +673,9 @@ public class MockDirectoryWrapper extends Directory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndexInput openSlice(long offset, long length) throws IOException {
|
public IndexInput openSlice(String sliceDescription, long offset, long length) throws IOException {
|
||||||
maybeYield();
|
maybeYield();
|
||||||
IndexInput ii = new MockIndexInputWrapper(MockDirectoryWrapper.this, name, delegateHandle.openSlice(offset, length));
|
IndexInput ii = new MockIndexInputWrapper(MockDirectoryWrapper.this, name, delegateHandle.openSlice(sliceDescription, offset, length));
|
||||||
addFileHandle(ii, name, Handle.Input);
|
addFileHandle(ii, name, Handle.Input);
|
||||||
return ii;
|
return ii;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ public class MockIndexInputWrapper extends IndexInput {
|
||||||
|
|
||||||
/** Construct an empty output buffer. */
|
/** Construct an empty output buffer. */
|
||||||
public MockIndexInputWrapper(MockDirectoryWrapper dir, String name, IndexInput delegate) {
|
public MockIndexInputWrapper(MockDirectoryWrapper dir, String name, IndexInput delegate) {
|
||||||
|
super("MockIndexInputWrapper(name=" + name + " delegate=" + delegate + ")");
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.dir = dir;
|
this.dir = dir;
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
|
|
|
@ -122,7 +122,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
|
||||||
"31.optimized.nocfs",
|
"31.optimized.nocfs",
|
||||||
};
|
};
|
||||||
|
|
||||||
/** This test checks that *only* IndexFormatTooOldExceptions are throws when you open and operate on too old indexes! */
|
/** This test checks that *only* IndexFormatTooOldExceptions are thrown when you open and operate on too old indexes! */
|
||||||
public void testUnsupportedOldIndexes() throws Exception {
|
public void testUnsupportedOldIndexes() throws Exception {
|
||||||
for(int i=0;i<unsupportedNames.length;i++) {
|
for(int i=0;i<unsupportedNames.length;i++) {
|
||||||
if (VERBOSE) {
|
if (VERBOSE) {
|
||||||
|
@ -154,6 +154,8 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
|
||||||
System.out.println("TEST: got expected exc:");
|
System.out.println("TEST: got expected exc:");
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace(System.out);
|
||||||
}
|
}
|
||||||
|
// Make sure exc message includes a path=
|
||||||
|
assertTrue("got exc message: " + e.getMessage(), e.getMessage().indexOf("path=\"") != -1);
|
||||||
} finally {
|
} finally {
|
||||||
// we should fail to open IW, and so it should be null when we get here.
|
// we should fail to open IW, and so it should be null when we get here.
|
||||||
// However, if the test fails (i.e., IW did not fail on open), we need
|
// However, if the test fails (i.e., IW did not fail on open), we need
|
||||||
|
|
|
@ -161,6 +161,7 @@ public class TestFieldsReader extends LuceneTestCase {
|
||||||
static boolean doFail;
|
static boolean doFail;
|
||||||
int count;
|
int count;
|
||||||
private FaultyIndexInput(IndexInput delegate) {
|
private FaultyIndexInput(IndexInput delegate) {
|
||||||
|
super("FaultyIndexInput(" + delegate + ")", BufferedIndexInput.BUFFER_SIZE);
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
}
|
}
|
||||||
private void simOutage() throws IOException {
|
private void simOutage() throws IOException {
|
||||||
|
|
|
@ -189,6 +189,7 @@ public class TestLazyProxSkipping extends LuceneTestCase {
|
||||||
|
|
||||||
|
|
||||||
SeeksCountingStream(IndexInput input) {
|
SeeksCountingStream(IndexInput input) {
|
||||||
|
super("SeekCountingStream(" + input + ")");
|
||||||
this.input = input;
|
this.input = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,6 +152,7 @@ public class TestMultiLevelSkipList extends LuceneTestCase {
|
||||||
private IndexInput input;
|
private IndexInput input;
|
||||||
|
|
||||||
CountingStream(IndexInput input) {
|
CountingStream(IndexInput input) {
|
||||||
|
super("CountingStream(" + input + ")");
|
||||||
this.input = input;
|
this.input = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ public class TestBufferedIndexInput extends LuceneTestCase {
|
||||||
writeBytes(tmpInputFile, TEST_FILE_LENGTH);
|
writeBytes(tmpInputFile, TEST_FILE_LENGTH);
|
||||||
|
|
||||||
// run test with chunk size of 10 bytes
|
// run test with chunk size of 10 bytes
|
||||||
runReadBytesAndClose(new SimpleFSIndexInput(tmpInputFile,
|
runReadBytesAndClose(new SimpleFSIndexInput("SimpleFSIndexInput(path=\"" + tmpInputFile + "\")", tmpInputFile,
|
||||||
newIOContext(random), 10), inputBufferSize, random);
|
newIOContext(random), 10), inputBufferSize, random);
|
||||||
|
|
||||||
// run test with chunk size of 10 bytes
|
// run test with chunk size of 10 bytes
|
||||||
|
@ -211,6 +211,7 @@ public class TestBufferedIndexInput extends LuceneTestCase {
|
||||||
private long pos;
|
private long pos;
|
||||||
private long len;
|
private long len;
|
||||||
public MyBufferedIndexInput(long len){
|
public MyBufferedIndexInput(long len){
|
||||||
|
super("MyBufferedIndexInput(len=" + len + ")", BufferedIndexInput.BUFFER_SIZE);
|
||||||
this.len = len;
|
this.len = len;
|
||||||
this.pos = 0;
|
this.pos = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class TestHugeRamFile extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
out.close();
|
out.close();
|
||||||
// input part
|
// input part
|
||||||
RAMInputStream in = new RAMInputStream(f);
|
RAMInputStream in = new RAMInputStream("testcase", f);
|
||||||
assertEquals("input length must match",n,in.length());
|
assertEquals("input length must match",n,in.length());
|
||||||
//System.out.println("input length = "+in.length()+" % 1024 = "+in.length()%1024);
|
//System.out.println("input length = "+in.length()+" % 1024 = "+in.length()%1024);
|
||||||
for (int j=0; j<L; j++) {
|
for (int j=0; j<L; j++) {
|
||||||
|
|
|
@ -1,14 +1,5 @@
|
||||||
package org.apache.lucene.util;
|
package org.apache.lucene.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import org.apache.lucene.store.IOContext;
|
|
||||||
import org.apache.lucene.store.IndexInput;
|
|
||||||
import org.apache.lucene.store.IndexOutput;
|
|
||||||
import org.apache.lucene.store.RAMDirectory;
|
|
||||||
import org.apache.lucene.util.ThreadInterruptedException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
@ -26,6 +17,14 @@ import org.apache.lucene.util.ThreadInterruptedException;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.apache.lucene.store.IOContext;
|
||||||
|
import org.apache.lucene.store.IndexInput;
|
||||||
|
import org.apache.lucene.store.IndexOutput;
|
||||||
|
import org.apache.lucene.store.RAMDirectory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test utility - slow directory
|
* Test utility - slow directory
|
||||||
*/
|
*/
|
||||||
|
@ -84,6 +83,7 @@ public class SlowRAMDirectory extends RAMDirectory {
|
||||||
private int numRead = 0;
|
private int numRead = 0;
|
||||||
|
|
||||||
public SlowIndexInput(IndexInput ii) {
|
public SlowIndexInput(IndexInput ii) {
|
||||||
|
super("SlowIndexInput(" + ii + ")");
|
||||||
this.ii = ii;
|
this.ii = ii;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue