Alter ShardSearchStats
@@ -122,6 +122,22 @@ public final class ShardSearchStats implements SearchOperationListener {
});
}
+ public void clear() {
+ totalStats.clear();
+ synchronized (this) {
+ if (!groupsStats.isEmpty()) {
+ MapBuilder<String, StatsHolder> typesStatsBuilder = MapBuilder.newMapBuilder();
+ for (Map.Entry<String, StatsHolder> 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<StatsHolder> consumer) {
consumer.accept(totalStats);
if (searchContext.groupStats() != null) {
@@ -167,9 +183,9 @@ public final class ShardSearchStats implements SearchOperationListener {
totalStats.scrollMetric.inc(TimeUnit.NANOSECONDS.toMicros(System.nanoTime() - context.getOriginNanoTime()));
}
- static final class StatsHolder {
- final MeanMetric queryMetric = new MeanMetric();
- final MeanMetric fetchMetric = new MeanMetric();
+ public static final class StatsHolder {
+ public final MeanMetric queryMetric = new MeanMetric();
+ public 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
@@ -177,12 +193,12 @@ 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).
*/
- 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 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();
SearchStats.Stats stats() {
return new SearchStats.Stats(
@@ -192,5 +208,16 @@ 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();
+ }
}
}
