mirror of https://github.com/apache/lucene.git
also assert points stats docCount <= maxDoc, and docCount >=0 and size >= 0
This commit is contained in:
parent
c16f73aa91
commit
2d5519a0ee
|
@ -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);
|
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 (globalMinPackedValue == null) {
|
||||||
if (size != 0) {
|
if (size != 0) {
|
||||||
throw new RuntimeException("getMinPackedValue is null points for field \"" + fieldInfo.name + "\" yet size=" + size);
|
throw new RuntimeException("getMinPackedValue is null points for field \"" + fieldInfo.name + "\" yet size=" + size);
|
||||||
|
|
|
@ -64,7 +64,7 @@ public final class AssertingPointFormat extends PointFormat {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PointReader fieldsReader(SegmentReadState state) throws IOException {
|
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 */
|
/** 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 {
|
static class AssertingPointReader extends PointReader {
|
||||||
private final PointReader in;
|
private final PointReader in;
|
||||||
|
private final int maxDoc;
|
||||||
|
|
||||||
AssertingPointReader(PointReader in) {
|
AssertingPointReader(int maxDoc, PointReader in) {
|
||||||
this.in = in;
|
this.in = in;
|
||||||
|
this.maxDoc = maxDoc;
|
||||||
// do a few simple checks on init
|
// do a few simple checks on init
|
||||||
assert toString() != null;
|
assert toString() != null;
|
||||||
assert ramBytesUsed() >= 0;
|
assert ramBytesUsed() >= 0;
|
||||||
|
@ -188,7 +190,7 @@ public final class AssertingPointFormat extends PointFormat {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PointReader getMergeInstance() throws IOException {
|
public PointReader getMergeInstance() throws IOException {
|
||||||
return new AssertingPointReader(in.getMergeInstance());
|
return new AssertingPointReader(maxDoc, in.getMergeInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -198,35 +200,46 @@ public final class AssertingPointFormat extends PointFormat {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getMinPackedValue(String fieldName) throws IOException {
|
public byte[] getMinPackedValue(String fieldName) throws IOException {
|
||||||
|
assertStats(fieldName);
|
||||||
return in.getMinPackedValue(fieldName);
|
return in.getMinPackedValue(fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getMaxPackedValue(String fieldName) throws IOException {
|
public byte[] getMaxPackedValue(String fieldName) throws IOException {
|
||||||
|
assertStats(fieldName);
|
||||||
return in.getMaxPackedValue(fieldName);
|
return in.getMaxPackedValue(fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNumDimensions(String fieldName) throws IOException {
|
public int getNumDimensions(String fieldName) throws IOException {
|
||||||
|
assertStats(fieldName);
|
||||||
return in.getNumDimensions(fieldName);
|
return in.getNumDimensions(fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBytesPerDimension(String fieldName) throws IOException {
|
public int getBytesPerDimension(String fieldName) throws IOException {
|
||||||
|
assertStats(fieldName);
|
||||||
return in.getBytesPerDimension(fieldName);
|
return in.getBytesPerDimension(fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long size(String fieldName) {
|
public long size(String fieldName) {
|
||||||
// TODO: what to assert?
|
assertStats(fieldName);
|
||||||
return in.size(fieldName);
|
return in.size(fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getDocCount(String fieldName) {
|
public int getDocCount(String fieldName) {
|
||||||
// TODO: what to assert?
|
assertStats(fieldName);
|
||||||
return in.getDocCount(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 {
|
static class AssertingPointWriter extends PointWriter {
|
||||||
|
|
Loading…
Reference in New Issue