@@ -1340,6 +1340,7 @@ void TPersQueue::Handle(TEvKeyValue::TEvResponse::TPtr& ev, const TActorContext&
1340
1340
EndWriteTabletState (resp, ctx);
1341
1341
break ;
1342
1342
case WRITE_TX_COOKIE:
1343
+ PQ_LOG_D (" Handle TEvKeyValue::TEvResponse (WRITE_TX_COOKIE)" );
1343
1344
EndWriteTxs (resp, ctx);
1344
1345
break ;
1345
1346
default :
@@ -3459,7 +3460,7 @@ void TPersQueue::Handle(TEvTxProcessing::TEvReadSetAck::TPtr& ev, const TActorCo
3459
3460
tx->OnReadSetAck (event);
3460
3461
tx->UnbindMsgsFromPipe (event.GetTabletConsumer ());
3461
3462
3462
- if (tx->State == NKikimrPQ::TTransaction::EXECUTED ) {
3463
+ if (tx->State == NKikimrPQ::TTransaction::WAIT_RS_ACKS ) {
3463
3464
CheckTxState (ctx, *tx);
3464
3465
3465
3466
TryWriteTxs (ctx);
@@ -3803,20 +3804,34 @@ void TPersQueue::ProcessWriteTxs(const TActorContext& ctx,
3803
3804
void TPersQueue::ProcessDeleteTxs (const TActorContext& ctx,
3804
3805
NKikimrClient::TKeyValueRequest& request)
3805
3806
{
3806
- Y_ABORT_UNLESS (!WriteTxsInProgress);
3807
+ Y_ABORT_UNLESS (!WriteTxsInProgress,
3808
+ " PQ %" PRIu64,
3809
+ TabletID ());
3807
3810
3808
3811
for (ui64 txId : DeleteTxs) {
3809
- auto tx = GetTransaction (ctx, txId);
3810
- Y_ABORT_UNLESS (tx );
3812
+ PQ_LOG_D ( " delete key for TxId " << txId);
3813
+ AddCmdDeleteTx (request, txId );
3811
3814
3812
- tx->AddCmdDelete (request);
3813
-
3814
- ChangedTxs.insert (tx->TxId );
3815
+ auto tx = GetTransaction (ctx, txId);
3816
+ if (tx) {
3817
+ ChangedTxs.insert (txId);
3818
+ }
3815
3819
}
3816
3820
3817
3821
DeleteTxs.clear ();
3818
3822
}
3819
3823
3824
+ void TPersQueue::AddCmdDeleteTx (NKikimrClient::TKeyValueRequest& request,
3825
+ ui64 txId)
3826
+ {
3827
+ TString key = GetTxKey (txId);
3828
+ auto range = request.AddCmdDeleteRange ()->MutableRange ();
3829
+ range->SetFrom (key);
3830
+ range->SetIncludeFrom (true );
3831
+ range->SetTo (key);
3832
+ range->SetIncludeTo (true );
3833
+ }
3834
+
3820
3835
void TPersQueue::ProcessConfigTx (const TActorContext& ctx,
3821
3836
TEvKeyValue::TEvRequest* request)
3822
3837
{
@@ -3938,6 +3953,7 @@ void TPersQueue::SendEvReadSetToReceivers(const TActorContext& ctx,
3938
3953
void TPersQueue::SendEvReadSetAckToSenders (const TActorContext& ctx,
3939
3954
TDistributedTransaction& tx)
3940
3955
{
3956
+ PQ_LOG_D (" TPersQueue::SendEvReadSetAckToSenders" );
3941
3957
for (auto & [target, event] : tx.ReadSetAcks ) {
3942
3958
PQ_LOG_D (" Send TEvTxProcessing::TEvReadSetAck " << event->ToString ());
3943
3959
ctx.Send (target, event.release ());
@@ -4307,42 +4323,87 @@ void TPersQueue::CheckTxState(const TActorContext& ctx,
4307
4323
Y_ABORT_UNLESS (false );
4308
4324
}
4309
4325
4326
+ WriteTx (tx, NKikimrPQ::TTransaction::EXECUTED);
4327
+
4310
4328
tx.State = NKikimrPQ::TTransaction::EXECUTED;
4311
4329
PQ_LOG_D (" TxId " << tx.TxId <<
4312
4330
" , NewState " << NKikimrPQ::TTransaction_EState_Name (tx.State ));
4313
- } else {
4314
- break ;
4315
4331
}
4316
4332
4317
- [[fallthrough]] ;
4333
+ break ;
4318
4334
4319
4335
case NKikimrPQ::TTransaction::EXECUTED:
4320
- PQ_LOG_D (" HaveAllRecipientsReceive " << tx.HaveAllRecipientsReceive ());
4321
- if (tx.HaveAllRecipientsReceive ()) {
4322
- if (tx.WriteId .Defined ()) {
4323
- BeginDeleteTx (tx);
4324
- } else {
4325
- DeleteTx (tx);
4326
- }
4336
+ SendEvReadSetAckToSenders (ctx, tx);
4337
+
4338
+ tx.State = NKikimrPQ::TTransaction::WAIT_RS_ACKS;
4339
+ PQ_LOG_D (" TxId " << tx.TxId <<
4340
+ " , NewState " << NKikimrPQ::TTransaction_EState_Name (tx.State ));
4341
+
4342
+ [[fallthrough]];
4343
+
4344
+ case NKikimrPQ::TTransaction::WAIT_RS_ACKS:
4345
+ PQ_LOG_D (" HaveAllRecipientsReceive " << tx.HaveAllRecipientsReceive () <<
4346
+ " , WriteIdIsDisabled " << WriteIdIsDisabled (tx.WriteId ));
4347
+ if (tx.HaveAllRecipientsReceive () && WriteIdIsDisabled (tx.WriteId )) {
4348
+ DeleteTx (tx);
4349
+ // implicitly switch to the state DELETING
4327
4350
}
4328
4351
4329
4352
break ;
4330
4353
4331
4354
case NKikimrPQ::TTransaction::DELETING:
4332
4355
// The PQ tablet has persisted its state. Now she can delete the transaction and take the next one.
4333
- SendEvReadSetAckToSenders (ctx, tx);
4334
4356
if (!TxQueue.empty () && (TxQueue.front ().second == tx.TxId )) {
4335
4357
TxQueue.pop ();
4336
4358
TryStartTransaction (ctx);
4337
4359
}
4360
+
4361
+ DeleteWriteId (tx.WriteId );
4362
+ PQ_LOG_D (" delete TxId " << tx.TxId );
4338
4363
Txs.erase (tx.TxId );
4364
+
4339
4365
// If this was the last transaction, then you need to send responses to messages about changes
4340
4366
// in the status of the PQ tablet (if they came)
4341
4367
TryReturnTabletStateAll (ctx);
4342
4368
break ;
4343
4369
}
4344
4370
}
4345
4371
4372
+ bool TPersQueue::WriteIdIsDisabled (const TMaybe<TWriteId>& writeId) const
4373
+ {
4374
+ if (!writeId.Defined ()) {
4375
+ return true ;
4376
+ }
4377
+
4378
+ Y_ABORT_UNLESS (TxWrites.contains (*writeId),
4379
+ " PQ %" PRIu64 " , WriteId {%" PRIu64 " , %" PRIu64 " }" ,
4380
+ TabletID (), writeId->NodeId , writeId->KeyId );
4381
+ const TTxWriteInfo& writeInfo = TxWrites.at (*writeId);
4382
+
4383
+ bool disabled =
4384
+ (writeInfo.LongTxSubscriptionStatus != NKikimrLongTxService::TEvLockStatus::STATUS_SUBSCRIBED) &&
4385
+ writeInfo.Partitions .empty ()
4386
+ ;
4387
+
4388
+ PQ_LOG_D (" WriteId " << *writeId << " is " << (disabled ? " disabled" : " enabled" ));
4389
+
4390
+ return disabled;
4391
+ }
4392
+
4393
+ void TPersQueue::DeleteWriteId (const TMaybe<TWriteId>& writeId)
4394
+ {
4395
+ if (!writeId.Defined ()) {
4396
+ return ;
4397
+ }
4398
+
4399
+ Y_ABORT_UNLESS (TxWrites.contains (*writeId),
4400
+ " PQ %" PRIu64 " , WriteId {%" PRIu64 " , %" PRIu64 " }" ,
4401
+ TabletID (), writeId->NodeId , writeId->KeyId );
4402
+
4403
+ PQ_LOG_D (" delete WriteId " << *writeId);
4404
+ TxWrites.erase (*writeId);
4405
+ }
4406
+
4346
4407
void TPersQueue::WriteTx (TDistributedTransaction& tx, NKikimrPQ::TTransaction::EState state)
4347
4408
{
4348
4409
WriteTxs[tx.TxId ] = state;
@@ -4375,7 +4436,9 @@ void TPersQueue::CheckChangedTxStates(const TActorContext& ctx)
4375
4436
{
4376
4437
for (ui64 txId : ChangedTxs) {
4377
4438
auto tx = GetTransaction (ctx, txId);
4378
- Y_ABORT_UNLESS (tx);
4439
+ Y_ABORT_UNLESS (tx,
4440
+ " PQ %" PRIu64 " , TxId %" PRIu64,
4441
+ TabletID (), txId);
4379
4442
4380
4443
CheckTxState (ctx, *tx);
4381
4444
}
@@ -4698,7 +4761,9 @@ void TPersQueue::Handle(NLongTxService::TEvLongTxService::TEvLockStatus::TPtr& e
4698
4761
PQ_LOG_D (" delete write info for WriteId " << writeId << " and TxId " << txId);
4699
4762
4700
4763
auto * tx = GetTransaction (ctx, txId);
4701
- if (!tx || (tx->State == NKikimrPQ::TTransaction::EXECUTED)) {
4764
+ if (!tx ||
4765
+ (tx->State == NKikimrPQ::TTransaction::EXECUTED) ||
4766
+ (tx->State == NKikimrPQ::TTransaction::WAIT_RS_ACKS)) {
4702
4767
BeginDeletePartitions (writeInfo);
4703
4768
}
4704
4769
}
@@ -4754,11 +4819,11 @@ void TPersQueue::Handle(TEvPQ::TEvDeletePartitionDone::TPtr& ev, const TActorCon
4754
4819
UnsubscribeWriteId (writeId, ctx);
4755
4820
if (writeInfo.TxId .Defined ()) {
4756
4821
if (auto tx = GetTransaction (ctx, *writeInfo.TxId ); tx) {
4757
- DeleteTx (*tx);
4822
+ if (tx->State == NKikimrPQ::TTransaction::WAIT_RS_ACKS) {
4823
+ CheckTxState (ctx, *tx);
4824
+ }
4758
4825
}
4759
4826
}
4760
- PQ_LOG_D (" delete WriteId " << writeId);
4761
- TxWrites.erase (writeId);
4762
4827
}
4763
4828
TxWritesChanged = true ;
4764
4829
@@ -4767,6 +4832,9 @@ void TPersQueue::Handle(TEvPQ::TEvDeletePartitionDone::TPtr& ev, const TActorCon
4767
4832
4768
4833
void TPersQueue::Handle (TEvPQ::TEvTransactionCompleted::TPtr& ev, const TActorContext&)
4769
4834
{
4835
+ PQ_LOG_D (" Handle TEvPQ::TEvTransactionCompleted" <<
4836
+ " WriteId " << ev->Get ()->WriteId );
4837
+
4770
4838
auto * event = ev->Get ();
4771
4839
if (!event->WriteId .Defined ()) {
4772
4840
return ;
@@ -4782,26 +4850,6 @@ void TPersQueue::Handle(TEvPQ::TEvTransactionCompleted::TPtr& ev, const TActorCo
4782
4850
BeginDeletePartitions (writeInfo);
4783
4851
}
4784
4852
4785
- void TPersQueue::BeginDeleteTx (const TDistributedTransaction& tx)
4786
- {
4787
- Y_ABORT_UNLESS (tx.WriteId .Defined ());
4788
- const TWriteId& writeId = *tx.WriteId ;
4789
- PQ_LOG_D (" begin delete write info for WriteId " << writeId);
4790
- if (!TxWrites.contains (writeId)) {
4791
- // the transaction has already been completed
4792
- PQ_LOG_D (" unknown WriteId " << writeId);
4793
- return ;
4794
- }
4795
-
4796
- TTxWriteInfo& writeInfo = TxWrites.at (writeId);
4797
- if (writeInfo.LongTxSubscriptionStatus == NKikimrLongTxService::TEvLockStatus::STATUS_SUBSCRIBED) {
4798
- PQ_LOG_D (" wait for WriteId subscription status" );
4799
- return ;
4800
- }
4801
-
4802
- BeginDeletePartitions (writeInfo);
4803
- }
4804
-
4805
4853
void TPersQueue::BeginDeletePartitions (TTxWriteInfo& writeInfo)
4806
4854
{
4807
4855
if (writeInfo.Deleting ) {
0 commit comments