From 7582af27b079d0a7df8e11a6c9c23ffdd9adb907 Mon Sep 17 00:00:00 2001 From: "Yunfeng,Wu" Date: Fri, 6 Sep 2019 15:44:55 +0800 Subject: [PATCH] Resolve the incorrect scroll_current when delete or close index (#45226) Resolve the incorrect current scroll for deleted or closed index --- .../index/search/stats/SearchStats.java | 23 +++++++++++++++++++ .../elasticsearch/indices/IndicesService.java | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/index/search/stats/SearchStats.java b/server/src/main/java/org/elasticsearch/index/search/stats/SearchStats.java index 5f514b89b64..7dc3ae4785c 100644 --- a/server/src/main/java/org/elasticsearch/index/search/stats/SearchStats.java +++ b/server/src/main/java/org/elasticsearch/index/search/stats/SearchStats.java @@ -117,6 +117,22 @@ public class SearchStats implements Writeable, ToXContentFragment { suggestCurrent += stats.suggestCurrent; } + public void addForClosingShard(Stats stats) { + queryCount += stats.queryCount; + queryTimeInMillis += stats.queryTimeInMillis; + + fetchCount += stats.fetchCount; + fetchTimeInMillis += stats.fetchTimeInMillis; + + scrollCount += stats.scrollCount; + scrollTimeInMillis += stats.scrollTimeInMillis; + // need consider the count of the shard's current scroll + scrollCount += stats.scrollCurrent; + + suggestCount += stats.suggestCount; + suggestTimeInMillis += stats.suggestTimeInMillis; + } + public long getQueryCount() { return queryCount; } @@ -274,6 +290,13 @@ public class SearchStats implements Writeable, ToXContentFragment { totalStats.add(searchStats.totalStats); } + public void addTotalsForClosingShard(SearchStats searchStats) { + if (searchStats == null) { + return; + } + totalStats.addForClosingShard(searchStats.totalStats); + } + public Stats getTotal() { return this.totalStats; } diff --git a/server/src/main/java/org/elasticsearch/indices/IndicesService.java b/server/src/main/java/org/elasticsearch/indices/IndicesService.java index 1fa49966344..38ab7149521 100644 --- a/server/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/server/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -727,7 +727,8 @@ public class IndicesService extends AbstractLifecycleComponent if (indexShard != null) { getStats.addTotals(indexShard.getStats()); indexingStats.addTotals(indexShard.indexingStats()); - searchStats.addTotals(indexShard.searchStats()); + // if this index was closed or deleted, we should eliminate the effect of the current scroll for this shard + searchStats.addTotalsForClosingShard(indexShard.searchStats()); mergeStats.addTotals(indexShard.mergeStats()); refreshStats.addTotals(indexShard.refreshStats()); flushStats.addTotals(indexShard.flushStats());