Skip to content

Commit d54d788

Browse files
authored
24-3: Add counters for volatile transactions (#10747)
1 parent 42494f2 commit d54d788

File tree

3 files changed

+116
-4
lines changed

3 files changed

+116
-4
lines changed

ydb/core/protos/counters_datashard.proto

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ enum ESimpleCounters {
3232
COUNTER_DELAYED_PROPOSE_QUEUE_SIZE = 22 [(CounterOpts) = {Name: "DelayedProposeQueueSize"}];
3333
COUNTER_WAITING_TX_QUEUE_SIZE = 23 [(CounterOpts) = {Name: "WaitingTxQueueSize"}];
3434
COUNTER_CHANGE_QUEUE_RESERVED_CAPACITY = 24 [(CounterOpts) = {Name: "ChangeQueueReservedCapacity"}];
35+
COUNTER_VOLATILE_TX_INFLIGHT = 25 [(CounterOpts) = {Name: "VolatileTxInFlight"}];
36+
COUNTER_VOLATILE_TX_WAITING_COUNT = 26 [(CounterOpts) = {Name: "VolatileTxWaitingCount"}];
37+
COUNTER_VOLATILE_TX_COMMITTED_COUNT = 27 [(CounterOpts) = {Name: "VolatileTxCommittedCount"}];
38+
COUNTER_VOLATILE_TX_ABORTING_COUNT = 28 [(CounterOpts) = {Name: "VolatileTxAbortingCount"}];
3539
}
3640

3741
enum ECumulativeCounters {
@@ -403,7 +407,37 @@ enum EPercentileCounters {
403407

404408
COUNTER_WRITE_EXEC_LATENCY = 21 [(CounterOpts) = {
405409
Name: "WriteExecLatency"
406-
}];
410+
}];
411+
412+
COUNTER_VOLATILE_TX_WAIT_LATENCY_MS = 22 [(CounterOpts) = {
413+
Name: "VolatileTxWaitLatencyMs"
414+
Ranges: { Value: 0 Name: "0"},
415+
Ranges: { Value: 1 Name: "1"},
416+
Ranges: { Value: 2 Name: "2"},
417+
Ranges: { Value: 5 Name: "5"},
418+
Ranges: { Value: 10 Name: "10"},
419+
Ranges: { Value: 25 Name: "25"},
420+
Ranges: { Value: 50 Name: "50"},
421+
Ranges: { Value: 125 Name: "125"},
422+
Ranges: { Value: 250 Name: "250"},
423+
Ranges: { Value: 500 Name: "500"},
424+
Ranges: { Value: 1000 Name: "1000"},
425+
}];
426+
427+
COUNTER_VOLATILE_TX_TOTAL_LATENCY_MS = 23 [(CounterOpts) = {
428+
Name: "VolatileTxTotalLatencyMs"
429+
Ranges: { Value: 0 Name: "0"},
430+
Ranges: { Value: 1 Name: "1"},
431+
Ranges: { Value: 2 Name: "2"},
432+
Ranges: { Value: 5 Name: "5"},
433+
Ranges: { Value: 10 Name: "10"},
434+
Ranges: { Value: 25 Name: "25"},
435+
Ranges: { Value: 50 Name: "50"},
436+
Ranges: { Value: 125 Name: "125"},
437+
Ranges: { Value: 250 Name: "250"},
438+
Ranges: { Value: 500 Name: "500"},
439+
Ranges: { Value: 1000 Name: "1000"},
440+
}];
407441
}
408442

