also assert points stats docCount <= maxDoc, and docCount >=0 and size >= 0

This commit is contained in:
Mike McCandless 2016-03-03 05:48:15 -05:00
parent c16f73aa91
commit 2d5519a0ee
2 changed files with 22 additions and 5 deletions

View File

@ -1716,6 +1716,10 @@ public final class CheckIndex implements Closeable {
throw new RuntimeException("point values for field \"" + fieldInfo.name + "\" claims to have size=" + size + " points and inconsistent docCount=" + docCount);
}
if (docCount > reader.maxDoc()) {
throw new RuntimeException("point values for field \"" + fieldInfo.name + "\" claims to have docCount=" + docCount + " but that's greater than maxDoc=" + reader.maxDoc());
}
if (globalMinPackedValue == null) {
if (size != 0) {
throw new RuntimeException("getMinPackedValue is null points for field \"" + fieldInfo.name + "\" yet size=" + size);

View File

@ -64,7 +64,7 @@ public final class AssertingPointFormat extends PointFormat {
@Override
public PointReader fieldsReader(SegmentReadState state) throws IOException {
return new AssertingPointReader(in.fieldsReader(state));
return new AssertingPointReader(state.segmentInfo.maxDoc(), in.fieldsReader(state));
}
/** Validates in the 1D case that all points are visited in order, and point values are in bounds of the last cell checked */
@ -146,9 +146,11 @@ public final class AssertingPointFormat extends PointFormat {
static class AssertingPointReader extends PointReader {
private final PointReader in;
private final int maxDoc;
AssertingPointReader(PointReader in) {
AssertingPointReader(int maxDoc, PointReader in) {
this.in = in;
this.maxDoc = maxDoc;
// do a few simple checks on init
assert toString() != null;
assert ramBytesUsed() >= 0;
@ -188,7 +190,7 @@ public final class AssertingPointFormat extends PointFormat {
@Override
public PointReader getMergeInstance() throws IOException {
return new AssertingPointReader(in.getMergeInstance());
return new AssertingPointReader(maxDoc, in.getMergeInstance());
}
@Override
@ -198,35 +200,46 @@ public final class AssertingPointFormat extends PointFormat {
@Override
public byte[] getMinPackedValue(String fieldName) throws IOException {
assertStats(fieldName);
return in.getMinPackedValue(fieldName);
}
@Override
public byte[] getMaxPackedValue(String fieldName) throws IOException {
assertStats(fieldName);
return in.getMaxPackedValue(fieldName);
}
@Override
public int getNumDimensions(String fieldName) throws IOException {
assertStats(fieldName);
return in.getNumDimensions(fieldName);
}
@Override
public int getBytesPerDimension(String fieldName) throws IOException {
assertStats(fieldName);
return in.getBytesPerDimension(fieldName);
}
@Override
public long size(String fieldName) {
// TODO: what to assert?
assertStats(fieldName);
return in.size(fieldName);
}
@Override
public int getDocCount(String fieldName) {
// TODO: what to assert?
assertStats(fieldName);
return in.getDocCount(fieldName);
}
private void assertStats(String fieldName) {
assert in.size(fieldName) >= 0;
assert in.getDocCount(fieldName) >= 0;
assert in.getDocCount(fieldName) <= in.size(fieldName);
assert in.getDocCount(fieldName) <= maxDoc;
}
}
static class AssertingPointWriter extends PointWriter {