From 5dbd1bf552aa213b35acc07bb8a4f0e881d9e074 Mon Sep 17 00:00:00 2001 From: Konstantin Melekhov Date: Thu, 19 Sep 2024 11:24:11 +0000 Subject: [PATCH 1/2] Fix tx counters bug --- ydb/core/persqueue/partition_write.cpp | 18 ++++++------------ ydb/core/persqueue/percentile_counter.cpp | 9 +++++++++ ydb/core/persqueue/percentile_counter.h | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/ydb/core/persqueue/partition_write.cpp b/ydb/core/persqueue/partition_write.cpp index 1752eed90027..41e6aa387b90 100644 --- a/ydb/core/persqueue/partition_write.cpp +++ b/ydb/core/persqueue/partition_write.cpp @@ -472,20 +472,14 @@ void TPartition::UpdateAfterWriteCounters(bool writeComplete) { // If supportive - update counters only prior to write, otherwise - only after writes; return; } - if (BytesWrittenGrpc) - BytesWrittenGrpc.Inc(WriteNewSizeInternal); - if (BytesWrittenTotal) - BytesWrittenTotal.Inc(WriteNewSize); - - if (BytesWrittenUncompressed) - BytesWrittenUncompressed.Inc(WriteNewSizeUncompressed); + BytesWrittenGrpc.Inc(WriteNewSizeInternal); + BytesWrittenTotal.Inc(WriteNewSize); + BytesWrittenUncompressed.Inc(WriteNewSizeUncompressed); if (BytesWrittenComp) BytesWrittenComp.Inc(WriteCycleSize); - if (MsgsWrittenGrpc) - MsgsWrittenGrpc.Inc(WriteNewMessagesInternal); - if (MsgsWrittenTotal) { - MsgsWrittenTotal.Inc(WriteNewMessages); - } + + MsgsWrittenGrpc.Inc(WriteNewMessagesInternal); + MsgsWrittenTotal.Inc(WriteNewMessages); } void TPartition::HandleWriteResponse(const TActorContext& ctx) { diff --git a/ydb/core/persqueue/percentile_counter.cpp b/ydb/core/persqueue/percentile_counter.cpp index 85edf4a950e4..e9e4d26cb52c 100644 --- a/ydb/core/persqueue/percentile_counter.cpp +++ b/ydb/core/persqueue/percentile_counter.cpp @@ -131,6 +131,12 @@ NKikimr::NPQ::TPercentileCounter CreateSLIDurationCounter( return NKikimr::NPQ::TPercentileCounter(counters->GetSubgroup("sensor", name), aggr, {}, "Duration", buckets, true, false); } +TPartitionCounterWrapper::TPartitionCounterWrapper() + : DoSave(false) + , DoReport(false) +{ +} + TPartitionCounterWrapper::TPartitionCounterWrapper(NKikimr::NPQ::TMultiCounter&& counter, bool isSupportivePartition, bool doReport) { Setup(isSupportivePartition, doReport, std::move(counter)); } @@ -177,6 +183,9 @@ void TPartitionHistogramWrapper::Setup(bool isSupportivePartition, std::unique_p } } void TPartitionHistogramWrapper::IncFor(ui64 key, ui64 value) { + if (!Inited) + return; + if (!IsSupportivePartition) { return Histogram->IncFor(key, value); } diff --git a/ydb/core/persqueue/percentile_counter.h b/ydb/core/persqueue/percentile_counter.h index 89ec2a2dddc9..48bdde888ce1 100644 --- a/ydb/core/persqueue/percentile_counter.h +++ b/ydb/core/persqueue/percentile_counter.h @@ -66,7 +66,7 @@ class TPartitionCounterWrapper { bool Inited = false; public: - TPartitionCounterWrapper() = default; + TPartitionCounterWrapper(); explicit TPartitionCounterWrapper(NKikimr::NPQ::TMultiCounter&& counter, bool isSupportivePartition, bool doReport = true); void Setup(bool isSupportivePartition, bool doReport, NKikimr::NPQ::TMultiCounter&& counter); void Inc(ui64 value); From 8ff243c1c0d7b842fc312ef8d2aeb215afa8f6ed Mon Sep 17 00:00:00 2001 From: Konstantin Melekhov Date: Thu, 19 Sep 2024 11:38:27 +0000 Subject: [PATCH 2/2] Restyle --- ydb/core/persqueue/percentile_counter.cpp | 6 ------ ydb/core/persqueue/percentile_counter.h | 6 +++--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/ydb/core/persqueue/percentile_counter.cpp b/ydb/core/persqueue/percentile_counter.cpp index e9e4d26cb52c..dec88c19391d 100644 --- a/ydb/core/persqueue/percentile_counter.cpp +++ b/ydb/core/persqueue/percentile_counter.cpp @@ -131,12 +131,6 @@ NKikimr::NPQ::TPercentileCounter CreateSLIDurationCounter( return NKikimr::NPQ::TPercentileCounter(counters->GetSubgroup("sensor", name), aggr, {}, "Duration", buckets, true, false); } -TPartitionCounterWrapper::TPartitionCounterWrapper() - : DoSave(false) - , DoReport(false) -{ -} - TPartitionCounterWrapper::TPartitionCounterWrapper(NKikimr::NPQ::TMultiCounter&& counter, bool isSupportivePartition, bool doReport) { Setup(isSupportivePartition, doReport, std::move(counter)); } diff --git a/ydb/core/persqueue/percentile_counter.h b/ydb/core/persqueue/percentile_counter.h index 48bdde888ce1..cb78e7e49b54 100644 --- a/ydb/core/persqueue/percentile_counter.h +++ b/ydb/core/persqueue/percentile_counter.h @@ -59,14 +59,14 @@ NKikimr::NPQ::TPercentileCounter CreateSLIDurationCounter( class TPartitionCounterWrapper { private: - bool DoSave; - bool DoReport; + bool DoSave = false; + bool DoReport = false; TMaybe Counter; ui64 CounterValue = 0; bool Inited = false; public: - TPartitionCounterWrapper(); + TPartitionCounterWrapper() = default; explicit TPartitionCounterWrapper(NKikimr::NPQ::TMultiCounter&& counter, bool isSupportivePartition, bool doReport = true); void Setup(bool isSupportivePartition, bool doReport, NKikimr::NPQ::TMultiCounter&& counter); void Inc(ui64 value);