Skip to content

Commit cff4055

Browse files
committed
Review fixes
1 parent 6d5c9c8 commit cff4055

15 files changed

+82
-72
lines changed

ydb/core/keyvalue/keyvalue_flat_impl.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ class TKeyValueFlat : public TActor<TKeyValueFlat>, public NTabletFlatExecutor::
122122
TKeyValueFlat *Self;
123123
TVector<TLogoBlobID> TrashBeingCommitted;
124124

125-
TTxRequest(THolder<TIntermediate> intermediate, TKeyValueFlat *keyValueFlat)
126-
: Intermediate(std::move(intermediate))
125+
TTxRequest(THolder<TIntermediate> intermediate, TKeyValueFlat *keyValueFlat, NWilson::TTraceId &&traceId)
126+
: NTabletFlatExecutor::ITransaction(std::move(traceId))
127+
, Intermediate(std::move(intermediate))
127128
, Self(keyValueFlat)
128129
{
129130
Intermediate->Response.SetStatus(NMsgBusProxy::MSTATUS_UNKNOWN);
@@ -390,7 +391,7 @@ class TKeyValueFlat : public TActor<TKeyValueFlat>, public NTabletFlatExecutor::
390391

391392
State.OnEvIntermediate(*(ev->Get()->Intermediate), ctx);
392393
auto traceId = ev->Get()->Intermediate->Span.GetTraceId();
393-
Execute(new TTxRequest(std::move(ev->Get()->Intermediate), this), ctx, std::move(traceId));
394+
Execute(new TTxRequest(std::move(ev->Get()->Intermediate), this, std::move(traceId)), ctx);
394395
}
395396

396397
void Handle(TEvKeyValue::TEvNotify::TPtr &ev, const TActorContext &ctx) {

ydb/core/tablet_flat/flat_exec_seat.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace NTabletFlatExecutor {
99
}
1010
Self->Complete(ctx);
1111

12-
TxSpan.Attribute("rw", isRW);
13-
TxSpan.EndOk();
12+
Self->TxSpan.Attribute("rw", isRW);
13+
Self->TxSpan.EndOk();
1414
}
1515

1616
void TSeat::Terminate(ETerminationReason reason, const TActorContext& ctx) noexcept {
1717
Self->Terminate(reason, ctx);
1818

19-
TxSpan.EndError("Terminated");
19+
Self->TxSpan.EndError("Terminated");
2020
}
2121

2222
} // namespace NTabletFlatExecutor

