Skip to content

Apache Lucene open-source search software

LUCENE-10134: Move initialization of liveDocs bits outside the constructor to avoid AssertionError (#345)

goankurcb366d04d4a6
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/sortedset/ConcurrentSortedSetDocValuesFacetCounts.java b/lucene/facet/src/java/org/apache/lucene/facet/sortedset/ConcurrentSortedSetDocValuesFacetCounts.java
index 09b305b9c3e..1ee786308e4 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/sortedset/ConcurrentSortedSetDocValuesFacetCounts.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/sortedset/ConcurrentSortedSetDocValuesFacetCounts.java
@@ -161,7 +161,6 @@ public class ConcurrentSortedSetDocValuesFacetCounts extends Facets {
final MatchingDocs hits;
final OrdinalMap ordinalMap;
final int segOrd;
- final Bits liveDocs;
public CountOneSegment(
LeafReader leafReader, MatchingDocs hits, OrdinalMap ordinalMap, int segOrd) {
@@ -170,7 +169,6 @@ public class ConcurrentSortedSetDocValuesFacetCounts extends Facets {
this.hits = hits;
this.ordinalMap = ordinalMap;
this.segOrd = segOrd;
- this.liveDocs = leafReader.getLiveDocs();
}
@Override
@@ -198,6 +196,10 @@ public class ConcurrentSortedSetDocValuesFacetCounts extends Facets {
DocIdSetIterator it;
if (hits == null) {
// count all
+ // Initializing liveDocs bits in the constructor leads to a situation where liveDocs bits
+ // get initialized in the calling thread but get used in a different thread leading to an
+ // AssertionError. See LUCENE-10134
+ final Bits liveDocs = leafReader.getLiveDocs();
it = (liveDocs != null) ? FacetUtils.liveDocsDISI(valuesIt, liveDocs) : valuesIt;
} else {
it = ConjunctionUtils.intersectIterators(Arrays.asList(hits.bits.iterator(), valuesIt));