Fix concurrency bug in DrillSidewaysQuery (#195)

This commit is contained in:
Greg Miller 2021-06-24 12:18:38 -07:00 committed by GitHub
parent 9942d59f0d
commit 578f5cf51b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -19,6 +19,7 @@ package org.apache.lucene.facet;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -65,12 +66,15 @@ class DrillSidewaysQuery extends Query {
FacetsCollectorManager[] drillSidewaysCollectorManagers, FacetsCollectorManager[] drillSidewaysCollectorManagers,
Query[] drillDownQueries, Query[] drillDownQueries,
boolean scoreSubDocsAtOnce) { boolean scoreSubDocsAtOnce) {
// Note that the "managed" facet collector lists are synchronized here since bulkScorer()
// can be invoked concurrently and needs to remain thread-safe. We're OK with synchronizing
// on the whole list as contention is expected to remain very low:
this( this(
baseQuery, baseQuery,
drillDownCollectorManager, drillDownCollectorManager,
drillSidewaysCollectorManagers, drillSidewaysCollectorManagers,
new ArrayList<>(), Collections.synchronizedList(new ArrayList<>()),
new ArrayList<>(), Collections.synchronizedList(new ArrayList<>()),
drillDownQueries, drillDownQueries,
scoreSubDocsAtOnce); scoreSubDocsAtOnce);
} }