@@ -1041,16 +1041,21 @@ void TPersQueue::InitTxWrites(const NKikimrPQ::TTabletTxInfo& info,
1041
1041
for (size_t i = 0 ; i != info.TxWritesSize (); ++i) {
1042
1042
auto & txWrite = info.GetTxWrites (i);
1043
1043
const TWriteId writeId = GetWriteId (txWrite);
1044
- ui32 partitionId = txWrite.GetOriginalPartitionId ();
1045
- TPartitionId shadowPartitionId (partitionId, writeId, txWrite.GetInternalPartitionId ());
1046
1044
1047
- TxWrites[writeId].Partitions .emplace (partitionId, shadowPartitionId);
1045
+ TTxWriteInfo& writeInfo = TxWrites[writeId];
1046
+ if (txWrite.HasOriginalPartitionId ()) {
1047
+ ui32 partitionId = txWrite.GetOriginalPartitionId ();
1048
+ TPartitionId shadowPartitionId (partitionId, writeId, txWrite.GetInternalPartitionId ());
1048
1049
1049
- AddSupportivePartition (shadowPartitionId);
1050
- CreateSupportivePartitionActor (shadowPartitionId, ctx);
1051
- SubscribeWriteId (writeId, ctx);
1050
+ writeInfo.Partitions .emplace (partitionId, shadowPartitionId);
1051
+
1052
+ AddSupportivePartition (shadowPartitionId);
1053
+ CreateSupportivePartitionActor (shadowPartitionId, ctx);
1054
+
1055
+ NextSupportivePartitionId = Max (NextSupportivePartitionId, shadowPartitionId.InternalPartitionId + 1 );
1056
+ }
1052
1057
1053
- NextSupportivePartitionId = Max (NextSupportivePartitionId, shadowPartitionId. InternalPartitionId + 1 );
1058
+ SubscribeWriteId (writeId, ctx );
1054
1059
}
1055
1060
1056
1061
NewSupportivePartitions.clear ();
@@ -3283,7 +3288,7 @@ bool TPersQueue::CheckTxWriteOperation(const NKikimrPQ::TPartitionOperation& ope
3283
3288
TPartitionId partitionId (operation.GetPartitionId (),
3284
3289
writeId,
3285
3290
operation.GetSupportivePartition ());
3286
- PQ_LOG_D (" partitionId= " << partitionId);
3291
+ PQ_LOG_D (" PartitionId " << partitionId << " for WriteId " << writeId );
3287
3292
return Partitions.contains (partitionId);
3288
3293
}
3289
3294
@@ -3294,7 +3299,6 @@ bool TPersQueue::CheckTxWriteOperations(const NKikimrPQ::TDataTransaction& txBod
3294
3299
}
3295
3300
3296
3301
const TWriteId writeId = GetWriteId (txBody);
3297
- PQ_LOG_D (" writeId=" << writeId);
3298
3302
3299
3303
for (auto & operation : txBody.GetOperations ()) {
3300
3304
auto isWrite = [](const NKikimrPQ::TPartitionOperation& o) {
@@ -3320,7 +3324,7 @@ void TPersQueue::HandleDataTransaction(TAutoPtr<TEvPersQueue::TEvProposeTransact
3320
3324
const NKikimrPQ::TDataTransaction& txBody = event.GetData ();
3321
3325
3322
3326
if (TabletState != NKikimrPQ::ENormal) {
3323
- PQ_LOG_D (" invalid PQ tablet state (" << NKikimrPQ::ETabletState_Name (TabletState) << " )" );
3327
+ PQ_LOG_D (" TxId " << event. GetTxId () << " invalid PQ tablet state (" << NKikimrPQ::ETabletState_Name (TabletState) << " )" );
3324
3328
SendProposeTransactionAbort (ActorIdFromProto (event.GetSourceActor ()),
3325
3329
event.GetTxId (),
3326
3330
NKikimrPQ::TError::ERROR,
@@ -3334,7 +3338,7 @@ void TPersQueue::HandleDataTransaction(TAutoPtr<TEvPersQueue::TEvProposeTransact
3334
3338
//
3335
3339
3336
3340
if (txBody.OperationsSize () <= 0 ) {
3337
- PQ_LOG_D (" empty list of operations" );
3341
+ PQ_LOG_D (" TxId " << event. GetTxId () << " empty list of operations" );
3338
3342
SendProposeTransactionAbort (ActorIdFromProto (event.GetSourceActor ()),
3339
3343
event.GetTxId (),
3340
3344
NKikimrPQ::TError::BAD_REQUEST,
@@ -3344,7 +3348,7 @@ void TPersQueue::HandleDataTransaction(TAutoPtr<TEvPersQueue::TEvProposeTransact
3344
3348
}
3345
3349
3346
3350
if (!CheckTxWriteOperations (txBody)) {
3347
- PQ_LOG_D (" invalid WriteId " << txBody.GetWriteId ());
3351
+ PQ_LOG_D (" TxId " << event. GetTxId () << " invalid WriteId " << txBody.GetWriteId ());
3348
3352
SendProposeTransactionAbort (ActorIdFromProto (event.GetSourceActor ()),
3349
3353
event.GetTxId (),
3350
3354
NKikimrPQ::TError::BAD_REQUEST,
@@ -3353,9 +3357,36 @@ void TPersQueue::HandleDataTransaction(TAutoPtr<TEvPersQueue::TEvProposeTransact
3353
3357
return ;
3354
3358
}
3355
3359
3360
+ if (txBody.HasWriteId ()) {
3361
+ const TWriteId writeId = GetWriteId (txBody);
3362
+ if (!TxWrites.contains (writeId)) {
3363
+ PQ_LOG_D (" TxId " << event.GetTxId () << " unknown WriteId " << writeId);
3364
+ SendProposeTransactionAbort (ActorIdFromProto (event.GetSourceActor ()),
3365
+ event.GetTxId (),
3366
+ NKikimrPQ::TError::BAD_REQUEST,
3367
+ " unknown WriteId" ,
3368
+ ctx);
3369
+ return ;
3370
+ }
3371
+
3372
+ TTxWriteInfo& writeInfo = TxWrites.at (writeId);
3373
+ if (writeInfo.Deleting ) {
3374
+ PQ_LOG_W (" TxId " << event.GetTxId () << " WriteId " << writeId << " will be deleted" );
3375
+ SendProposeTransactionAbort (ActorIdFromProto (event.GetSourceActor ()),
3376
+ event.GetTxId (),
3377
+ NKikimrPQ::TError::BAD_REQUEST,
3378
+ " WriteId will be deleted" ,
3379
+ ctx);
3380
+ return ;
3381
+ }
3382
+
3383
+ writeInfo.TxId = event.GetTxId ();
3384
+ PQ_LOG_D (" TxId " << event.GetTxId () << " has WriteId " << writeId);
3385
+ }
3386
+
3356
3387
TMaybe<TPartitionId> partitionId = FindPartitionId (txBody);
3357
3388
if (!partitionId.Defined ()) {
3358
- PQ_LOG_D ( " unknown partition for WriteId " << txBody.GetWriteId ());
3389
+ PQ_LOG_W ( " TxId " << event. GetTxId () << " unknown partition for WriteId " << txBody.GetWriteId ());
3359
3390
SendProposeTransactionAbort (ActorIdFromProto (event.GetSourceActor ()),
3360
3391
event.GetTxId (),
3361
3392
NKikimrPQ::TError::INTERNAL,
@@ -3568,13 +3599,15 @@ bool TPersQueue::CanProcessTxWrites() const
3568
3599
void TPersQueue::SubscribeWriteId (const TWriteId& writeId,
3569
3600
const TActorContext& ctx)
3570
3601
{
3602
+ PQ_LOG_D (" send TEvSubscribeLock for WriteId " << writeId);
3571
3603
ctx.Send (NLongTxService::MakeLongTxServiceID (writeId.NodeId ),
3572
3604
new NLongTxService::TEvLongTxService::TEvSubscribeLock (writeId.KeyId , writeId.NodeId ));
3573
3605
}
3574
3606
3575
3607
void TPersQueue::UnsubscribeWriteId (const TWriteId& writeId,
3576
3608
const TActorContext& ctx)
3577
3609
{
3610
+ PQ_LOG_D (" send TEvUnsubscribeLock for WriteId " << writeId);
3578
3611
ctx.Send (NLongTxService::MakeLongTxServiceID (writeId.NodeId ),
3579
3612
new NLongTxService::TEvLongTxService::TEvUnsubscribeLock (writeId.KeyId , writeId.NodeId ));
3580
3613
}
@@ -3876,11 +3909,16 @@ void TPersQueue::SavePlanStep(NKikimrPQ::TTabletTxInfo& info)
3876
3909
void TPersQueue::SaveTxWrites (NKikimrPQ::TTabletTxInfo& info)
3877
3910
{
3878
3911
for (auto & [writeId, write ] : TxWrites) {
3879
- for ( auto [partitionId, shadowPartitionId] : write .Partitions ) {
3912
+ if ( write .Partitions . empty () ) {
3880
3913
auto * txWrite = info.MutableTxWrites ()->Add ();
3881
3914
SetWriteId (*txWrite, writeId);
3882
- txWrite->SetOriginalPartitionId (partitionId);
3883
- txWrite->SetInternalPartitionId (shadowPartitionId.InternalPartitionId );
3915
+ } else {
3916
+ for (auto [partitionId, shadowPartitionId] : write .Partitions ) {
3917
+ auto * txWrite = info.MutableTxWrites ()->Add ();
3918
+ SetWriteId (*txWrite, writeId);
3919
+ txWrite->SetOriginalPartitionId (partitionId);
3920
+ txWrite->SetInternalPartitionId (shadowPartitionId.InternalPartitionId );
3921
+ }
3884
3922
}
3885
3923
}
3886
3924
@@ -4325,6 +4363,9 @@ void TPersQueue::CheckTxState(const TActorContext& ctx,
4325
4363
4326
4364
WriteTx (tx, NKikimrPQ::TTransaction::EXECUTED);
4327
4365
4366
+ PQ_LOG_D (" delete partitions for TxId " << tx.TxId );
4367
+ BeginDeletePartitions (tx);
4368
+
4328
4369
tx.State = NKikimrPQ::TTransaction::EXECUTED;
4329
4370
PQ_LOG_D (" TxId " << tx.TxId <<
4330
4371
" , NewState " << NKikimrPQ::TTransaction_EState_Name (tx.State ));
@@ -4343,8 +4384,8 @@ void TPersQueue::CheckTxState(const TActorContext& ctx,
4343
4384
4344
4385
case NKikimrPQ::TTransaction::WAIT_RS_ACKS:
4345
4386
PQ_LOG_D (" HaveAllRecipientsReceive " << tx.HaveAllRecipientsReceive () <<
4346
- " , WriteIdIsDisabled " << WriteIdIsDisabled (tx.WriteId ));
4347
- if (tx.HaveAllRecipientsReceive () && WriteIdIsDisabled (tx.WriteId )) {
4387
+ " , AllSupportivePartitionsHaveBeenDeleted " << AllSupportivePartitionsHaveBeenDeleted (tx.WriteId ));
4388
+ if (tx.HaveAllRecipientsReceive () && AllSupportivePartitionsHaveBeenDeleted (tx.WriteId )) {
4348
4389
DeleteTx (tx);
4349
4390
// implicitly switch to the state DELETING
4350
4391
}
@@ -4369,7 +4410,7 @@ void TPersQueue::CheckTxState(const TActorContext& ctx,
4369
4410
}
4370
4411
}
4371
4412
4372
- bool TPersQueue::WriteIdIsDisabled (const TMaybe<TWriteId>& writeId) const
4413
+ bool TPersQueue::AllSupportivePartitionsHaveBeenDeleted (const TMaybe<TWriteId>& writeId) const
4373
4414
{
4374
4415
if (!writeId.Defined ()) {
4375
4416
return true ;
@@ -4380,26 +4421,21 @@ bool TPersQueue::WriteIdIsDisabled(const TMaybe<TWriteId>& writeId) const
4380
4421
TabletID (), writeId->NodeId , writeId->KeyId );
4381
4422
const TTxWriteInfo& writeInfo = TxWrites.at (*writeId);
4382
4423
4383
- bool disabled =
4384
- (writeInfo.LongTxSubscriptionStatus != NKikimrLongTxService::TEvLockStatus::STATUS_SUBSCRIBED) &&
4424
+ PQ_LOG_D (" WriteId " << *writeId <<
4425
+ " Partitions.size=" << writeInfo.Partitions .size ());
4426
+ bool deleted =
4385
4427
writeInfo.Partitions .empty ()
4386
4428
;
4387
4429
4388
- PQ_LOG_D (" WriteId " << *writeId << " is " << (disabled ? " disabled" : " enabled" ));
4389
-
4390
- return disabled;
4430
+ return deleted;
4391
4431
}
4392
4432
4393
4433
void TPersQueue::DeleteWriteId (const TMaybe<TWriteId>& writeId)
4394
4434
{
4395
- if (!writeId.Defined ()) {
4435
+ if (!writeId.Defined () || !TxWrites. contains (*writeId) ) {
4396
4436
return ;
4397
4437
}
4398
4438
4399
- Y_ABORT_UNLESS (TxWrites.contains (*writeId),
4400
- " PQ %" PRIu64 " , WriteId {%" PRIu64 " , %" PRIu64 " }" ,
4401
- TabletID (), writeId->NodeId , writeId->KeyId );
4402
-
4403
4439
PQ_LOG_D (" delete WriteId " << *writeId);
4404
4440
TxWrites.erase (*writeId);
4405
4441
}
@@ -4729,7 +4765,7 @@ void TPersQueue::ProcessCheckPartitionStatusRequests(const TPartitionId& partiti
4729
4765
}
4730
4766
}
4731
4767
4732
- void TPersQueue::Handle (NLongTxService::TEvLongTxService::TEvLockStatus::TPtr& ev, const TActorContext& ctx )
4768
+ void TPersQueue::Handle (NLongTxService::TEvLongTxService::TEvLockStatus::TPtr& ev)
4733
4769
{
4734
4770
PQ_LOG_D (" Handle TEvLongTxService::TEvLockStatus " << ev->Get ()->Record .ShortDebugString ());
4735
4771
@@ -4750,22 +4786,14 @@ void TPersQueue::Handle(NLongTxService::TEvLongTxService::TEvLockStatus::TPtr& e
4750
4786
return ;
4751
4787
}
4752
4788
4753
- if (!writeInfo.TxId .Defined ()) {
4754
- PQ_LOG_D (" delete write info for WriteId " << writeId);
4755
- // the message TEvProposeTransaction will not come anymore
4756
- BeginDeletePartitions (writeInfo);
4789
+ if (writeInfo.TxId .Defined ()) {
4790
+ // the message `TEvProposeTransaction` has already arrived
4791
+ PQ_LOG_D (" there is already a transaction TxId " << writeInfo.TxId << " for WriteId " << writeId);
4757
4792
return ;
4758
4793
}
4759
4794
4760
- ui64 txId = *writeInfo.TxId ;
4761
- PQ_LOG_D (" delete write info for WriteId " << writeId << " and TxId " << txId);
4762
-
4763
- auto * tx = GetTransaction (ctx, txId);
4764
- if (!tx ||
4765
- (tx->State == NKikimrPQ::TTransaction::EXECUTED) ||
4766
- (tx->State == NKikimrPQ::TTransaction::WAIT_RS_ACKS)) {
4767
- BeginDeletePartitions (writeInfo);
4768
- }
4795
+ PQ_LOG_D (" delete partitions for WriteId " << writeId);
4796
+ BeginDeletePartitions (writeInfo);
4769
4797
}
4770
4798
4771
4799
void TPersQueue::Handle (TEvPQ::TEvReadingPartitionStatusRequest::TPtr& ev, const TActorContext& ctx)
@@ -4865,6 +4893,16 @@ void TPersQueue::BeginDeletePartitions(TTxWriteInfo& writeInfo)
4865
4893
writeInfo.Deleting = true ;
4866
4894
}
4867
4895
4896
+ void TPersQueue::BeginDeletePartitions (const TDistributedTransaction& tx)
4897
+ {
4898
+ if (!tx.WriteId .Defined () || !TxWrites.contains (*tx.WriteId )) {
4899
+ return ;
4900
+ }
4901
+
4902
+ TTxWriteInfo& writeInfo = TxWrites.at (*tx.WriteId );
4903
+ BeginDeletePartitions (writeInfo);
4904
+ }
4905
+
4868
4906
TString TPersQueue::LogPrefix () const {
4869
4907
return TStringBuilder () << " [PQ: " << TabletID () << " ] " ;
4870
4908
}
@@ -4919,7 +4957,7 @@ bool TPersQueue::HandleHook(STFUNC_SIG)
4919
4957
HFuncTraced (TEvMediatorTimecast::TEvRegisterTabletResult, Handle );
4920
4958
HFuncTraced (TEvPQ::TEvCheckPartitionStatusRequest, Handle );
4921
4959
HFuncTraced (TEvPQ::TEvPartitionScaleStatusChanged, Handle );
4922
- HFuncTraced (NLongTxService::TEvLongTxService::TEvLockStatus, Handle );
4960
+ hFuncTraced (NLongTxService::TEvLongTxService::TEvLockStatus, Handle );
4923
4961
HFuncTraced (TEvPQ::TEvReadingPartitionStatusRequest, Handle );
4924
4962
HFuncTraced (TEvPQ::TEvDeletePartitionDone, Handle );
4925
4963
HFuncTraced (TEvPQ::TEvTransactionCompleted, Handle );
0 commit comments