@@ -303,10 +303,11 @@ class TKqpTableWriteActor : public TActorBootstrapped<TKqpTableWriteActor> {
303
303
// TODO: Maybe there are better ways to initialize new shards...
304
304
for (const auto & shardInfo : ShardedWriteController->GetPendingShards ()) {
305
305
TxManager->AddShard (shardInfo.ShardId , IsOlap (), TablePath);
306
- TxManager-> AddAction (shardInfo. ShardId , IKqpTransactionManager::EAction::WRITE) ;
306
+ IKqpTransactionManager::TActionFlags flags = IKqpTransactionManager::EAction::WRITE;
307
307
if (shardInfo.HasRead ) {
308
- TxManager-> AddAction (shardInfo. ShardId , IKqpTransactionManager::EAction::READ) ;
308
+ flags |= IKqpTransactionManager::EAction::READ;
309
309
}
310
+ TxManager->AddAction (shardInfo.ShardId , flags);
310
311
}
311
312
}
312
313
@@ -540,7 +541,6 @@ class TKqpTableWriteActor : public TActorBootstrapped<TKqpTableWriteActor> {
540
541
<< " ShardID=" << ev->Get ()->Record .GetOrigin () << " ,"
541
542
<< " Sink=" << this ->SelfId () << " ."
542
543
<< getIssues ().ToOneLineString ());
543
-
544
544
// TODO: Add new status for splits in datashard. This is tmp solution.
545
545
if (getIssues ().ToOneLineString ().Contains (" in a pre/offline state assuming this is due to a finished split (wrong shard state)" )) {
546
546
ResetShardRetries (ev->Get ()->Record .GetOrigin (), ev->Cookie );
@@ -561,13 +561,12 @@ class TKqpTableWriteActor : public TActorBootstrapped<TKqpTableWriteActor> {
561
561
<< " ShardID=" << ev->Get ()->Record .GetOrigin () << " ,"
562
562
<< " Sink=" << this ->SelfId () << " ."
563
563
<< getIssues ().ToOneLineString ());
564
-
565
- RuntimeError (
566
- TStringBuilder () << " Disk space exhausted for table `"
567
- << TablePath << " `. "
568
- << getIssues ().ToOneLineString (),
569
- NYql::NDqProto::StatusIds::PRECONDITION_FAILED,
570
- getIssues ());
564
+ RuntimeError (
565
+ TStringBuilder () << " Disk space exhausted for table `"
566
+ << TablePath << " `. "
567
+ << getIssues ().ToOneLineString (),
568
+ NYql::NDqProto::StatusIds::UNAVAILABLE,
569
+ getIssues ());
571
570
return ;
572
571
}
573
572
case NKikimrDataEvents::TEvWriteResult::STATUS_OVERLOADED: {
@@ -670,7 +669,7 @@ class TKqpTableWriteActor : public TActorBootstrapped<TKqpTableWriteActor> {
670
669
preparedInfo.Coordinator = domainCoordinators.Select (*TxId);
671
670
}
672
671
673
- OnMessageAcknowledged (ev->Get ()->Record .GetOrigin ());
672
+ OnMessageReceived (ev->Get ()->Record .GetOrigin ());
674
673
const auto result = ShardedWriteController->OnMessageAcknowledged (
675
674
ev->Get ()->Record .GetOrigin (), ev->Cookie );
676
675
if (result) {
@@ -713,7 +712,7 @@ class TKqpTableWriteActor : public TActorBootstrapped<TKqpTableWriteActor> {
713
712
return ;
714
713
}
715
714
716
- OnMessageAcknowledged (ev->Get ()->Record .GetOrigin ());
715
+ OnMessageReceived (ev->Get ()->Record .GetOrigin ());
717
716
const auto result = ShardedWriteController->OnMessageAcknowledged (
718
717
ev->Get ()->Record .GetOrigin (), ev->Cookie );
719
718
if (result && result->IsShardEmpty && Mode == EMode::IMMEDIATE_COMMIT) {
@@ -723,7 +722,7 @@ class TKqpTableWriteActor : public TActorBootstrapped<TKqpTableWriteActor> {
723
722
}
724
723
}
725
724
726
- void OnMessageAcknowledged (const ui64 shardId) {
725
+ void OnMessageReceived (const ui64 shardId) {
727
726
if (auto it = SendTime.find (shardId); it != std::end (SendTime)) {
728
727
Counters->WriteActorWritesLatencyHistogram ->Collect ((TInstant::Now () - it->second ).MilliSeconds ());
729
728
SendTime.erase (it);
@@ -847,7 +846,7 @@ class TKqpTableWriteActor : public TActorBootstrapped<TKqpTableWriteActor> {
847
846
<< " , Attempts=" << metadata->SendAttempts << " , Mode=" << static_cast <int >(Mode));
848
847
Send (
849
848
PipeCacheId,
850
- new TEvPipeCache::TEvForward (evWrite.release (), shardId, true ),
849
+ new TEvPipeCache::TEvForward (evWrite.release (), shardId, /* subscribe */ true ),
851
850
IEventHandle::FlagTrackDelivery,
852
851
metadata->Cookie ,
853
852
TableWriteActorSpan.GetTraceId ());
@@ -1270,6 +1269,7 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
1270
1269
, Alloc(std::make_shared<NKikimr::NMiniKQL::TScopedAlloc>(__LOCATION__))
1271
1270
, TypeEnv(*Alloc)
1272
1271
, Counters(settings.Counters)
1272
+ , TxProxyMon(settings.TxProxyMon)
1273
1273
, BufferWriteActor(TWilsonKqp::BufferWriteActor, NWilson::TTraceId(settings.TraceId), " TKqpBufferWriteActor" , NWilson::EFlags::AUTO_END)
1274
1274
, BufferWriteActorState(TWilsonKqp::BufferWriteActorState, BufferWriteActor.GetTraceId(),
1275
1275
" BufferWriteActorState::Writing" , NWilson::EFlags::AUTO_END)
@@ -1552,6 +1552,7 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
1552
1552
FillEvWritePrepare (evWrite.get (), shardId, *TxId, TxManager);
1553
1553
}
1554
1554
1555
+ SendTime[shardId] = TInstant::Now ();
1555
1556
CA_LOG_D (" Send EvWrite (external) to ShardID=" << shardId << " , isPrepare=" << !isRollback << " , isImmediateCommit=" << isRollback << " , TxId=" << evWrite->Record .GetTxId ()
1556
1557
<< " , LockTxId=" << evWrite->Record .GetLockTxId () << " , LockNodeId=" << evWrite->Record .GetLockNodeId ()
1557
1558
<< " , Locks= " << [&]() {
@@ -1565,10 +1566,11 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
1565
1566
<< " , OperationsCount=" << 0 << " , IsFinal=" << 1
1566
1567
<< " , Attempts=" << 0 );
1567
1568
1569
+ // TODO: Track latecy
1568
1570
Send (
1569
1571
NKikimr::MakePipePerNodeCacheID (false ),
1570
- new TEvPipeCache::TEvForward (evWrite.release (), shardId, true ),
1571
- 0 ,
1572
+ new TEvPipeCache::TEvForward (evWrite.release (), shardId, /* subscribe */ true ),
1573
+ IEventHandle::FlagTrackDelivery ,
1572
1574
0 );
1573
1575
}
1574
1576
}
@@ -1672,26 +1674,30 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
1672
1674
1673
1675
switch (res->GetStatus ()) {
1674
1676
case TEvTxProxy::TEvProposeTransactionStatus::EStatus::StatusAccepted:
1675
- // TODO: metrics
1677
+ TxProxyMon-> ClientTxStatusAccepted -> Inc ();
1676
1678
break ;
1677
1679
case TEvTxProxy::TEvProposeTransactionStatus::EStatus::StatusProcessed:
1680
+ TxProxyMon->ClientTxStatusProcessed ->Inc ();
1678
1681
break ;
1679
1682
case TEvTxProxy::TEvProposeTransactionStatus::EStatus::StatusConfirmed:
1683
+ TxProxyMon->ClientTxStatusConfirmed ->Inc ();
1680
1684
break ;
1681
1685
1682
1686
case TEvTxProxy::TEvProposeTransactionStatus::EStatus::StatusPlanned:
1687
+ TxProxyMon->ClientTxStatusPlanned ->Inc ();
1683
1688
break ;
1684
1689
1685
1690
case TEvTxProxy::TEvProposeTransactionStatus::EStatus::StatusOutdated:
1686
1691
case TEvTxProxy::TEvProposeTransactionStatus::EStatus::StatusDeclined:
1687
1692
case TEvTxProxy::TEvProposeTransactionStatus::EStatus::StatusDeclinedNoSpace:
1688
1693
case TEvTxProxy::TEvProposeTransactionStatus::EStatus::StatusRestarting:
1689
- // TODO: CancelProposal???
1694
+ TxProxyMon-> ClientTxStatusCoordinatorDeclined -> Inc ();
1690
1695
ReplyErrorAndDie (TStringBuilder () << " Failed to plan transaction, status: " << res->GetStatus (), NYql::NDqProto::StatusIds::UNAVAILABLE, {});
1691
1696
break ;
1692
1697
1693
1698
case TEvTxProxy::TEvProposeTransactionStatus::EStatus::StatusUnknown:
1694
1699
case TEvTxProxy::TEvProposeTransactionStatus::EStatus::StatusAborted:
1700
+ TxProxyMon->ClientTxStatusCoordinatorDeclined ->Inc ();
1695
1701
ReplyErrorAndDie (TStringBuilder () << " Unexpected TEvProposeTransactionStatus status: " << res->GetStatus (), NYql::NDqProto::StatusIds::INTERNAL_ERROR, {});
1696
1702
break ;
1697
1703
}
@@ -1797,7 +1803,6 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
1797
1803
<< " ShardID=" << ev->Get ()->Record .GetOrigin () << " ,"
1798
1804
<< " Sink=" << this ->SelfId () << " ."
1799
1805
<< getIssues ().ToOneLineString ());
1800
-
1801
1806
ReplyErrorAndDie (
1802
1807
TStringBuilder () << " Internal error for table. "
1803
1808
<< getIssues ().ToOneLineString (),
@@ -1810,11 +1815,10 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
1810
1815
<< " ShardID=" << ev->Get ()->Record .GetOrigin () << " ,"
1811
1816
<< " Sink=" << this ->SelfId () << " ."
1812
1817
<< getIssues ().ToOneLineString ());
1813
-
1814
1818
ReplyErrorAndDie (
1815
1819
TStringBuilder () << " Disk space exhausted for table. "
1816
1820
<< getIssues ().ToOneLineString (),
1817
- NYql::NDqProto::StatusIds::PRECONDITION_FAILED ,
1821
+ NYql::NDqProto::StatusIds::UNAVAILABLE ,
1818
1822
getIssues ());
1819
1823
return ;
1820
1824
}
@@ -1824,7 +1828,6 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
1824
1828
<< " Sink=" << this ->SelfId () << " ."
1825
1829
<< " Ignored this error."
1826
1830
<< getIssues ().ToOneLineString ());
1827
- // TODO: support waiting
1828
1831
ReplyErrorAndDie (
1829
1832
TStringBuilder () << " Tablet " << ev->Get ()->Record .GetOrigin () << " is overloaded."
1830
1833
<< getIssues ().ToOneLineString (),
@@ -1886,11 +1889,23 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
1886
1889
}
1887
1890
}
1888
1891
1892
+ void OnMessageReceived (const ui64 shardId) {
1893
+ if (auto it = SendTime.find (shardId); it != std::end (SendTime)) {
1894
+ Counters->WriteActorWritesLatencyHistogram ->Collect ((TInstant::Now () - it->second ).MilliSeconds ());
1895
+ SendTime.erase (it);
1896
+ }
1897
+ }
1898
+
1889
1899
void ProcessWritePreparedShard (NKikimr::NEvents::TDataEvents::TEvWriteResult::TPtr& ev) {
1890
1900
if (State != EState::PREPARING) {
1891
1901
CA_LOG_D (" Ignored write prepared event." );
1892
1902
return ;
1893
1903
}
1904
+ OnMessageReceived (ev->Get ()->Record .GetOrigin ());
1905
+ CA_LOG_D (" Got prepared result TxId=" << ev->Get ()->Record .GetTxId ()
1906
+ << " , TabletId=" << ev->Get ()->Record .GetOrigin ()
1907
+ << " , Cookie=" << ev->Cookie );
1908
+
1894
1909
const auto & record = ev->Get ()->Record ;
1895
1910
IKqpTransactionManager::TPrepareResult preparedInfo;
1896
1911
preparedInfo.ShardId = record.GetOrigin ();
@@ -1912,6 +1927,7 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
1912
1927
CA_LOG_D (" Ignored write completed event." );
1913
1928
return ;
1914
1929
}
1930
+ OnMessageReceived (ev->Get ()->Record .GetOrigin ());
1915
1931
CA_LOG_D (" Got completed result TxId=" << ev->Get ()->Record .GetTxId ()
1916
1932
<< " , TabletId=" << ev->Get ()->Record .GetOrigin ()
1917
1933
<< " , Cookie=" << ev->Cookie
@@ -2033,6 +2049,9 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
2033
2049
IShardedWriteControllerPtr ShardedWriteController = nullptr ;
2034
2050
2035
2051
TIntrusivePtr<TKqpCounters> Counters;
2052
+ TIntrusivePtr<NTxProxy::TTxProxyMon> TxProxyMon;
2053
+ THashMap<ui64, TInstant> SendTime;
2054
+
2036
2055
NWilson::TSpan BufferWriteActor;
2037
2056
NWilson::TSpan BufferWriteActorState;
2038
2057
};
0 commit comments