Skip to content

Commit

Permalink
Scan: Use ConcurrentHashMap instead of HashMap, because the readerSta…
Browse files Browse the repository at this point in the history
…tes is accessed by multiple threads during the entire scroll session.

Closes elastic#7499
Closes elastic#7478
  • Loading branch information
martijnvg committed Aug 28, 2014
1 parent c165e64 commit f536956
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main/java/org/elasticsearch/search/scan/ScanContext.java
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

0 comments on commit f536956

Please sign in to comment.