Skip to content

Commit 9b5b933

Browse files
authored
Bugfix: Remove TActiveTransaction from TExecutionUnit.OpsInFly on cancel (#935)
1 parent 83da989 commit 9b5b933

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

ydb/core/tx/datashard/datashard_pipeline.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,10 @@ bool TPipeline::CancelPropose(NIceDb::TNiceDb& db, const TActorContext& ctx, ui6
11711171
return false;
11721172
}
11731173

1174+
if (!op->IsExecutionPlanFinished()) {
1175+
GetExecutionUnit(op->GetCurrentUnit()).RemoveOperation(op);
1176+
}
1177+
11741178
ForgetTx(txId);
11751179
Self->CheckDelayedProposeQueue(ctx);
11761180
MaybeActivateWaitingSchemeOps(ctx);
@@ -1196,6 +1200,11 @@ ECleanupStatus TPipeline::CleanupOutdated(NIceDb::TNiceDb& db, const TActorConte
11961200
}
11971201

11981202
for (ui64 txId : outdatedTxs) {
1203+
auto op = Self->TransQueue.FindTxInFly(txId);
1204+
if (op && !op->IsExecutionPlanFinished()) {
1205+
GetExecutionUnit(op->GetCurrentUnit()).RemoveOperation(op);
1206+
}
1207+
11991208
ForgetTx(txId);
12001209
LOG_INFO(ctx, NKikimrServices::TX_DATASHARD,
12011210
"Outdated Tx %" PRIu64 " is cleaned at tablet %" PRIu64 " and outdatedStep# %" PRIu64,
@@ -1211,6 +1220,11 @@ bool TPipeline::CleanupVolatile(ui64 txId, const TActorContext& ctx,
12111220
std::vector<std::unique_ptr<IEventHandle>>& replies)
12121221
{
12131222
if (Self->TransQueue.CleanupVolatile(txId, replies)) {
1223+
auto op = Self->TransQueue.FindTxInFly(txId);
1224+
if (op && !op->IsExecutionPlanFinished()) {
1225+
GetExecutionUnit(op->GetCurrentUnit()).RemoveOperation(op);
1226+
}
1227+
12141228
ForgetTx(txId);
12151229

12161230
Self->CheckDelayedProposeQueue(ctx);

ydb/core/tx/datashard/datashard_ut_order.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <ydb/core/tx/tx_processing.h>
1313
#include <ydb/public/lib/deprecated/kicli/kicli.h>
1414
#include <ydb/core/testlib/tenant_runtime.h>
15+
#include <ydb/library/actors/util/memory_tracker.h>
1516
#include <util/system/valgrind.h>
1617

1718
#include <ydb/library/yql/minikql/invoke_builtins/mkql_builtins.h>
@@ -2477,6 +2478,23 @@ Y_UNIT_TEST(TestCopyTableNoDeadlock) {
24772478
}
24782479
}
24792480

2481+
void VerifyNoActiveTransactions() {
2482+
using namespace NActors::NMemory::NPrivate;
2483+
const auto& instance = TMemoryTracker::Instance();
2484+
instance->Initialize();
2485+
std::vector<TMetric> metrics;
2486+
TMemoryTracker::Instance()->GatherMetrics(metrics);
2487+
2488+
for (size_t i : xrange(metrics.size())) {
2489+
if (instance->GetName(i) == TString(MemoryLabelActiveTransactionBody)) {
2490+
UNIT_ASSERT_VALUES_EQUAL(metrics[i].GetCount(), 0);
2491+
return;
2492+
}
2493+
}
2494+
2495+
UNIT_ASSERT_C(false, "Datashard/TActiveTransaction/TxBody metric not found");
2496+
}
2497+
24802498
Y_UNIT_TEST(TestPlannedCancelSplit) {
24812499
TPortManager pm;
24822500
NKikimrConfig::TAppConfig app;
@@ -2665,6 +2683,8 @@ Y_UNIT_TEST(TestPlannedCancelSplit) {
26652683
TDuration elapsed = TInstant::Now() - splitStart;
26662684
UNIT_ASSERT_C(elapsed < TDuration::Seconds(NValgrind::PlainOrUnderValgrind(2, 10)),
26672685
"Split needed " << elapsed.ToString() << " to complete, which is too long");
2686+
2687+
VerifyNoActiveTransactions();
26682688
}
26692689

26702690
Y_UNIT_TEST(TestPlannedTimeoutSplit) {

0 commit comments

Comments
 (0)