ydb/core/tablet_flat/flat_exec_seat.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ namespace NTabletFlatExecutor {
1717

1818
TSeat(const TSeat&) = delete;
1919

20-
TSeat(ui32 uniqId, TAutoPtr<ITransaction> self, NWilson::TTraceId txTraceId)
20+
TSeat(ui32 uniqId, TAutoPtr<ITransaction> self)
2121
: UniqID(uniqId)
2222
, Self(self)
2323
{
24-
if (txTraceId) {
25-
SetupTxSpan(std::move(txTraceId));
26-
}
2724
}
2825

2926
void Describe(IOutputStream &out) const noexcept
@@ -37,38 +34,32 @@ namespace NTabletFlatExecutor {
3734

3835
void Terminate(ETerminationReason reason, const TActorContext& ctx) noexcept;
3936

40-
void SetupTxSpan(NWilson::TTraceId txTraceId) noexcept {
41-
TxSpan = NWilson::TSpan(TWilsonTablet::Tablet, std::move(txTraceId), "Tablet.Transaction");
42-
TxSpan.Attribute("Type", TypeName(*Self));
43-
}
44-
4537
NWilson::TSpan CreateExecutionSpan() noexcept {
46-
return NWilson::TSpan(TWilsonTablet::Tablet, TxSpan.GetTraceId(), "Tablet.Transaction.Execute");
38+
return NWilson::TSpan(TWilsonTablet::Tablet, Self->TxSpan.GetTraceId(), "Tablet.Transaction.Execute");
4739
}
4840

4941
void StartEnqueuedSpan() noexcept {
50-
WaitingSpan = NWilson::TSpan(TWilsonTablet::Tablet, TxSpan.GetTraceId(), "Tablet.Transaction.Enqueued");
42+
WaitingSpan = NWilson::TSpan(TWilsonTablet::Tablet, Self->TxSpan.GetTraceId(), "Tablet.Transaction.Enqueued");
5143
}
5244

5345
void FinishEnqueuedSpan() noexcept {
5446
WaitingSpan.EndOk();
5547
}
5648

5749
void CreatePendingSpan() noexcept {
58-
WaitingSpan = NWilson::TSpan(TWilsonTablet::Tablet, TxSpan.GetTraceId(), "Tablet.Transaction.Pending");
50+
WaitingSpan = NWilson::TSpan(TWilsonTablet::Tablet, Self->TxSpan.GetTraceId(), "Tablet.Transaction.Pending");
5951
}
6052

6153
void FinishPendingSpan() noexcept {
6254
WaitingSpan.EndOk();
6355
}
6456

6557
NWilson::TTraceId GetTxTraceId() const noexcept {
66-
return TxSpan.GetTraceId();
58+
return Self->TxSpan.GetTraceId();
6759
}
6860

6961
const ui64 UniqID = Max<ui64>();
7062
const TAutoPtr<ITransaction> Self;
71-
NWilson::TSpan TxSpan;
7263
NWilson::TSpan WaitingSpan;
7364
ui64 Retries = 0;
7465
TPinned Pinned;

ydb/core/tablet_flat/flat_executor.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,10 +1576,10 @@ bool TExecutor::CanExecuteTransaction() const {
15761576
return Stats->IsActive && (Stats->IsFollower || PendingPartSwitches.empty()) && !BrokenTransaction;
15771577
}
15781578

1579-
void TExecutor::DoExecute(TAutoPtr<ITransaction> self, bool allowImmediate, const TActorContext &ctx, NWilson::TTraceId traceId) {
1579+
void TExecutor::DoExecute(TAutoPtr<ITransaction> self, bool allowImmediate, const TActorContext &ctx) {
15801580
Y_ABORT_UNLESS(ActivationQueue, "attempt to execute transaction before activation");
15811581

1582-
TAutoPtr<TSeat> seat = new TSeat(++TransactionUniqCounter, self, std::move(traceId));
1582+
TAutoPtr<TSeat> seat = new TSeat(++TransactionUniqCounter, self);
15831583

15841584
LWTRACK(TransactionBegin, seat->Self->Orbit, seat->UniqID, Owner->TabletID(), TypeName(*seat->Self));
15851585

@@ -1634,12 +1634,12 @@ void TExecutor::DoExecute(TAutoPtr<ITransaction> self, bool allowImmediate, cons
16341634
ExecuteTransaction(seat, ctx);
16351635
}
16361636

1637-
void TExecutor::Execute(TAutoPtr<ITransaction> self, const TActorContext &ctx, NWilson::TTraceId traceId) {
1638-
DoExecute(self, true, ctx, std::move(traceId));
1637+
void TExecutor::Execute(TAutoPtr<ITransaction> self, const TActorContext &ctx) {
1638+
DoExecute(self, true, ctx);
16391639
}
16401640

1641-
void TExecutor::Enqueue(TAutoPtr<ITransaction> self, const TActorContext &ctx, NWilson::TTraceId traceId) {
1642-
DoExecute(self, false, ctx, std::move(traceId));
1641+
void TExecutor::Enqueue(TAutoPtr<ITransaction> self, const TActorContext &ctx) {
1642+
DoExecute(self, false, ctx);
16431643
}
16441644

16451645
void TExecutor::ExecuteTransaction(TAutoPtr<TSeat> seat, const TActorContext &ctx) {

ydb/core/tablet_flat/flat_executor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,9 @@ class TExecutor
629629
void Boot(TEvTablet::TEvBoot::TPtr &ev, const TActorContext &ctx) override;
630630
void Restored(TEvTablet::TEvRestored::TPtr &ev, const TActorContext &ctx) override;
631631
void DetachTablet(const TActorContext &ctx) override;
632-
void DoExecute(TAutoPtr<ITransaction> transaction, bool allowImmediate, const TActorContext &ctx, NWilson::TTraceId traceId);
633-
void Execute(TAutoPtr<ITransaction> transaction, const TActorContext &ctx, NWilson::TTraceId traceId = {}) override;
634-
void Enqueue(TAutoPtr<ITransaction> transaction, const TActorContext &ctx, NWilson::TTraceId traceId = {}) override;
632+
void DoExecute(TAutoPtr<ITransaction> transaction, bool allowImmediate, const TActorContext &ctx);
633+
void Execute(TAutoPtr<ITransaction> transaction, const TActorContext &ctx) override;
634+
void Enqueue(TAutoPtr<ITransaction> transaction, const TActorContext &ctx) override;
635635

636636
TLeaseCommit* AttachLeaseCommit(TLogCommit* commit, bool force = false);
637637
TLeaseCommit* EnsureReadOnlyLease(TMonotonic at);

ydb/core/tablet_flat/flat_executor_txloglogic.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,26 +184,29 @@ TLogicRedo::TCommitRWTransactionResult TLogicRedo::CommitRWTransaction(
184184
if (!Batch->Commit) {
185185
Batch->Commit = CommitManager->Begin(false, ECommit::Redo, seat->GetTxTraceId());
186186
} else {
187+
const TAutoPtr<ITransaction> &tx = seat->Self;
187188
// Batch commit's TraceId will be used for all blobstorage requests of the batch.
188-
if (!Batch->Commit->TraceId && seat->TxSpan) {
189+
if (!Batch->Commit->TraceId && tx->TxSpan) {
189190
// It is possible that the original or consequent transactions didn't have a TraceId,
190191
// but if a new transaction of a batch has TraceId, use it for the whole batch
191192
// (and consequent traced transactions).
192193
Batch->Commit->TraceId = seat->GetTxTraceId();
193194
} else {
194-
seat->TxSpan.Link(Batch->Commit->TraceId, {});
195+
tx->TxSpan.Link(Batch->Commit->TraceId, {});
195196
}
196197

197-
for (TSeat* tx = Batch->Commit->FirstTx; tx != nullptr; tx = tx->NextCommitTx) {
198+
i64 batchSize = Batch->Bodies.size() + 1;
199+
200+
for (TSeat* curSeat = Batch->Commit->FirstTx; curSeat != nullptr; curSeat = curSeat->NextCommitTx) {
198201
// Update batch size of the transaction, whose TraceId the commit uses (first transaction in batch, that has TraceId).
199-
if (tx->TxSpan) {
200-
i64 batchSize = Batch->Bodies.size() + 1;
201-
tx->TxSpan.Attribute("BatchSize", batchSize);
202+
if (curSeat->Self->TxSpan) {
203+
curSeat->Self->TxSpan.Attribute("BatchSize", batchSize);
202204
break;
203205
}
204206
}
205207

206-
seat->TxSpan.Attribute("Batched", true);
208+
tx->TxSpan.Attribute("Batched", true);
209+
tx->TxSpan.Attribute("BatchSize", batchSize);
207210
}
208211

209212
Batch->Commit->PushTx(seat.Get());

ydb/core/tablet_flat/tablet_flat_executed.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ IExecutor* TTabletExecutedFlat::CreateExecutor(const TActorContext &ctx) {
2929
return Executor();
3030
}
3131

32-
void TTabletExecutedFlat::Execute(TAutoPtr<ITransaction> transaction, const TActorContext &ctx, NWilson::TTraceId traceId) {
32+
void TTabletExecutedFlat::Execute(TAutoPtr<ITransaction> transaction, const TActorContext &ctx) {
3333
Y_UNUSED(ctx);
34-
Execute(transaction, std::move(traceId));
34+
Execute(transaction);
3535
}
3636

37-
void TTabletExecutedFlat::Execute(TAutoPtr<ITransaction> transaction, NWilson::TTraceId traceId) {
37+
void TTabletExecutedFlat::Execute(TAutoPtr<ITransaction> transaction) {
3838
if (transaction)
39-
static_cast<TExecutor*>(Executor())->Execute(transaction, ExecutorCtx(*TlsActivationContext), std::move(traceId));
39+
static_cast<TExecutor*>(Executor())->Execute(transaction, ExecutorCtx(*TlsActivationContext));
4040
}
4141

42-
void TTabletExecutedFlat::EnqueueExecute(TAutoPtr<ITransaction> transaction, NWilson::TTraceId traceId) {
42+
void TTabletExecutedFlat::EnqueueExecute(TAutoPtr<ITransaction> transaction) {
4343
if (transaction)
44-
static_cast<TExecutor*>(Executor())->Enqueue(transaction, ExecutorCtx(*TlsActivationContext), std::move(traceId));
44+
static_cast<TExecutor*>(Executor())->Enqueue(transaction, ExecutorCtx(*TlsActivationContext));
4545
}
4646

4747
const NTable::TScheme& TTabletExecutedFlat::Scheme() const noexcept {

ydb/core/tablet_flat/tablet_flat_executed.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class TTabletExecutedFlat : public NFlatExecutorSetup::ITablet {
2323
IExecutor* Executor() const { return Executor0; }
2424
const TInstant StartTime() const { return StartTime0; }
2525

26-
void Execute(TAutoPtr<ITransaction> transaction, const TActorContext &ctx, NWilson::TTraceId traceId = {});
27-
void Execute(TAutoPtr<ITransaction> transaction, NWilson::TTraceId traceId = {});
28-
void EnqueueExecute(TAutoPtr<ITransaction> transaction, NWilson::TTraceId traceId = {});
26+
void Execute(TAutoPtr<ITransaction> transaction, const TActorContext &ctx);
27+
void Execute(TAutoPtr<ITransaction> transaction);
28+
void EnqueueExecute(TAutoPtr<ITransaction> transaction);
2929

3030
const NTable::TScheme& Scheme() const noexcept;
3131

ydb/core/tablet_flat/tablet_flat_executor.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <ydb/core/base/tablet.h>
77
#include <ydb/core/base/blobstorage.h>
88
#include <ydb/library/actors/wilson/wilson_span.h>
9+
#include <ydb/library/wilson_ids/wilson.h>
910
#include <library/cpp/lwtrace/shuttle.h>
1011
#include <util/generic/maybe.h>
1112
#include <util/system/type_name.h>
@@ -278,6 +279,12 @@ class ITransaction : TNonCopyable {
278279
: Orbit(std::move(orbit))
279280
{ }
280281

282+
ITransaction(NWilson::TTraceId &&traceId)
283+
: TxSpan(NWilson::TSpan(TWilsonTablet::Tablet, std::move(traceId), "Tablet.Transaction"))
284+
{
285+
TxSpan.Attribute("Type", TypeName(*this));
286+
}
287+
281288
virtual ~ITransaction() = default;
282289
/// @return true if execution complete and transaction is ready for commit
283290
virtual bool Execute(TTransactionContext &txc, const TActorContext &ctx) = 0;
@@ -293,8 +300,15 @@ class ITransaction : TNonCopyable {
293300
out << TypeName(*this);
294301
}
295302

303+
void SetupTxSpan(NWilson::TTraceId traceId) noexcept {
304+
TxSpan = NWilson::TSpan(TWilsonTablet::Tablet, std::move(traceId), "Tablet.Transaction");
305+
TxSpan.Attribute("Type", TypeName(*this));
306+
}
307+
296308
public:
297309
NLWTrace::TOrbit Orbit;
310+
311+
NWilson::TSpan TxSpan;
298312
};
299313

300314
template<typename T>
@@ -313,6 +327,11 @@ class TTransactionBase : public ITransaction {
313327
: ITransaction(std::move(orbit))
314328
, Self(self)
315329
{ }
330+
331+
TTransactionBase(T *self, NWilson::TTraceId &&traceId)
332+
: ITransaction(std::move(traceId))
333+
, Self(self)
334+
{ }
316335
};
317336

318337
struct TExecutorStats {
@@ -518,8 +537,8 @@ namespace NFlatExecutorSetup {
518537
// all followers had completed log with requested gc-barrier
519538
virtual void FollowerGcApplied(ui32 step, TDuration followerSyncDelay) = 0;
520539

521-
virtual void Execute(TAutoPtr<ITransaction> transaction, const TActorContext &ctx, NWilson::TTraceId traceId = {}) = 0;
522-
virtual void Enqueue(TAutoPtr<ITransaction> transaction, const TActorContext &ctx, NWilson::TTraceId traceId = {}) = 0;
540+
virtual void Execute(TAutoPtr<ITransaction> transaction, const TActorContext &ctx) = 0;
541+
virtual void Enqueue(TAutoPtr<ITransaction> transaction, const TActorContext &ctx) = 0;
523542

524543
virtual void ConfirmReadOnlyLease(TMonotonic at) = 0;
525544
virtual void ConfirmReadOnlyLease(TMonotonic at, std::function<void()> callback) = 0;

ydb/core/tx/datashard/datashard.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,8 +2818,7 @@ void TDataShard::ProposeTransaction(TEvDataShard::TEvProposeTransaction::TPtr &&
28182818
UpdateProposeQueueSize();
28192819
} else {
28202820
// Prepare planned transactions as soon as possible
2821-
TTxProposeTransactionBase *tx = new TTxProposeTransactionBase(this, std::move(ev), TAppData::TimeProvider->Now(), NextTieBreakerIndex++, /* delayed */ false);
2822-
Execute(tx, ctx, tx->GetTraceId());
2821+
Execute(new TTxProposeTransactionBase(this, std::move(ev), TAppData::TimeProvider->Now(), NextTieBreakerIndex++, /* delayed */ false), ctx);
28232822
}
28242823
}
28252824

@@ -2837,8 +2836,7 @@ void TDataShard::ProposeTransaction(NEvents::TDataEvents::TEvWrite::TPtr&& ev, c
28372836
UpdateProposeQueueSize();
28382837
} else {
28392838
// Prepare planned transactions as soon as possible
2840-
TTxWrite *tx = new TTxWrite(this, std::move(ev), TAppData::TimeProvider->Now(), NextTieBreakerIndex++, /* delayed */ false);
2841-
Execute(tx, ctx, tx->GetTraceId());
2839+
Execute(new TTxWrite(this, std::move(ev), TAppData::TimeProvider->Now(), NextTieBreakerIndex++, /* delayed */ false), ctx);
28422840
}
28432841
}
28442842

@@ -2903,14 +2901,12 @@ void TDataShard::Handle(TEvPrivate::TEvDelayedProposeTransaction::TPtr &ev, cons
29032901
switch (item.Event->GetTypeRewrite()) {
29042902
case TEvDataShard::TEvProposeTransaction::EventType: {
29052903
auto event = IEventHandle::Downcast<TEvDataShard::TEvProposeTransaction>(std::move(item.Event));
2906-
TTxProposeTransactionBase *tx = new TTxProposeTransactionBase(this, std::move(event), item.ReceivedAt, item.TieBreakerIndex, /* delayed */ true);
2907-
Execute(tx, ctx, tx->GetTraceId());
2904+
Execute(new TTxProposeTransactionBase(this, std::move(event), item.ReceivedAt, item.TieBreakerIndex, /* delayed */ true), ctx);
29082905
return;
29092906
}
29102907
case NEvents::TDataEvents::TEvWrite::EventType: {
29112908
auto event = IEventHandle::Downcast<NEvents::TDataEvents::TEvWrite>(std::move(item.Event));
2912-
TTxWrite *tx = new TTxWrite(this, std::move(event), item.ReceivedAt, item.TieBreakerIndex, /* delayed */ true);
2913-
Execute(tx, ctx, tx->GetTraceId());
2909+
Execute(new TTxWrite(this, std::move(event), item.ReceivedAt, item.TieBreakerIndex, /* delayed */ true), ctx);
29142910
return;
29152911
}
29162912
default:
@@ -4121,13 +4117,13 @@ bool TDataShard::ReassignChannelsEnabled() const {
41214117
}
41224118

41234119
void TDataShard::ExecuteProgressTx(const TActorContext& ctx) {
4124-
Execute(new TTxProgressTransaction(this, {}), ctx);
4120+
Execute(new TTxProgressTransaction(this, {}, {}), ctx);
41254121
}
41264122

41274123
void TDataShard::ExecuteProgressTx(TOperation::TPtr op, const TActorContext& ctx) {
41284124
Y_ABORT_UNLESS(op->IsInProgress());
41294125
NWilson::TTraceId traceId = op->GetTraceId();
4130-
Execute(new TTxProgressTransaction(this, std::move(op)), ctx, std::move(traceId));
4126+
Execute(new TTxProgressTransaction(this, std::move(op), std::move(traceId)), ctx);
41314127
}
41324128

41334129
TDuration TDataShard::CleanupTimeout() const {

0 commit comments

Comments
 (0)