19
19
#include < ydb/core/tx/tx.h>
20
20
#include < ydb/library/actors/core/actorsystem.h>
21
21
#include < ydb/library/actors/core/interconnect.h>
22
+ #include < ydb/library/wilson_ids/wilson.h>
22
23
#include < ydb/library/yql/dq/actors/compute/dq_compute_actor_impl.h>
23
24
#include < ydb/library/yql/public/issue/yql_issue_message.h>
24
25
@@ -134,10 +135,13 @@ class TKqpDirectWriteActor : public TActorBootstrapped<TKqpDirectWriteActor>, pu
134
135
, InconsistentTx(
135
136
Settings.GetInconsistentTx())
136
137
, MemoryLimit(MessageSettings.InFlightMemoryLimitPerActorBytes)
138
+ , WriteActorSpan(TWilsonKqp::WriteActor, NWilson::TTraceId(args.TraceId), "WriteActor")
137
139
{
138
140
YQL_ENSURE (std::holds_alternative<ui64>(TxId));
139
141
YQL_ENSURE (!ImmediateTx);
140
142
EgressStats.Level = args.StatsLevel ;
143
+
144
+ Counters->WriteActorsCount ->Inc ();
141
145
}
142
146
143
147
void Bootstrap () {
@@ -244,6 +248,7 @@ class TKqpDirectWriteActor : public TActorBootstrapped<TKqpDirectWriteActor>, pu
244
248
}
245
249
246
250
void ResolveTable () {
251
+ Counters->WriteActorsShardResolve ->Inc ();
247
252
SchemeEntry.reset ();
248
253
SchemeRequest.reset ();
249
254
@@ -267,8 +272,11 @@ class TKqpDirectWriteActor : public TActorBootstrapped<TKqpDirectWriteActor>, pu
267
272
entry.ShowPrivatePath = true ;
268
273
request->ResultSet .emplace_back (entry);
269
274
270
- Send (MakeSchemeCacheID (), new TEvTxProxySchemeCache::TEvInvalidateTable (TableId, {}));
271
- Send (MakeSchemeCacheID (), new TEvTxProxySchemeCache::TEvNavigateKeySet (request));
275
+ WriteActorStateSpan = NWilson::TSpan (TWilsonKqp::WriteActorTableNavigate, WriteActorSpan.GetTraceId (),
276
+ " WaitForShardsResolve" , NWilson::EFlags::AUTO_END);
277
+
278
+ Send (MakeSchemeCacheID (), new TEvTxProxySchemeCache::TEvInvalidateTable (TableId, {}), 0 , 0 , WriteActorSpan.GetTraceId ());
279
+ Send (MakeSchemeCacheID (), new TEvTxProxySchemeCache::TEvNavigateKeySet (request), 0 , 0 , WriteActorSpan.GetTraceId ());
272
280
}
273
281
274
282
void Handle (TEvTxProxySchemeCache::TEvNavigateKeySetResult::TPtr& ev) {
@@ -327,7 +335,7 @@ class TKqpDirectWriteActor : public TActorBootstrapped<TKqpDirectWriteActor>, pu
327
335
request->ResultSet .emplace_back (std::move (keyRange));
328
336
329
337
TAutoPtr<TEvTxProxySchemeCache::TEvResolveKeySet> resolveReq (new TEvTxProxySchemeCache::TEvResolveKeySet (request));
330
- Send (MakeSchemeCacheID (), resolveReq.Release (), 0 , 0 );
338
+ Send (MakeSchemeCacheID (), resolveReq.Release (), 0 , 0 , WriteActorSpan. GetTraceId () );
331
339
}
332
340
333
341
void Handle (TEvTxProxySchemeCache::TEvResolveKeySetResult::TPtr& ev) {
@@ -368,6 +376,8 @@ class TKqpDirectWriteActor : public TActorBootstrapped<TKqpDirectWriteActor>, pu
368
376
}()
369
377
<< " , Cookie=" << ev->Cookie );
370
378
379
+
380
+
371
381
switch (ev->Get ()->GetStatus ()) {
372
382
case NKikimrDataEvents::TEvWriteResult::STATUS_UNSPECIFIED: {
373
383
CA_LOG_E (" Got UNSPECIFIED for table `"
@@ -557,6 +567,11 @@ class TKqpDirectWriteActor : public TActorBootstrapped<TKqpDirectWriteActor>, pu
557
567
EgressStats.Chunks ++;
558
568
EgressStats.Splits ++;
559
569
EgressStats.Resume ();
570
+
571
+ if (auto it = SendTime.find (shardId); it != std::end (SendTime)) {
572
+ Counters->WriteActorWritesLatencyHistogram ->Collect ((TInstant::Now () - it->second ).MilliSeconds ());
573
+ SendTime.erase (it);
574
+ }
560
575
}
561
576
resumeNotificator.CheckMemory ();
562
577
}
@@ -594,7 +609,6 @@ class TKqpDirectWriteActor : public TActorBootstrapped<TKqpDirectWriteActor>, pu
594
609
NYql::NDqProto::StatusIds::UNAVAILABLE);
595
610
return ;
596
611
}
597
-
598
612
auto evWrite = std::make_unique<NKikimr::NEvents::TDataEvents::TEvWrite>(
599
613
NKikimrDataEvents::TEvWrite::MODE_IMMEDIATE);
600
614
@@ -628,6 +642,16 @@ class TKqpDirectWriteActor : public TActorBootstrapped<TKqpDirectWriteActor>, pu
628
642
ShardedWriteController->GetDataFormat ());
629
643
}
630
644
645
+ if (metadata->SendAttempts == 0 ) {
646
+ Counters->WriteActorImmediateWrites ->Inc ();
647
+ Counters->WriteActorWritesSizeHistogram ->Collect (serializationResult.TotalDataSize );
648
+ Counters->WriteActorWritesOperationsHistogram ->Collect (metadata->OperationsCount );
649
+
650
+ SendTime[shardId] = TInstant::Now ();
651
+ } else {
652
+ Counters->WriteActorImmediateWritesRetries ->Inc ();
653
+ }
654
+
631
655
CA_LOG_D (" Send EvWrite to ShardID=" << shardId << " , TxId=" << evWrite->Record .GetTxId ()
632
656
<< " , TxMode=" << evWrite->Record .GetTxMode ()
633
657
<< " , LockTxId=" << evWrite->Record .GetLockTxId () << " , LockNodeId=" << evWrite->Record .GetLockNodeId ()
@@ -723,6 +747,13 @@ class TKqpDirectWriteActor : public TActorBootstrapped<TKqpDirectWriteActor>, pu
723
747
NYql::TIssues issues;
724
748
issues.AddIssue (std::move (issue));
725
749
750
+ if (WriteActorStateSpan) {
751
+ WriteActorStateSpan.EndError (issues.ToOneLineString ());
752
+ }
753
+ if (WriteActorSpan) {
754
+ WriteActorSpan.EndError (issues.ToOneLineString ());
755
+ }
756
+
726
757
Callbacks->OnAsyncOutputError (OutputIndex, std::move (issues), statusCode);
727
758
}
728
759
@@ -732,6 +763,8 @@ class TKqpDirectWriteActor : public TActorBootstrapped<TKqpDirectWriteActor>, pu
732
763
}
733
764
734
765
void Prepare () {
766
+ WriteActorStateSpan.EndOk ();
767
+
735
768
YQL_ENSURE (SchemeEntry);
736
769
ResolveAttempts = 0 ;
737
770
@@ -803,12 +836,16 @@ class TKqpDirectWriteActor : public TActorBootstrapped<TKqpDirectWriteActor>, pu
803
836
std::optional<NSchemeCache::TSchemeCacheRequest::TEntry> SchemeRequest;
804
837
ui64 ResolveAttempts = 0 ;
805
838
839
+ THashMap<ui64, TInstant> SendTime;
806
840
THashMap<ui64, TLockInfo> LocksInfo;
807
841
bool Finished = false ;
808
842
809
843
const i64 MemoryLimit;
810
844
811
845
IShardedWriteControllerPtr ShardedWriteController = nullptr ;
846
+
847
+ NWilson::TSpan WriteActorSpan;
848
+ NWilson::TSpan WriteActorStateSpan;
812
849
};
813
850
814
851
void RegisterKqpWriteActor (NYql::NDq::TDqAsyncIoFactory& factory, TIntrusivePtr<TKqpCounters> counters) {
0 commit comments