aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeniy Ivanov <i@eivanov.com>2022-04-19 04:02:59 +0300
committerEvgeniy Ivanov <i@eivanov.com>2022-04-19 04:02:59 +0300
commit7481c6ac6ea9234349cb9d05bbbfe568c6031416 (patch)
tree141df2fdbe6b5774ca7640cac653599edd2e1765
parent1faabd482e1e40c7130ad45feb777b323d4d143c (diff)
downloadydb-7481c6ac6ea9234349cb9d05bbbfe568c6031416.tar.gz
KIKIMR-14646: fix histogram aggregation
ref:a1a81d5dbd762f7b5c6aaa11bc18eaca5ad3f50b
-rw-r--r--ydb/core/tablet/tablet_counters_aggregator.cpp3
-rw-r--r--ydb/core/tablet/tablet_counters_aggregator_ut.cpp54
2 files changed, 56 insertions, 1 deletions
diff --git a/ydb/core/tablet/tablet_counters_aggregator.cpp b/ydb/core/tablet/tablet_counters_aggregator.cpp
index d90b1771d80..cb3229334b2 100644
--- a/ydb/core/tablet/tablet_counters_aggregator.cpp
+++ b/ydb/core/tablet/tablet_counters_aggregator.cpp
@@ -462,11 +462,12 @@ public:
TCountersByTabletIDMap::insert_ctx insertCtx;
auto it = CountersByTabletID[counterIndex].find(tabletID, insertCtx);
if (it != CountersByTabletID[counterIndex].end()) {
- const auto& oldValues = it->second;
+ auto& oldValues = it->second;
if (newValues != oldValues) {
SubValues(counterIndex, oldValues);
AddValues(counterIndex, newValues);
}
+ oldValues.swap(newValues);
} else {
AddValues(counterIndex, newValues);
CountersByTabletID[counterIndex].insert_direct(std::make_pair(tabletID, std::move(newValues)), insertCtx);
diff --git a/ydb/core/tablet/tablet_counters_aggregator_ut.cpp b/ydb/core/tablet/tablet_counters_aggregator_ut.cpp
index 69d80f7572d..a055fe12722 100644
--- a/ydb/core/tablet/tablet_counters_aggregator_ut.cpp
+++ b/ydb/core/tablet/tablet_counters_aggregator_ut.cpp
@@ -474,6 +474,60 @@ Y_UNIT_TEST_SUITE(TTabletCountersAggregator) {
);
}
+ Y_UNIT_TEST(IntegralPercentileAggregationRegularCheckSingleTablet) {
+ // test regular histogram, i.e. not named "HIST"
+ // check that when single tablet sends multiple count updates,
+ // the aggregated value is correct
+ TTestBasicRuntime runtime(1);
+
+ runtime.Initialize(TAppPrepare().Unwrap());
+ TActorId edge = runtime.AllocateEdgeActor();
+
+ auto aggregator = CreateTabletCountersAggregator(false);
+ auto aggregatorId = runtime.Register(aggregator);
+ runtime.EnableScheduleForActor(aggregatorId);
+
+ TDispatchOptions options;
+ options.FinalEvents.emplace_back(TEvents::TSystem::Bootstrap, 1);
+ runtime.DispatchEvents(options);
+
+ TTabletWithHist tablet1(1);
+ tablet1.UpdatePercentile("MyHist", 1);
+ tablet1.SendUpdate(runtime, aggregatorId, edge);
+ tablet1.SendUpdate(runtime, aggregatorId, edge);
+
+ TTabletWithHist::CheckHistogram(
+ runtime,
+ "MyHist",
+ {0, 1, 0, 0},
+ {0, 1, 0, 0}
+ );
+
+ tablet1.UpdatePercentile("MyHist", 13);
+ tablet1.SendUpdate(runtime, aggregatorId, edge);
+ tablet1.SendUpdate(runtime, aggregatorId, edge);
+
+ TTabletWithHist::CheckHistogram(
+ runtime,
+ "MyHist",
+ {0, 1, 1, 0},
+ {0, 1, 1, 0}
+ );
+
+ tablet1.UpdatePercentile("MyHist", 1);
+ tablet1.UpdatePercentile("MyHist", 1);
+ tablet1.UpdatePercentile("MyHist", 100);
+ tablet1.SendUpdate(runtime, aggregatorId, edge);
+ tablet1.SendUpdate(runtime, aggregatorId, edge);
+
+ TTabletWithHist::CheckHistogram(
+ runtime,
+ "MyHist",
+ {0, 3, 1, 1},
+ {0, 3, 1, 1}
+ );
+ }
+
// Regression test for KIKIMR-13457
Y_UNIT_TEST(IntegralPercentileAggregationRegular) {
// test regular histogram, i.e. not named "HIST"