Skip to content

Commit ebe396b

Browse files
authored
Add op context to some TSubOperation calls (#10215)
1 parent a92340d commit ebe396b

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

ydb/core/tx/schemeshard/schemeshard__init.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3560,7 +3560,8 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> {
35603560

35613561
TOperation::TPtr operation = Self->Operations.at(operationId.GetTxId());
35623562
Y_ABORT_UNLESS(operationId.GetSubTxId() == operation->Parts.size());
3563-
ISubOperation::TPtr part = operation->RestorePart(txState.TxType, txState.State);
3563+
TOperationContext context{Self, txc, ctx, OnComplete, MemChanges, DbChanges};
3564+
ISubOperation::TPtr part = operation->RestorePart(txState.TxType, txState.State, context);
35643565
operation->AddPart(part);
35653566

35663567
if (!txInFlightRowset.Next())

ydb/core/tx/schemeshard/schemeshard__operation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ TOperation::TSplitTransactionsResult TOperation::SplitIntoTransactions(const TTx
978978
return result;
979979
}
980980

981-
ISubOperation::TPtr TOperation::RestorePart(TTxState::ETxType txType, TTxState::ETxState txState) const {
981+
ISubOperation::TPtr TOperation::RestorePart(TTxState::ETxType txType, TTxState::ETxState txState, TOperationContext& context) const {
982982
switch (txType) {
983983
case TTxState::ETxType::TxMkDir:
984984
return CreateMkDir(NextPartId(), txState);
@@ -1197,6 +1197,8 @@ ISubOperation::TPtr TOperation::RestorePart(TTxState::ETxType txType, TTxState::
11971197
Y_UNREACHABLE();
11981198
}
11991199

1200+
Y_UNUSED(context); // TODO(Enjection): will be used by complex operations later
1201+
12001202
Y_UNREACHABLE();
12011203
}
12021204

ydb/core/tx/schemeshard/schemeshard__operation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct TOperation: TSimpleRefCount<TOperation> {
7979
static TConsumeQuotaResult ConsumeQuota(const TTxTransaction& tx, TOperationContext& context);
8080
static TSplitTransactionsResult SplitIntoTransactions(const TTxTransaction& tx, const TOperationContext& context);
8181

82-
ISubOperation::TPtr RestorePart(TTxState::ETxType opType, TTxState::ETxState opState) const;
82+
ISubOperation::TPtr RestorePart(TTxState::ETxType opType, TTxState::ETxState opState, TOperationContext& context) const;
8383
TVector<ISubOperation::TPtr> ConstructParts(const TTxTransaction& tx, TOperationContext& context) const;
8484
void AddPart(ISubOperation::TPtr part);
8585

ydb/core/tx/schemeshard/schemeshard__operation_part.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ class TSubOperation: public TSubOperationBase {
250250
virtual TTxState::ETxState NextState(TTxState::ETxState state) const = 0;
251251
virtual TSubOperationState::TPtr SelectStateFunc(TTxState::ETxState state) = 0;
252252

253+
virtual TSubOperationState::TPtr SelectStateFunc(TTxState::ETxState state, TOperationContext&) {
254+
return SelectStateFunc(state);
255+
}
256+
253257
virtual void StateDone(TOperationContext& context) {
254258
auto state = NextState(GetState());
255259
SetState(state);
@@ -272,6 +276,11 @@ class TSubOperation: public TSubOperationBase {
272276
return State;
273277
}
274278

279+
void SetState(TTxState::ETxState state, TOperationContext& context) {
280+
State = state;
281+
StateFunc = SelectStateFunc(state, context);
282+
}
283+
275284
void SetState(TTxState::ETxState state) {
276285
State = state;
277286
StateFunc = SelectStateFunc(state);
@@ -313,6 +322,13 @@ ISubOperation::TPtr MakeSubOperation(const TOperationId& id, const TTxTransactio
313322
return new T(id, tx, std::forward<Args>(args)...);
314323
}
315324

325+
template <typename T, typename... Args>
326+
ISubOperation::TPtr MakeSubOperation(const TOperationId& id, TTxState::ETxState state, TOperationContext& context, Args&&... args) {
327+
auto result = MakeHolder<T>(id, state, std::forward<Args>(args)...);
328+
result->SetState(state, context);
329+
return result.Release();
330+
}
331+
316332
template <typename T, typename... Args>
317333
ISubOperation::TPtr MakeSubOperation(const TOperationId& id, TTxState::ETxState state, Args&&... args) {
318334
auto result = MakeHolder<T>(id, state, std::forward<Args>(args)...);

0 commit comments

Comments
 (0)