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 2016/03/03 12:08:47 UTC

[8/9] lucene-solr git commit: also assert points stats docCount <= maxDoc, and docCount >=0 and size >= 0

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


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/2d5519a0
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/2d5519a0
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/2d5519a0

Branch: refs/heads/master
Commit: 2d5519a0ee7415a62356c3bc93fd80206811a8ac
Parents: c16f73a
Author: Mike McCandless <mi...@apache.org>
Authored: Thu Mar 3 05:48:15 2016 -0500
Committer: Mike McCandless <mi...@apache.org>
Committed: Thu Mar 3 05:48:15 2016 -0500

----------------------------------------------------------------------
 .../org/apache/lucene/index/CheckIndex.java     |  4 ++++
 .../codecs/asserting/AssertingPointFormat.java  | 23 +++++++++++++++-----
 2 files changed, 22 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2d5519a0/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
index 012f88a..1da69c1 100644
--- a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
+++ b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
@@ -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);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2d5519a0/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingPointFormat.java
----------------------------------------------------------------------
diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingPointFormat.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingPointFormat.java
index 892eeef..07365e0 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingPointFormat.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingPointFormat.java
@@ -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 {