From 147c5e65d35f4397b9fbeef56a8104a8c80ec741 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 15 Jan 2019 09:39:53 +0100 Subject: [PATCH] Remove dead code from ShardSearchStats (#37421) The clear methodsa are unused and unsafe at this point. This commit removes the dead code. --- .../index/search/stats/ShardSearchStats.java | 49 +++++-------------- 1 file changed, 11 insertions(+), 38 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/search/stats/ShardSearchStats.java b/server/src/main/java/org/elasticsearch/index/search/stats/ShardSearchStats.java index 342b638db31..0a19702e595 100644 --- a/server/src/main/java/org/elasticsearch/index/search/stats/ShardSearchStats.java +++ b/server/src/main/java/org/elasticsearch/index/search/stats/ShardSearchStats.java @@ -122,27 +122,11 @@ public final class ShardSearchStats implements SearchOperationListener { }); } - public void clear() { - totalStats.clear(); - synchronized (this) { - if (!groupsStats.isEmpty()) { - MapBuilder typesStatsBuilder = MapBuilder.newMapBuilder(); - for (Map.Entry typeStats : groupsStats.entrySet()) { - if (typeStats.getValue().totalCurrent() > 0) { - typeStats.getValue().clear(); - typesStatsBuilder.put(typeStats.getKey(), typeStats.getValue()); - } - } - groupsStats = typesStatsBuilder.immutableMap(); - } - } - } - private void computeStats(SearchContext searchContext, Consumer consumer) { consumer.accept(totalStats); if (searchContext.groupStats() != null) { - for (int i = 0; i < searchContext.groupStats().size(); i++) { - consumer.accept(groupStats(searchContext.groupStats().get(i))); + for (String group : searchContext.groupStats()) { + consumer.accept(groupStats(group)); } } } @@ -184,8 +168,8 @@ public final class ShardSearchStats implements SearchOperationListener { } static final class StatsHolder { - public final MeanMetric queryMetric = new MeanMetric(); - public final MeanMetric fetchMetric = new MeanMetric(); + final MeanMetric queryMetric = new MeanMetric(); + final MeanMetric fetchMetric = new MeanMetric(); /* We store scroll statistics in microseconds because with nanoseconds we run the risk of overflowing the total stats if there are * many scrolls. For example, on a system with 2^24 scrolls that have been executed, each executing for 2^10 seconds, then using * nanoseconds would require a numeric representation that can represent at least 2^24 * 2^10 * 10^9 > 2^24 * 2^10 * 2^29 = 2^63 @@ -193,14 +177,14 @@ public final class ShardSearchStats implements SearchOperationListener { * times as many scrolls (i.e., billions of scrolls which at one per second would take 32 years to occur), or scrolls that execute * for one-thousand times as long (i.e., scrolls that execute for almost twelve days on average). */ - public final MeanMetric scrollMetric = new MeanMetric(); - public final MeanMetric suggestMetric = new MeanMetric(); - public final CounterMetric queryCurrent = new CounterMetric(); - public final CounterMetric fetchCurrent = new CounterMetric(); - public final CounterMetric scrollCurrent = new CounterMetric(); - public final CounterMetric suggestCurrent = new CounterMetric(); + final MeanMetric scrollMetric = new MeanMetric(); + final MeanMetric suggestMetric = new MeanMetric(); + final CounterMetric queryCurrent = new CounterMetric(); + final CounterMetric fetchCurrent = new CounterMetric(); + final CounterMetric scrollCurrent = new CounterMetric(); + final CounterMetric suggestCurrent = new CounterMetric(); - public SearchStats.Stats stats() { + SearchStats.Stats stats() { return new SearchStats.Stats( queryMetric.count(), TimeUnit.NANOSECONDS.toMillis(queryMetric.sum()), queryCurrent.count(), fetchMetric.count(), TimeUnit.NANOSECONDS.toMillis(fetchMetric.sum()), fetchCurrent.count(), @@ -208,16 +192,5 @@ public final class ShardSearchStats implements SearchOperationListener { suggestMetric.count(), TimeUnit.NANOSECONDS.toMillis(suggestMetric.sum()), suggestCurrent.count() ); } - - public long totalCurrent() { - return queryCurrent.count() + fetchCurrent.count() + scrollCurrent.count() + suggestCurrent.count(); - } - - public void clear() { - queryMetric.clear(); - fetchMetric.clear(); - scrollMetric.clear(); - suggestMetric.clear(); - } } }