Skip to content

Bugfix Remove TActiveTransaction from TExecutionUnit.OpsInFly on cancel #935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ydb/core/tx/datashard/datashard_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,10 @@ bool TPipeline::CancelPropose(NIceDb::TNiceDb& db, const TActorContext& ctx, ui6
return false;
}

if (!op->IsExecutionPlanFinished()) {
GetExecutionUnit(op->GetCurrentUnit()).RemoveOperation(op);
}

ForgetTx(txId);
Self->CheckDelayedProposeQueue(ctx);
MaybeActivateWaitingSchemeOps(ctx);
Expand All @@ -1196,6 +1200,11 @@ ECleanupStatus TPipeline::CleanupOutdated(NIceDb::TNiceDb& db, const TActorConte
}

for (ui64 txId : outdatedTxs) {
auto op = Self->TransQueue.FindTxInFly(txId);
if (op && !op->IsExecutionPlanFinished()) {
GetExecutionUnit(op->GetCurrentUnit()).RemoveOperation(op);
}

ForgetTx(txId);
LOG_INFO(ctx, NKikimrServices::TX_DATASHARD,
"Outdated Tx %" PRIu64 " is cleaned at tablet %" PRIu64 " and outdatedStep# %" PRIu64,
Expand All @@ -1211,6 +1220,11 @@ bool TPipeline::CleanupVolatile(ui64 txId, const TActorContext& ctx,
std::vector<std::unique_ptr<IEventHandle>>& replies)
{
if (Self->TransQueue.CleanupVolatile(txId, replies)) {
auto op = Self->TransQueue.FindTxInFly(txId);
if (op && !op->IsExecutionPlanFinished()) {
GetExecutionUnit(op->GetCurrentUnit()).RemoveOperation(op);
}

ForgetTx(txId);

Self->CheckDelayedProposeQueue(ctx);
Expand Down
20 changes: 20 additions & 0 deletions ydb/core/tx/datashard/datashard_ut_order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <ydb/core/tx/tx_processing.h>
#include <ydb/public/lib/deprecated/kicli/kicli.h>
#include <ydb/core/testlib/tenant_runtime.h>
#include <ydb/library/actors/util/memory_tracker.h>
#include <util/system/valgrind.h>

#include <ydb/library/yql/minikql/invoke_builtins/mkql_builtins.h>
Expand Down Expand Up @@ -2477,6 +2478,23 @@ Y_UNIT_TEST(TestCopyTableNoDeadlock) {
}
}

void VerifyNoActiveTransactions() {
using namespace NActors::NMemory::NPrivate;
const auto& instance = TMemoryTracker::Instance();
instance->Initialize();
std::vector<TMetric> metrics;
TMemoryTracker::Instance()->GatherMetrics(metrics);

for (size_t i : xrange(metrics.size())) {
if (instance->GetName(i) == TString(MemoryLabelActiveTransactionBody)) {
UNIT_ASSERT_VALUES_EQUAL(metrics[i].GetCount(), 0);
return;
}
}

UNIT_ASSERT_C(false, "Datashard/TActiveTransaction/TxBody metric not found");
}

Y_UNIT_TEST(TestPlannedCancelSplit) {
TPortManager pm;
NKikimrConfig::TAppConfig app;
Expand Down Expand Up @@ -2665,6 +2683,8 @@ Y_UNIT_TEST(TestPlannedCancelSplit) {
TDuration elapsed = TInstant::Now() - splitStart;
UNIT_ASSERT_C(elapsed < TDuration::Seconds(NValgrind::PlainOrUnderValgrind(2, 10)),
"Split needed " << elapsed.ToString() << " to complete, which is too long");

VerifyNoActiveTransactions();
}

Y_UNIT_TEST(TestPlannedTimeoutSplit) {
Expand Down