409443
enum ETxTypes {

ydb/core/tx/datashard/volatile_tx.cpp

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ namespace NKikimr::NDataShard {
344344
std::vector<TVolatileTxInfo*> byCommitOrder;
345345
byCommitOrder.reserve(VolatileTxs.size());
346346

347-
auto postProcessTxInfo = [this, &byCommitOrder](TVolatileTxInfo* info) {
347+
auto postProcessTxInfo = [&](TVolatileTxInfo* info) {
348348
switch (info->State) {
349349
case EVolatileTxState::Waiting:
350350
case EVolatileTxState::Committed: {
@@ -399,6 +399,28 @@ namespace NKikimr::NDataShard {
399399
VolatileTxByCommitOrder.PushBack(info);
400400
}
401401

402+
ui64 numWaiting = 0;
403+
ui64 numCommitted = 0;
404+
ui64 numAborting = 0;
405+
for (auto& pr : VolatileTxs) {
406+
switch (pr.second->State) {
407+
case EVolatileTxState::Waiting:
408+
++numWaiting;
409+
break;
410+
case EVolatileTxState::Committed:
411+
++numCommitted;
412+
break;
413+
case EVolatileTxState::Aborting:
414+
++numAborting;
415+
break;
416+
}
417+
}
418+
419+
Self->SetCounter(COUNTER_VOLATILE_TX_INFLIGHT, VolatileTxs.size());
420+
Self->SetCounter(COUNTER_VOLATILE_TX_WAITING_COUNT, numWaiting);
421+
Self->SetCounter(COUNTER_VOLATILE_TX_COMMITTED_COUNT, numCommitted);
422+
Self->SetCounter(COUNTER_VOLATILE_TX_ABORTING_COUNT, numAborting);
423+
402424
return true;
403425
}
404426

@@ -554,6 +576,8 @@ namespace NKikimr::NDataShard {
554576
db.Table<Schema::TxVolatileParticipants>().Key(info->TxId, shardId).Update();
555577
}
556578

579+
UpdateCountersAdd(info);
580+
557581
txc.DB.OnRollback([this, txId]() {
558582
RollbackAddVolatileTx(txId);
559583
});
@@ -593,7 +617,10 @@ namespace NKikimr::NDataShard {
593617

594618
// FIXME: do we need to handle WaitingSnapshotEvents somehow?
595619

620+
// Note: not counting latency (this is a rollback)
621+
596622
// This will also unlink from linked lists
623+
UpdateCountersRemove(info);
597624
VolatileTxs.erase(txId);
598625
}
599626

@@ -632,6 +659,10 @@ namespace NKikimr::NDataShard {
632659
VolatileTxByCommitTxId.erase(commitTxId);
633660
}
634661
VolatileTxByVersion.erase(info);
662+
663+
Self->IncCounter(COUNTER_VOLATILE_TX_TOTAL_LATENCY_MS, info->LatencyTimer.Passed() * 1000);
664+
665+
UpdateCountersRemove(info);
635666
VolatileTxs.erase(txId);
636667

637668
if (prevUncertain < GetMinUncertainVersion()) {
@@ -728,7 +759,7 @@ namespace NKikimr::NDataShard {
728759
ui64 txId = info->TxId;
729760

730761
// Move tx to aborting, but don't persist yet, we need a separate transaction for that
731-
info->State = EVolatileTxState::Aborting;
762+
ChangeState(info, EVolatileTxState::Aborting);
732763

733764
// Aborted transactions don't have dependencies
734765
for (ui64 dependencyTxId : info->Dependencies) {
@@ -842,7 +873,7 @@ namespace NKikimr::NDataShard {
842873
// Move tx to committed.
843874
// Note that we don't need to wait until the new state is committed (it's repeatable),
844875
// but we need to wait until the initial effects are committed and persisted.
845-
info->State = EVolatileTxState::Committed;
876+
ChangeState(info, EVolatileTxState::Committed);
846877
db.Table<Schema::TxVolatileDetails>().Key(txId).Update(
847878
NIceDb::TUpdate<Schema::TxVolatileDetails::State>(info->State));
848879

@@ -1030,4 +1061,43 @@ namespace NKikimr::NDataShard {
10301061
return false;
10311062
}
10321063

1064+
void TVolatileTxManager::UpdateCountersAdd(TVolatileTxInfo* info) {
1065+
Self->IncCounter(COUNTER_VOLATILE_TX_INFLIGHT);
1066+
switch (info->State) {
1067+
case EVolatileTxState::Waiting:
1068+
Self->IncCounter(COUNTER_VOLATILE_TX_WAITING_COUNT);
1069+
break;
1070+
case EVolatileTxState::Committed:
1071+
Self->IncCounter(COUNTER_VOLATILE_TX_COMMITTED_COUNT);
1072+
break;
1073+
case EVolatileTxState::Aborting:
1074+
Self->IncCounter(COUNTER_VOLATILE_TX_ABORTING_COUNT);
1075+
break;
1076+
}
1077+
}
1078+
1079+
void TVolatileTxManager::UpdateCountersRemove(TVolatileTxInfo* info) {
1080+
Self->DecCounter(COUNTER_VOLATILE_TX_INFLIGHT);
1081+
switch (info->State) {
1082+
case EVolatileTxState::Waiting:
1083+
Self->DecCounter(COUNTER_VOLATILE_TX_WAITING_COUNT);
1084+
break;
1085+
case EVolatileTxState::Committed:
1086+
Self->DecCounter(COUNTER_VOLATILE_TX_COMMITTED_COUNT);
1087+
break;
1088+
case EVolatileTxState::Aborting:
1089+
Self->DecCounter(COUNTER_VOLATILE_TX_ABORTING_COUNT);
1090+
break;
1091+
}
1092+
}
1093+
1094+
void TVolatileTxManager::ChangeState(TVolatileTxInfo* info, EVolatileTxState state) {
1095+
if (info->State == EVolatileTxState::Waiting) {
1096+
Self->IncCounter(COUNTER_VOLATILE_TX_WAIT_LATENCY_MS, info->LatencyTimer.Passed() * 1000);
1097+
}
1098+
UpdateCountersRemove(info);
1099+
info->State = state;
1100+
UpdateCountersAdd(info);
1101+
}
1102+
10331103
} // namespace NKikimr::NDataShard

ydb/core/tx/datashard/volatile_tx.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <library/cpp/containers/stack_vector/stack_vec.h>
77
#include <util/generic/hash.h>
88
#include <util/generic/intrlist.h>
9+
#include <util/system/hp_timer.h>
910

1011
namespace NKikimr::NTabletFlatExecutor {
1112

@@ -75,6 +76,9 @@ namespace NKikimr::NDataShard {
7576
// DECISION_ABORT on abort.
7677
std::vector<ui64> ArbiterReadSets;
7778

79+
// Calculates Waiting and Total latency
80+
THPTimer LatencyTimer;
81+
7882
template<class TTag>
7983
bool IsInList() const {
8084
using TItem = TIntrusiveListItem<TVolatileTxInfo, TTag>;
@@ -276,6 +280,10 @@ namespace NKikimr::NDataShard {
276280
void RemoveFromCommitOrder(TVolatileTxInfo* info);
277281
bool ReadyToDbCommit(TVolatileTxInfo* info) const;
278282

283+
void UpdateCountersAdd(TVolatileTxInfo* info);
284+
void UpdateCountersRemove(TVolatileTxInfo* info);
285+
void ChangeState(TVolatileTxInfo* info, EVolatileTxState state);
286+
279287
private:
280288
TDataShard* const Self;
281289
absl::flat_hash_map<ui64, std::unique_ptr<TVolatileTxInfo>> VolatileTxs; // TxId -> Info

0 commit comments

Comments
 (0)