Skip to content

Commit 119d2fe

Browse files
committed
refactor: localize stats storage
1 parent 34c0cf8 commit 119d2fe

36 files changed

+671
-428
lines changed

ydb/core/tx/columnshard/background_controller.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ void TBackgroundController::CheckDeadlinesIndexation() {
2626
}
2727
}
2828

29-
TInstant TBackgroundController::GetLastCompactionFinishInstant(ui64 pathId) const {
30-
auto findInstant = LastCompactionFinishByPathId.find(pathId);
31-
if (findInstant.IsEnd()) {
32-
return TInstant::Zero();
33-
}
34-
return findInstant->second;
35-
}
36-
3729
void TBackgroundController::StartIndexing(const NOlap::TColumnEngineChanges& changes) {
3830
LastIndexationInstant = TMonotonic::Now();
3931
Y_ABORT_UNLESS(ActiveIndexationTasks.emplace(changes.GetTaskIdentifier(), TMonotonic::Now()).second);

ydb/core/tx/columnshard/background_controller.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22
#include "engines/changes/abstract/compaction_info.h"
33
#include "engines/portions/meta.h"
4+
#include <ydb/core/tx/columnshard/counters/statistics_store.h>
45
#include <ydb/core/base/appdata.h>
56

67
namespace NKikimr::NOlap {
@@ -15,13 +16,16 @@ class TBackgroundController {
1516

1617
using TCurrentCompaction = THashMap<ui64, NOlap::TPlanCompactionInfo>;
1718
TCurrentCompaction ActiveCompactionInfo;
18-
THashMap<ui64, TInstant> LastCompactionFinishByPathId;
1919

20+
TBackgroundControllerCounters& Stats;
2021
bool ActiveCleanupPortions = false;
2122
bool ActiveCleanupTables = false;
2223
bool ActiveCleanupInsertTable = false;
2324
YDB_READONLY(TMonotonic, LastIndexationInstant, TMonotonic::Zero());
2425
public:
26+
TBackgroundController(TBackgroundControllerCounters& stats) : Stats(stats) {
27+
}
28+
2529
THashSet<NOlap::TPortionAddress> GetConflictTTLPortions() const;
2630
THashSet<NOlap::TPortionAddress> GetConflictCompactionPortions() const;
2731

@@ -31,8 +35,7 @@ class TBackgroundController {
3135
bool StartCompaction(const NOlap::TPlanCompactionInfo& info);
3236
void FinishCompaction(const NOlap::TPlanCompactionInfo& info) {
3337
Y_ABORT_UNLESS(ActiveCompactionInfo.erase(info.GetPathId()));
34-
TInstant& lastFinishInstant = LastCompactionFinishByPathId[info.GetPathId()];
35-
lastFinishInstant = std::max(lastFinishInstant, TAppData::TimeProvider->Now());
38+
Stats.OnCompactionFinish(info.GetPathId());
3639
}
3740
const TCurrentCompaction& GetActiveCompaction() const {
3841
return ActiveCompactionInfo;

ydb/core/tx/columnshard/blobs_action/bs/write.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ void TWriteAction::DoOnCompleteTxAfterWrite(NColumnShard::TColumnShard& self, co
1515
ui64 blobsWritten = BlobBatch.GetBlobCount();
1616
ui64 bytesWritten = BlobBatch.GetTotalSize();
1717
if (blobsWroteSuccessfully) {
18-
self.IncCounter(NColumnShard::COUNTER_UPSERT_BLOBS_WRITTEN, blobsWritten);
19-
self.IncCounter(NColumnShard::COUNTER_UPSERT_BYTES_WRITTEN, bytesWritten);
20-
// self.IncCounter(NColumnShard::COUNTER_RAW_BYTES_UPSERTED, insertedBytes);
21-
self.IncCounter(NColumnShard::COUNTER_WRITE_SUCCESS);
18+
self.Stats.GetTabletCounters().IncCounter(NColumnShard::COUNTER_UPSERT_BLOBS_WRITTEN, blobsWritten);
19+
self.Stats.GetTabletCounters().IncCounter(NColumnShard::COUNTER_UPSERT_BYTES_WRITTEN, bytesWritten);
20+
// self.Stats.GetTabletCounters().IncCounter(NColumnShard::COUNTER_RAW_BYTES_UPSERTED, insertedBytes);
21+
self.Stats.GetTabletCounters().IncCounter(NColumnShard::COUNTER_WRITE_SUCCESS);
2222
Manager->SaveBlobBatchOnComplete(std::move(BlobBatch));
2323
} else {
24-
self.IncCounter(NColumnShard::COUNTER_WRITE_FAIL);
24+
self.Stats.GetTabletCounters().IncCounter(NColumnShard::COUNTER_WRITE_FAIL);
2525
}
2626
}
2727

ydb/core/tx/columnshard/blobs_action/transaction/tx_write.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ bool TTxWrite::Execute(TTransactionContext& txc, const TActorContext&) {
7070

7171
if (!InsertOneBlob(txc, i, writeId)) {
7272
LOG_S_DEBUG(TxPrefix() << "duplicate writeId " << (ui64)writeId << TxSuffix());
73-
Self->IncCounter(COUNTER_WRITE_DUPLICATE);
73+
Self->Stats.GetTabletCounters().IncCounter(COUNTER_WRITE_DUPLICATE);
7474
}
7575
}
7676
}
@@ -140,10 +140,10 @@ void TTxWrite::Complete(const TActorContext& ctx) {
140140
}
141141
for (ui32 i = 0; i < buffer.GetAggregations().size(); ++i) {
142142
const auto& writeMeta = buffer.GetAggregations()[i]->GetWriteMeta();
143-
Self->CSCounters.OnWriteTxComplete(now - writeMeta.GetWriteStartInstant());
144-
Self->CSCounters.OnSuccessWriteResponse();
143+
Self->Stats.GetCSCounters().OnWriteTxComplete(now - writeMeta.GetWriteStartInstant());
144+
Self->Stats.GetCSCounters().OnSuccessWriteResponse();
145145
}
146-
Self->IncCounter(COUNTER_IMMEDIATE_TX_COMPLETED);
146+
Self->Stats.GetTabletCounters().IncCounter(COUNTER_IMMEDIATE_TX_COMPLETED);
147147
}
148148

149149
}

ydb/core/tx/columnshard/columnshard.cpp

Lines changed: 76 additions & 158 deletions
Large diffs are not rendered by default.

ydb/core/tx/columnshard/columnshard__init.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ bool TTxInit::ReadEverything(TTransactionContext& txc, const TActorContext& ctx)
165165
}
166166
Self->TablesManager = std::move(tManagerLocal);
167167

168-
Self->SetCounter(COUNTER_TABLES, Self->TablesManager.GetTables().size());
169-
Self->SetCounter(COUNTER_TABLE_PRESETS, Self->TablesManager.GetSchemaPresets().size());
170-
Self->SetCounter(COUNTER_TABLE_TTLS, Self->TablesManager.GetTtl().PathsCount());
168+
Self->Stats.GetTabletCounters().SetCounter(COUNTER_TABLES, Self->TablesManager.GetTables().size());
169+
Self->Stats.GetTabletCounters().SetCounter(COUNTER_TABLE_PRESETS, Self->TablesManager.GetSchemaPresets().size());
170+
Self->Stats.GetTabletCounters().SetCounter(COUNTER_TABLE_TTLS, Self->TablesManager.GetTtl().PathsCount());
171171
ACFL_DEBUG("step", "TTablesManager::Load_Finish");
172172
}
173173

