@@ -3322,7 +3322,7 @@ void TPersQueue::ScheduleDeleteExpiredKafkaTransactions() {
33223322 for (auto & pair : TxWrites) {
33233323 if (txnExpired (pair.second )) {
33243324 PQ_LOG_D (" Transaction for Kafka producer " << pair.first .KafkaProducerInstanceId << " is expired" );
3325- BeginDeletePartitions (pair.second );
3325+ BeginDeletePartitions (pair.first , pair. second );
33263326 }
33273327 }
33283328}
@@ -5420,7 +5420,7 @@ void TPersQueue::Handle(NLongTxService::TEvLongTxService::TEvLockStatus::TPtr& e
54205420 }
54215421
54225422 PQ_LOG_TX_I (" delete partitions for WriteId " << writeId << " (longTxService lost tx)" );
5423- BeginDeletePartitions (writeInfo);
5423+ BeginDeletePartitions (writeId, writeInfo);
54245424}
54255425
54265426void TPersQueue::Handle (TEvPQ::TEvReadingPartitionStatusRequest::TPtr& ev, const TActorContext& ctx)
@@ -5470,6 +5470,14 @@ void TPersQueue::Handle(TEvPQ::TEvDeletePartitionDone::TPtr& ev, const TActorCon
54705470 DeletePartition (partitionId, ctx);
54715471
54725472 writeInfo.Partitions .erase (partitionId.OriginalPartitionId );
5473+ TryDeleteWriteId (writeId, writeInfo, ctx);
5474+ TxWritesChanged = true ;
5475+
5476+ TryWriteTxs (ctx);
5477+ }
5478+
5479+ void TPersQueue::TryDeleteWriteId (const TWriteId& writeId, const TTxWriteInfo& writeInfo, const TActorContext& ctx)
5480+ {
54735481 if (writeInfo.Partitions .empty ()) {
54745482 if (!writeInfo.KafkaTransaction ) {
54755483 UnsubscribeWriteId (writeId, ctx);
@@ -5481,14 +5489,15 @@ void TPersQueue::Handle(TEvPQ::TEvDeletePartitionDone::TPtr& ev, const TActorCon
54815489 (tx->State == NKikimrPQ::TTransaction::CANCELED)) {
54825490 TryExecuteTxs (ctx, *tx);
54835491 }
5492+ } else {
5493+ // if the transaction is not in Txs, then it is an immediate transaction
5494+ DeleteWriteId (writeId);
54845495 }
5485- } else if (writeInfo.KafkaTransaction ) { // case when kafka transaction haven't even started in KQP, but data for it was already written in partition
5496+ } else {
5497+ // this is kafka transaction or immediate transaction
54865498 DeleteWriteId (writeId);
54875499 }
54885500 }
5489- TxWritesChanged = true ;
5490-
5491- TryWriteTxs (ctx);
54925501}
54935502
54945503void TPersQueue::Handle (TEvPQ::TEvTransactionCompleted::TPtr& ev, const TActorContext&)
@@ -5508,20 +5517,24 @@ void TPersQueue::Handle(TEvPQ::TEvTransactionCompleted::TPtr& ev, const TActorCo
55085517 TTxWriteInfo& writeInfo = TxWrites.at (writeId);
55095518 Y_ABORT_UNLESS (writeInfo.Partitions .size () == 1 );
55105519
5511- BeginDeletePartitions (writeInfo);
5520+ BeginDeletePartitions (writeId, writeInfo);
55125521}
55135522
5514- void TPersQueue::BeginDeletePartitions (TTxWriteInfo& writeInfo)
5523+ void TPersQueue::BeginDeletePartitions (const TWriteId& writeId, TTxWriteInfo& writeInfo)
55155524{
55165525 if (writeInfo.Deleting ) {
55175526 PQ_LOG_TX_D (" Already deleting WriteInfo" );
55185527 return ;
55195528 }
5520- for (auto & [_, partitionId] : writeInfo.Partitions ) {
5521- Y_ABORT_UNLESS (Partitions.contains (partitionId));
5522- const TPartitionInfo& partition = Partitions.at (partitionId);
5523- PQ_LOG_TX_D (" send TEvPQ::TEvDeletePartition to partition " << partitionId);
5524- Send (partition.Actor , new TEvPQ::TEvDeletePartition);
5529+ if (writeInfo.Partitions .empty ()) {
5530+ TryDeleteWriteId (writeId, writeInfo, ActorContext ());
5531+ } else {
5532+ for (auto & [_, partitionId] : writeInfo.Partitions ) {
5533+ Y_ABORT_UNLESS (Partitions.contains (partitionId));
5534+ const TPartitionInfo& partition = Partitions.at (partitionId);
5535+ PQ_LOG_TX_D (" send TEvPQ::TEvDeletePartition to partition " << partitionId);
5536+ Send (partition.Actor , new TEvPQ::TEvDeletePartition);
5537+ }
55255538 }
55265539 writeInfo.Deleting = true ;
55275540}
@@ -5533,7 +5546,7 @@ void TPersQueue::BeginDeletePartitions(const TDistributedTransaction& tx)
55335546 }
55345547
55355548 TTxWriteInfo& writeInfo = TxWrites.at (*tx.WriteId );
5536- BeginDeletePartitions (writeInfo);
5549+ BeginDeletePartitions (*tx. WriteId , writeInfo);
55375550}
55385551
55395552TString TPersQueue::LogPrefix () const {
0 commit comments