Skip to content

Late messages TEvProposeTransaction (#16216) #16270

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
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
27 changes: 26 additions & 1 deletion ydb/core/persqueue/pq_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1685,7 +1685,7 @@ void TPersQueue::Handle(TEvPersQueue::TEvDropTablet::TPtr& ev, const TActorConte
{
PQ_LOG_D("Handle TEvPersQueue::TEvDropTablet");

auto& record = ev->Get()->Record;
const auto& record = ev->Get()->Record;
ui64 txId = record.GetTxId();

TChangeNotification stateRequest(ev->Sender, txId);
Expand Down Expand Up @@ -4560,6 +4560,31 @@ void TPersQueue::InitMediatorTimeCast(const TActorContext& ctx)

bool TPersQueue::AllTransactionsHaveBeenProcessed() const
{
bool existDataTx = false;
bool existPlannedConfigTx = false;
bool existUnplannedConfigTx = false;

for (const auto& [_, tx] : Txs) {
switch (tx.Kind) {
case NKikimrPQ::TTransaction::KIND_CONFIG:
((tx.Step == Max<ui64>()) ? existUnplannedConfigTx : existPlannedConfigTx) = true;
break;
case NKikimrPQ::TTransaction::KIND_DATA:
existDataTx = true;
break;
case NKikimrPQ::TTransaction::KIND_UNKNOWN:
Y_ABORT_UNLESS(false);
}
}

if (existDataTx || existPlannedConfigTx) {
return false;
}

if (existUnplannedConfigTx) {
return true;
}

return EvProposeTransactionQueue.empty() && Txs.empty();
}

Expand Down
62 changes: 62 additions & 0 deletions ydb/core/persqueue/ut/pqtablet_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,68 @@ Y_UNIT_TEST_F(DropTablet_Before_Write, TPQTabletFixture)
.Status=NKikimrPQ::TEvProposeTransactionResult::ABORTED});
}

Y_UNIT_TEST_F(DropTablet_And_UnplannedConfigTransaction, TPQTabletFixture)
{
PQTabletPrepare({.partitions=2}, {}, *Ctx);

const ui64 txId = 67890;

auto tabletConfig =
NHelpers::MakeConfig(2, {
{.Consumer="client-1", .Generation=0},
{.Consumer="client-3", .Generation=7}},
2);

SendProposeTransactionRequest({.TxId=txId,
.Configs=NHelpers::TConfigParams{
.Tablet=tabletConfig,
.Bootstrap=NHelpers::MakeBootstrapConfig(),
}});
WaitProposeTransactionResponse({.TxId=txId,
.Status=NKikimrPQ::TEvProposeTransactionResult::PREPARED});

// The 'TEvDropTablet` message arrives when the transaction has not yet received a PlanStep. We know that SS
// performs no more than one operation at a time. Therefore, we believe that no one is waiting for this
// transaction anymore.
SendDropTablet({.TxId=12345});
WaitDropTabletReply({.Status=NKikimrProto::EReplyStatus::OK, .TxId=12345, .TabletId=Ctx->TabletId, .State=NKikimrPQ::EDropped});
}

Y_UNIT_TEST_F(DropTablet_And_PlannedConfigTransaction, TPQTabletFixture)
{
PQTabletPrepare({.partitions=2}, {}, *Ctx);

const ui64 txId = 67890;

auto tabletConfig =
NHelpers::MakeConfig(2, {
{.Consumer="client-1", .Generation=0},
{.Consumer="client-3", .Generation=7}},
2);

SendProposeTransactionRequest({.TxId=txId,
.Configs=NHelpers::TConfigParams{
.Tablet=tabletConfig,
.Bootstrap=NHelpers::MakeBootstrapConfig(),
}});
WaitProposeTransactionResponse({.TxId=txId,
.Status=NKikimrPQ::TEvProposeTransactionResult::PREPARED});

SendPlanStep({.Step=100, .TxIds={txId}});
WaitPlanStepAck({.Step=100, .TxIds={txId}});

// The 'TEvDropTablet` message arrives when the transaction has already received a PlanStep.
// We will receive the response when the transaction is executed.
SendDropTablet({.TxId=12345});

WaitPlanStepAccepted({.Step=100});

WaitProposeTransactionResponse({.TxId=txId,
.Status=NKikimrPQ::TEvProposeTransactionResult::COMPLETE});

WaitDropTabletReply({.Status=NKikimrProto::EReplyStatus::OK, .TxId=12345, .TabletId=Ctx->TabletId, .State=NKikimrPQ::EDropped});
}

Y_UNIT_TEST_F(UpdateConfig_1, TPQTabletFixture)
{
PQTabletPrepare({.partitions=2}, {}, *Ctx);
Expand Down
Loading