Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ConcurrentHashMap in SCAN search to keep track of the reader states. #7499

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/main/java/org/elasticsearch/search/scan/ScanContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@

package org.elasticsearch.search.scan;

import com.google.common.collect.Maps;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.*;
import org.apache.lucene.util.Bits;
import org.elasticsearch.common.lucene.docset.AllDocIdSet;
import org.elasticsearch.common.lucene.search.XFilteredQuery;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.search.internal.SearchContext;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;

/**
* The scan context allows to optimize readers we already processed during scanning. We do that by keeping track
Expand All @@ -39,7 +39,7 @@
*/
public class ScanContext {

private final Map<IndexReader, ReaderState> readerStates = Maps.newHashMap();
private final ConcurrentMap<IndexReader, ReaderState> readerStates = ConcurrentCollections.newConcurrentMap();

public void clear() {
readerStates.clear();
Expand All @@ -58,7 +58,7 @@ public TopDocs execute(SearchContext context) throws IOException {

static class ScanCollector extends Collector {

private final Map<IndexReader, ReaderState> readerStates;
private final ConcurrentMap<IndexReader, ReaderState> readerStates;

private final int from;

Expand All @@ -77,7 +77,7 @@ static class ScanCollector extends Collector {
private IndexReader currentReader;
private ReaderState readerState;

ScanCollector(Map<IndexReader, ReaderState> readerStates, int from, int size, boolean trackScores) {
ScanCollector(ConcurrentMap<IndexReader, ReaderState> readerStates, int from, int size, boolean trackScores) {
this.readerStates = readerStates;
this.from = from;
this.to = from + size;
Expand Down Expand Up @@ -142,11 +142,11 @@ public Throwable fillInStackTrace() {

public static class ScanFilter extends Filter {

private final Map<IndexReader, ReaderState> readerStates;
private final ConcurrentMap<IndexReader, ReaderState> readerStates;

private final ScanCollector scanCollector;

public ScanFilter(Map<IndexReader, ReaderState> readerStates, ScanCollector scanCollector) {
public ScanFilter(ConcurrentMap<IndexReader, ReaderState> readerStates, ScanCollector scanCollector) {
this.readerStates = readerStates;
this.scanCollector = scanCollector;
}
Expand Down