From 9bea7cbda842f85f8d462b2bab1bce93d8812510 Mon Sep 17 00:00:00 2001 From: Alex Chow Date: Thu, 24 Sep 2015 17:23:08 -0700 Subject: [PATCH] Omit current* stats for OldShardStats (closes #13386) --- .../org/elasticsearch/index/flush/FlushStats.java | 4 ++++ .../java/org/elasticsearch/index/get/GetStats.java | 8 ++++++++ .../index/indexing/IndexingStats.java | 9 ++++++++- .../org/elasticsearch/index/merge/MergeStats.java | 14 +++++++++++--- .../index/recovery/RecoveryStats.java | 8 ++------ .../elasticsearch/index/refresh/RefreshStats.java | 4 ++++ .../index/search/stats/SearchStats.java | 9 ++++++++- .../org/elasticsearch/indices/IndicesService.java | 14 +++++++------- 8 files changed, 52 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/flush/FlushStats.java b/core/src/main/java/org/elasticsearch/index/flush/FlushStats.java index 0566442c189..a1d18c13506 100644 --- a/core/src/main/java/org/elasticsearch/index/flush/FlushStats.java +++ b/core/src/main/java/org/elasticsearch/index/flush/FlushStats.java @@ -50,6 +50,10 @@ public class FlushStats implements Streamable, ToXContent { } public void add(FlushStats flushStats) { + addTotals(flushStats); + } + + public void addTotals(FlushStats flushStats) { if (flushStats == null) { return; } diff --git a/core/src/main/java/org/elasticsearch/index/get/GetStats.java b/core/src/main/java/org/elasticsearch/index/get/GetStats.java index fa7730c21d7..876c9ac565a 100644 --- a/core/src/main/java/org/elasticsearch/index/get/GetStats.java +++ b/core/src/main/java/org/elasticsearch/index/get/GetStats.java @@ -51,6 +51,14 @@ public class GetStats implements Streamable, ToXContent { } public void add(GetStats stats) { + if (stats == null) { + return; + } + current += stats.current; + addTotals(stats); + } + + public void addTotals(GetStats stats) { if (stats == null) { return; } diff --git a/core/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java b/core/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java index af4add91329..3df62994f96 100644 --- a/core/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java +++ b/core/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java @@ -232,7 +232,7 @@ public class IndexingStats implements Streamable, ToXContent { if (indexingStats == null) { return; } - totalStats.add(indexingStats.totalStats); + addTotals(indexingStats); if (includeTypes && indexingStats.typeStats != null && !indexingStats.typeStats.isEmpty()) { if (typeStats == null) { typeStats = new HashMap<>(indexingStats.typeStats.size()); @@ -248,6 +248,13 @@ public class IndexingStats implements Streamable, ToXContent { } } + public void addTotals(IndexingStats indexingStats) { + if (indexingStats == null) { + return; + } + totalStats.add(indexingStats.totalStats); + } + public Stats getTotal() { return this.totalStats; } diff --git a/core/src/main/java/org/elasticsearch/index/merge/MergeStats.java b/core/src/main/java/org/elasticsearch/index/merge/MergeStats.java index 055558cc563..bcacb3516da 100644 --- a/core/src/main/java/org/elasticsearch/index/merge/MergeStats.java +++ b/core/src/main/java/org/elasticsearch/index/merge/MergeStats.java @@ -76,6 +76,17 @@ public class MergeStats implements Streamable, ToXContent { } public void add(MergeStats mergeStats) { + if (mergeStats == null) { + return; + } + this.current += mergeStats.current; + this.currentNumDocs += mergeStats.currentNumDocs; + this.currentSizeInBytes += mergeStats.currentSizeInBytes; + + addTotals(mergeStats); + } + + public void addTotals(MergeStats mergeStats) { if (mergeStats == null) { return; } @@ -83,9 +94,6 @@ public class MergeStats implements Streamable, ToXContent { this.totalTimeInMillis += mergeStats.totalTimeInMillis; this.totalNumDocs += mergeStats.totalNumDocs; this.totalSizeInBytes += mergeStats.totalSizeInBytes; - this.current += mergeStats.current; - this.currentNumDocs += mergeStats.currentNumDocs; - this.currentSizeInBytes += mergeStats.currentSizeInBytes; this.totalStoppedTimeInMillis += mergeStats.totalStoppedTimeInMillis; this.totalThrottledTimeInMillis += mergeStats.totalThrottledTimeInMillis; if (this.totalBytesPerSecAutoThrottle == Long.MAX_VALUE || mergeStats.totalBytesPerSecAutoThrottle == Long.MAX_VALUE) { diff --git a/core/src/main/java/org/elasticsearch/index/recovery/RecoveryStats.java b/core/src/main/java/org/elasticsearch/index/recovery/RecoveryStats.java index 38ea3402b5d..3f512b3e123 100644 --- a/core/src/main/java/org/elasticsearch/index/recovery/RecoveryStats.java +++ b/core/src/main/java/org/elasticsearch/index/recovery/RecoveryStats.java @@ -47,15 +47,11 @@ public class RecoveryStats implements ToXContent, Streamable { if (recoveryStats != null) { this.currentAsSource.addAndGet(recoveryStats.currentAsSource()); this.currentAsTarget.addAndGet(recoveryStats.currentAsTarget()); - this.throttleTimeInNanos.addAndGet(recoveryStats.throttleTime().nanos()); } + addTotals(recoveryStats); } - /** - * add statistics that should be accumulated about old shards after they have been - * deleted or relocated - */ - public void addAsOld(RecoveryStats recoveryStats) { + public void addTotals(RecoveryStats recoveryStats) { if (recoveryStats != null) { this.throttleTimeInNanos.addAndGet(recoveryStats.throttleTime().nanos()); } diff --git a/core/src/main/java/org/elasticsearch/index/refresh/RefreshStats.java b/core/src/main/java/org/elasticsearch/index/refresh/RefreshStats.java index e98a0290ea6..4ef6e9dbb31 100644 --- a/core/src/main/java/org/elasticsearch/index/refresh/RefreshStats.java +++ b/core/src/main/java/org/elasticsearch/index/refresh/RefreshStats.java @@ -50,6 +50,10 @@ public class RefreshStats implements Streamable, ToXContent { } public void add(RefreshStats refreshStats) { + addTotals(refreshStats); + } + + public void addTotals(RefreshStats refreshStats) { if (refreshStats == null) { return; } diff --git a/core/src/main/java/org/elasticsearch/index/search/stats/SearchStats.java b/core/src/main/java/org/elasticsearch/index/search/stats/SearchStats.java index 2d3ee81d0ce..c35a4cdbadb 100644 --- a/core/src/main/java/org/elasticsearch/index/search/stats/SearchStats.java +++ b/core/src/main/java/org/elasticsearch/index/search/stats/SearchStats.java @@ -221,7 +221,7 @@ public class SearchStats implements Streamable, ToXContent { if (searchStats == null) { return; } - totalStats.add(searchStats.totalStats); + addTotals(searchStats); openContexts += searchStats.openContexts; if (includeTypes && searchStats.groupStats != null && !searchStats.groupStats.isEmpty()) { if (groupStats == null) { @@ -238,6 +238,13 @@ public class SearchStats implements Streamable, ToXContent { } } + public void addTotals(SearchStats searchStats) { + if (searchStats == null) { + return; + } + totalStats.add(searchStats.totalStats); + } + public Stats getTotal() { return this.totalStats; } diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesService.java b/core/src/main/java/org/elasticsearch/indices/IndicesService.java index 9cb8ec81634..7df98be3cdc 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -446,13 +446,13 @@ public class IndicesService extends AbstractLifecycleComponent i public synchronized void beforeIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard, @IndexSettings Settings indexSettings) { if (indexShard != null) { - getStats.add(indexShard.getStats()); - indexingStats.add(indexShard.indexingStats(), false); - searchStats.add(indexShard.searchStats(), false); - mergeStats.add(indexShard.mergeStats()); - refreshStats.add(indexShard.refreshStats()); - flushStats.add(indexShard.flushStats()); - recoveryStats.addAsOld(indexShard.recoveryStats()); + getStats.addTotals(indexShard.getStats()); + indexingStats.addTotals(indexShard.indexingStats()); + searchStats.addTotals(indexShard.searchStats()); + mergeStats.addTotals(indexShard.mergeStats()); + refreshStats.addTotals(indexShard.refreshStats()); + flushStats.addTotals(indexShard.flushStats()); + recoveryStats.addTotals(indexShard.recoveryStats()); } } }