@@ -109,6 +109,23 @@ namespace {
109
109
*protoLocks->AddLocks () = lock;
110
110
}
111
111
}
112
+
113
+ void FillTopicsCommit (NKikimrPQ::TDataTransaction& transaction, const NKikimr::NKqp::IKqpTransactionManagerPtr& txManager) {
114
+ transaction.SetOp (NKikimrPQ::TDataTransaction::Commit);
115
+ const auto prepareSettings = txManager->GetPrepareTransactionInfo ();
116
+
117
+ if (!prepareSettings.ArbiterColumnShard ) {
118
+ for (const ui64 sendingShardId : prepareSettings.SendingShards ) {
119
+ transaction.AddSendingShards (sendingShardId);
120
+ }
121
+ for (const ui64 receivingShardId : prepareSettings.ReceivingShards ) {
122
+ transaction.AddReceivingShards (receivingShardId);
123
+ }
124
+ } else {
125
+ transaction.AddSendingShards (*prepareSettings.ArbiterColumnShard );
126
+ transaction.AddReceivingShards (*prepareSettings.ArbiterColumnShard );
127
+ }
128
+ }
112
129
}
113
130
114
131
@@ -1594,7 +1611,7 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
1594
1611
Close ();
1595
1612
Process ();
1596
1613
SendToExternalShards (false );
1597
- SendToTopics ();
1614
+ SendToTopics (false );
1598
1615
}
1599
1616
1600
1617
void ImmediateCommit () {
@@ -1613,6 +1630,7 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
1613
1630
}
1614
1631
Close ();
1615
1632
Process ();
1633
+ SendToTopics (true );
1616
1634
}
1617
1635
1618
1636
void DistributedCommit () {
@@ -1640,6 +1658,7 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
1640
1658
CA_LOG_D (" Start rollback" );
1641
1659
State = EState::ROLLINGBACK;
1642
1660
SendToExternalShards (true );
1661
+ SendToTopics (true );
1643
1662
}
1644
1663
1645
1664
void SendToExternalShards (bool isRollback) {
@@ -1692,7 +1711,7 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
1692
1711
}
1693
1712
}
1694
1713
1695
- void SendToTopics () {
1714
+ void SendToTopics (bool isImmediateCommit ) {
1696
1715
if (!TxManager->HasTopics ()) {
1697
1716
return ;
1698
1717
}
@@ -1707,29 +1726,19 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
1707
1726
1708
1727
for (auto & [tabletId, t] : topicTxs) {
1709
1728
auto & transaction = t.tx ;
1710
- transaction.SetOp (NKikimrPQ::TDataTransaction::Commit);
1711
-
1712
- const auto prepareSettings = TxManager->GetPrepareTransactionInfo ();
1713
- if (!prepareSettings.ArbiterColumnShard ) {
1714
- for (const ui64 sendingShardId : prepareSettings.SendingShards ) {
1715
- transaction.AddSendingShards (sendingShardId);
1716
- }
1717
- for (const ui64 receivingShardId : prepareSettings.ReceivingShards ) {
1718
- transaction.AddReceivingShards (receivingShardId);
1719
- }
1720
- } else {
1721
- transaction.AddSendingShards (*prepareSettings.ArbiterColumnShard );
1722
- transaction.AddReceivingShards (*prepareSettings.ArbiterColumnShard );
1729
+
1730
+ if (!isImmediateCommit) {
1731
+ FillTopicsCommit (transaction, TxManager);
1723
1732
}
1724
1733
1725
- auto ev = std::make_unique<TEvPersQueue::TEvProposeTransactionBuilder>();
1726
-
1727
1734
if (t.hasWrite && writeId.Defined ()) {
1728
1735
auto * w = transaction.MutableWriteId ();
1729
1736
w->SetNodeId (SelfId ().NodeId ());
1730
1737
w->SetKeyId (*writeId);
1731
1738
}
1732
- transaction.SetImmediate (false );
1739
+ transaction.SetImmediate (isImmediateCommit);
1740
+
1741
+ auto ev = std::make_unique<TEvPersQueue::TEvProposeTransactionBuilder>();
1733
1742
1734
1743
ActorIdToProto (SelfId (), ev->Record .MutableSourceActor ());
1735
1744
ev->Record .MutableData ()->Swap (&transaction);
@@ -1738,7 +1747,8 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
1738
1747
SendTime[tabletId] = TInstant::Now ();
1739
1748
auto traceId = BufferWriteActor.GetTraceId ();
1740
1749
1741
- CA_LOG_D (" Preparing KQP transaction on topic tablet: " << tabletId << " , writeId: " << writeId);
1750
+ CA_LOG_D (" Executing KQP transaction on topic tablet: " << tabletId
1751
+ << " , writeId: " << writeId << " , isImmediateCommit: " << isImmediateCommit);
1742
1752
1743
1753
Send (
1744
1754
MakePipePerNodeCacheID (false ),
@@ -1962,7 +1972,7 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
1962
1972
Rollback ();
1963
1973
State = EState::FINISHED;
1964
1974
Send (ExecuterActorId, new TEvKqpBuffer::TEvResult{});
1965
- } else if (TxManager->IsSingleShard () && !TxManager->HasOlapTable () && !WriteInfos.empty () && ! TxManager->HasTopics ()) {
1975
+ } else if (TxManager->IsSingleShard () && !TxManager->HasOlapTable () && ( !WriteInfos.empty () || TxManager->HasTopics () )) {
1966
1976
TxManager->StartExecute ();
1967
1977
ImmediateCommit ();
1968
1978
} else {
0 commit comments