You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ro...@apache.org on 2026/03/02 08:51:18 UTC

(lucene) branch main updated: Fix wrong BitSet result in MemoryAccountingBitsetCollector (#15656)

This is an automated email from the ASF dual-hosted git repository.

romseygeek pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/main by this push:
     new 305d278a627 Fix wrong BitSet result in MemoryAccountingBitsetCollector (#15656)
305d278a627 is described below

commit 305d278a62701671181675824bd36f1f1d7d1385
Author: gaobinlong <gb...@amazon.com>
AuthorDate: Mon Mar 2 16:51:12 2026 +0800

    Fix wrong BitSet result in MemoryAccountingBitsetCollector (#15656)
    
    The Collector was not taking docBase into account, meaning that
    it could set incorrect values for later segments.
---
 lucene/CHANGES.txt                                         |  2 ++
 .../misc/search/MemoryAccountingBitsetCollector.java       |  1 +
 .../misc/search/TestMemoryAccountingBitsetCollector.java   | 14 ++++++++++++++
 3 files changed, 17 insertions(+)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 9d739e1366b..034d232bf90 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -251,6 +251,8 @@ Bug Fixes
 * GITHUB#15731: Fix tessellator failure when a hole is touching another hole in the middle of a segment. In this case
   we might fail to detect it and choose a wrong bridge to eliminate the hole. (Ignacio Vera)
 
+* GITHUB#15656: Fix wrong BitSet result in MemoryAccountingBitsetCollector (Binlong Gao)
+
 Other
 ---------------------
 * GITHUB#15586: Document that scoring and ranking may change across major Lucene versions, and that applications requiring stable ranking should explicitly configure Similarity. (Parveen Saini)
diff --git a/lucene/misc/src/java/org/apache/lucene/misc/search/MemoryAccountingBitsetCollector.java b/lucene/misc/src/java/org/apache/lucene/misc/search/MemoryAccountingBitsetCollector.java
index 21e3c58537a..a2337ab033e 100644
--- a/lucene/misc/src/java/org/apache/lucene/misc/search/MemoryAccountingBitsetCollector.java
+++ b/lucene/misc/src/java/org/apache/lucene/misc/search/MemoryAccountingBitsetCollector.java
@@ -39,6 +39,7 @@ public class MemoryAccountingBitsetCollector extends SimpleCollector {
 
   @Override
   protected void doSetNextReader(LeafReaderContext context) throws IOException {
+    docBase = context.docBase;
     length += context.reader().maxDoc();
     FixedBitSet newBitSet = FixedBitSet.ensureCapacity(bitSet, length);
     if (newBitSet != bitSet) {
diff --git a/lucene/misc/src/test/org/apache/lucene/misc/search/TestMemoryAccountingBitsetCollector.java b/lucene/misc/src/test/org/apache/lucene/misc/search/TestMemoryAccountingBitsetCollector.java
index a77fb564942..b642cf8f171 100644
--- a/lucene/misc/src/test/org/apache/lucene/misc/search/TestMemoryAccountingBitsetCollector.java
+++ b/lucene/misc/src/test/org/apache/lucene/misc/search/TestMemoryAccountingBitsetCollector.java
@@ -70,4 +70,18 @@ public class TestMemoryAccountingBitsetCollector extends LuceneTestCase {
           searcher.search(MatchAllDocsQuery.INSTANCE, bitSetCollector);
         });
   }
+
+  public void testCollectedResult() throws Exception {
+    CollectorMemoryTracker tracker =
+        new CollectorMemoryTracker("testMemoryTracker", Long.MAX_VALUE);
+    MemoryAccountingBitsetCollector collector = new MemoryAccountingBitsetCollector(tracker);
+
+    IndexSearcher searcher = new IndexSearcher(reader);
+    searcher.search(MatchAllDocsQuery.INSTANCE, collector);
+
+    assertEquals(1000, collector.bitSet.cardinality());
+    for (int i = 0; i < 1000; i++) {
+      assertTrue(collector.bitSet.get(i));
+    }
+  }
 }