From d29a8d3ec141e02d3697d3a9a75574ec35384aaa Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Thu, 14 Oct 2021 10:08:20 +0200 Subject: [PATCH] Allow field usage tracker to be concurrent accessed (#79088) While Lucene readers are currently only sequentially accessed, we expect future usages (and custom plugins) to access this concurrently. Closes #78899 --- .../search/stats/ShardFieldUsageTracker.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/search/stats/ShardFieldUsageTracker.java b/server/src/main/java/org/elasticsearch/index/search/stats/ShardFieldUsageTracker.java index fc7d48db8f06f..ebac9f3e9d370 100644 --- a/server/src/main/java/org/elasticsearch/index/search/stats/ShardFieldUsageTracker.java +++ b/server/src/main/java/org/elasticsearch/index/search/stats/ShardFieldUsageTracker.java @@ -75,22 +75,24 @@ static class InternalFieldStats { } static class PerField { - boolean terms; - boolean postings; - boolean termFrequencies; - boolean positions; - boolean offsets; - boolean docValues; - boolean storedFields; - boolean norms; - boolean payloads; - boolean termVectors; - boolean points; + // while these fields are currently only sequentially accessed, we expect concurrent access by future usages (and custom plugins) + volatile boolean terms; + volatile boolean postings; + volatile boolean termFrequencies; + volatile boolean positions; + volatile boolean offsets; + volatile boolean docValues; + volatile boolean storedFields; + volatile boolean norms; + volatile boolean payloads; + volatile boolean termVectors; + volatile boolean points; } public class FieldUsageStatsTrackingSession implements FieldUsageNotifier, Releasable { - private final Map usages = new HashMap<>(); + // while this map is currently only sequentially accessed, we expect future usages (and custom plugins) to access this concurrently + private final Map usages = new ConcurrentHashMap<>(); @Override public void close() {