diff --git a/core/src/main/java/org/elasticsearch/common/util/concurrent/ConcurrentCollections.java b/core/src/main/java/org/elasticsearch/common/util/concurrent/ConcurrentCollections.java index 1f6b0645d4e..5dfd8795909 100644 --- a/core/src/main/java/org/elasticsearch/common/util/concurrent/ConcurrentCollections.java +++ b/core/src/main/java/org/elasticsearch/common/util/concurrent/ConcurrentCollections.java @@ -43,7 +43,14 @@ public abstract class ConcurrentCollections { * Creates a new CHM with an aggressive concurrency level, aimed at high concurrent update rate long living maps. */ public static ConcurrentMap newConcurrentMapWithAggressiveConcurrency() { - return new ConcurrentHashMap<>(16, 0.75f, aggressiveConcurrencyLevel); + return newConcurrentMapWithAggressiveConcurrency(16); + } + + /** + * Creates a new CHM with an aggressive concurrency level, aimed at high concurrent update rate long living maps. + */ + public static ConcurrentMap newConcurrentMapWithAggressiveConcurrency(int initalCapacity) { + return new ConcurrentHashMap<>(initalCapacity, 0.75f, aggressiveConcurrencyLevel); } public static ConcurrentMap newConcurrentMap() { diff --git a/core/src/main/java/org/elasticsearch/index/engine/LiveVersionMap.java b/core/src/main/java/org/elasticsearch/index/engine/LiveVersionMap.java index 7396c3143c6..aef41d9d162 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/LiveVersionMap.java +++ b/core/src/main/java/org/elasticsearch/index/engine/LiveVersionMap.java @@ -102,7 +102,7 @@ class LiveVersionMap implements ReferenceManager.RefreshListener, Accountable { // map. While reopen is running, any lookup will first // try this new map, then fallback to old, then to the // current searcher: - maps = new Maps(ConcurrentCollections.newConcurrentMapWithAggressiveConcurrency(), maps.current); + maps = new Maps(ConcurrentCollections.newConcurrentMapWithAggressiveConcurrency(maps.current.size()), maps.current); // This is not 100% correct, since concurrent indexing ops can change these counters in between our execution of the previous // line and this one, but that should be minor, and the error won't accumulate over time: @@ -117,7 +117,7 @@ class LiveVersionMap implements ReferenceManager.RefreshListener, Accountable { // case. This is because we assign new maps (in beforeRefresh) slightly before Lucene actually flushes any segments for the // reopen, and so any concurrent indexing requests can still sneak in a few additions to that current map that are in fact reflected // in the previous reader. We don't touch tombstones here: they expire on their own index.gc_deletes timeframe: - maps = new Maps(maps.current, ConcurrentCollections.newConcurrentMapWithAggressiveConcurrency()); + maps = new Maps(maps.current, Collections.emptyMap()); } /** Returns the live version (add or delete) for this uid. */