From c93b5727b303823789a2be432dec4dc7d108274b Mon Sep 17 00:00:00 2001 From: Mryange <59914473+Mryange@users.noreply.github.com> Date: Thu, 30 Nov 2023 21:45:15 +0800 Subject: [PATCH] [fix](profile) fix double add in aggcounter #27826 --- .../apache/doris/common/util/AggCounter.java | 24 ++++++++++++------- .../doris/common/util/RuntimeProfile.java | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/util/AggCounter.java b/fe/fe-core/src/main/java/org/apache/doris/common/util/AggCounter.java index ed8f91533f..d7eb718495 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/common/util/AggCounter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/AggCounter.java @@ -26,18 +26,24 @@ public class AggCounter extends Counter { Counter min; int number; - public AggCounter(org.apache.doris.thrift.TUnit type, long value) { - super(type, value); - max = new Counter(type, value); - sum = new Counter(type, value); - min = new Counter(type, value); - number = 1; + public AggCounter(org.apache.doris.thrift.TUnit type) { + super(type, 0); + max = new Counter(type, 0); + sum = new Counter(type, 0); + min = new Counter(type, 0); + number = 0; } public void addCounter(Counter counter) { - max.maxValue(counter); - sum.addValue(counter); - min.minValue(counter); + if (number == 0) { + max.setValue(counter.getValue()); + sum.setValue(counter.getValue()); + min.setValue(counter.getValue()); + } else { + max.maxValue(counter); + sum.addValue(counter); + min.minValue(counter); + } number++; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/util/RuntimeProfile.java b/fe/fe-core/src/main/java/org/apache/doris/common/util/RuntimeProfile.java index 432171e9ce..41e3738f0a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/common/util/RuntimeProfile.java +++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/RuntimeProfile.java @@ -494,7 +494,7 @@ public class RuntimeProfile { mergeCounters(childCounterName, profiles, simpleProfile); if (counter.getLevel() == 1) { Counter oldCounter = profiles.get(0).counterMap.get(childCounterName); - AggCounter aggCounter = new AggCounter(oldCounter.getType(), oldCounter.getValue()); + AggCounter aggCounter = new AggCounter(oldCounter.getType()); for (RuntimeProfile profile : profiles) { Counter orgCounter = profile.counterMap.get(childCounterName); aggCounter.addCounter(orgCounter);