ydb/core/tx/columnshard/columnshard__plan_step.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ bool TTxPlanStep::Execute(TTransactionContext& txc, const TActorContext& ctx) {
102102

103103
Result = std::make_unique<TEvTxProcessing::TEvPlanStepAccepted>(Self->TabletID(), step);
104104

105-
Self->IncCounter(COUNTER_PLAN_STEP_ACCEPTED);
105+
Self->Stats.GetTabletCounters().IncCounter(COUNTER_PLAN_STEP_ACCEPTED);
106106

107107
if (plannedCount > 0 || Self->ProgressTxController->HaveOutdatedTxs()) {
108108
Self->EnqueueProgressTx(ctx);

ydb/core/tx/columnshard/columnshard__progress_tx.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TColumnShard::TTxProgressTx : public TTransactionBase<TColumnShard> {
1818
bool Execute(TTransactionContext& txc, const TActorContext& ctx) override {
1919
NActors::TLogContextGuard logGuard = NActors::TLogContextBuilder::Build(NKikimrServices::TX_COLUMNSHARD)("tablet_id", Self->TabletID())("tx_state", "execute");
2020
Y_ABORT_UNLESS(Self->ProgressTxInFlight);
21-
Self->TabletCounters->Simple()[COUNTER_TX_COMPLETE_LAG].Set(Self->GetTxCompleteLag().MilliSeconds());
21+
Self->Stats.GetTabletCounters().SetCounter(COUNTER_TX_COMPLETE_LAG, Self->GetTxCompleteLag().MilliSeconds());
2222

2323
const size_t removedCount = Self->ProgressTxController->CleanExpiredTxs(txc);
2424
if (removedCount > 0) {
@@ -43,7 +43,7 @@ class TColumnShard::TTxProgressTx : public TTransactionBase<TColumnShard> {
4343
TxOperator = Self->ProgressTxController->GetVerifiedTxOperator(txId);
4444
AFL_VERIFY(TxOperator->ProgressOnExecute(*Self, NOlap::TSnapshot(step, txId), txc));
4545
Self->ProgressTxController->FinishPlannedTx(txId, txc);
46-
Self->IncCounter(COUNTER_PLANNED_TX_COMPLETED);
46+
Self->Stats.GetTabletCounters().IncCounter(COUNTER_PLANNED_TX_COMPLETED);
4747
}
4848
return true;
4949
}

ydb/core/tx/columnshard/columnshard__propose_transaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class TTxProposeTransaction: public NTabletFlatExecutor::TTransactionBase<TColum
2525
txc.DB.NoMoreReadsForTx();
2626
NIceDb::TNiceDb db(txc.DB);
2727

28-
Self->IncCounter(COUNTER_PREPARE_REQUEST);
28+
Self->Stats.GetTabletCounters().IncCounter(COUNTER_PREPARE_REQUEST);
2929

3030
auto& record = Proto(Ev->Get());
3131
const auto txKind = record.GetTxKind();

ydb/core/tx/columnshard/columnshard__scan.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "engines/reader/transaction/tx_internal_scan.h"
66

77
#include <ydb/core/protos/kqp.pb.h>
8+
#include <ydb/core/base/appdata_fwd.h>
89

910
namespace NKikimr::NColumnShard {
1011

@@ -29,9 +30,9 @@ void TColumnShard::Handle(TEvColumnShard::TEvScan::TPtr& ev, const TActorContext
2930
return;
3031
}
3132

32-
TablesManager.RegisterAccess(record.GetLocalPathId());
33-
ScanTxInFlight.insert({txId, LastAccessTime});
34-
SetCounter(COUNTER_SCAN_IN_FLY, ScanTxInFlight.size());
33+
Stats.GetColumnTableCounters().GetPathIdCounter(record.GetLocalPathId()).OnAccess();
34+
ScanTxInFlight.insert({txId, TAppData::TimeProvider->Now()});
35+
Stats.GetTabletCounters().SetCounter(COUNTER_SCAN_IN_FLY, ScanTxInFlight.size());
3536
Execute(new NOlap::NReader::TTxScan(this, ev), ctx);
3637
}
3738

0 commit comments

Comments
 (0)