diff --git a/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDTreeDocValuesFormat.java b/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDTreeDocValuesFormat.java index 6333716e766..34598c1014f 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDTreeDocValuesFormat.java +++ b/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDTreeDocValuesFormat.java @@ -40,7 +40,7 @@ import org.apache.lucene.index.SegmentWriteState; * smaller rectangles, until the smallest rectangles have approximately * between X/2 and X (X default is 1024) points in them, at which point * such leaf cells are written as a block to disk, while the index tree - * structure recording how space was sub-divided is loaded into HEAP + * structure records how space was sub-divided is loaded into HEAP * at search time. At search time, the tree is recursed based on whether * each of left or right child overlap with the query shape, and once * a leaf block is reached, all documents in that leaf block are collected diff --git a/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDTreeDocValuesProducer.java b/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDTreeDocValuesProducer.java index 0283a7247d4..1c6706561c9 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDTreeDocValuesProducer.java +++ b/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDTreeDocValuesProducer.java @@ -153,6 +153,7 @@ class BKDTreeDocValuesProducer extends DocValuesProducer { for(Map.Entry ent : treeReaders.entrySet()) { resources.add(Accountables.namedAccountable("field " + ent.getKey(), ent.getValue())); } + resources.add(Accountables.namedAccountable("delegate", delegate)); return resources; } @@ -164,6 +165,6 @@ class BKDTreeDocValuesProducer extends DocValuesProducer { @Override public long ramBytesUsed() { - return ramBytesUsed.get(); + return ramBytesUsed.get() + delegate.ramBytesUsed(); } } diff --git a/lucene/sandbox/src/test/org/apache/lucene/bkdtree/TestBKDTree.java b/lucene/sandbox/src/test/org/apache/lucene/bkdtree/TestBKDTree.java index 4b2c3b40cf7..a1ba2103ca4 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/bkdtree/TestBKDTree.java +++ b/lucene/sandbox/src/test/org/apache/lucene/bkdtree/TestBKDTree.java @@ -35,7 +35,10 @@ import org.apache.lucene.index.Term; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.SimpleCollector; +import org.apache.lucene.search.TopDocs; import org.apache.lucene.store.Directory; +import org.apache.lucene.util.Accountable; +import org.apache.lucene.util.Accountables; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.LuceneTestCase.Nightly; @@ -592,4 +595,24 @@ public class TestBKDTree extends LuceneTestCase { int y = BKDTreeWriter.encodeLon(Math.nextAfter(180.0, Double.POSITIVE_INFINITY)); assertTrue(y < Integer.MAX_VALUE); } + + public void testAccountableHasDelegate() throws Exception { + Directory dir = newDirectory(); + IndexWriterConfig iwc = newIndexWriterConfig(); + Codec codec = TestUtil.alwaysDocValuesFormat(new BKDTreeDocValuesFormat()); + iwc.setCodec(codec); + RandomIndexWriter w = new RandomIndexWriter(random(), dir, iwc); + Document doc = new Document(); + doc.add(new BKDPointField("field", -18.2861, 147.7)); + w.addDocument(doc); + IndexReader r = w.getReader(); + + // We can't wrap with "exotic" readers because the BKD query must see the BKDDVFormat: + IndexSearcher s = newSearcher(r, false); + // Need to run a query so the DV field is really loaded: + TopDocs hits = s.search(new BKDPointInBBoxQuery("field", -30, 0, 140, 150), 1); + assertEquals(1, hits.totalHits); + assertTrue(Accountables.toString((Accountable) r.leaves().get(0).reader()).contains("delegate")); + IOUtils.close(r, w, dir); + } }