@@ -46,7 +46,7 @@ void TColumnShard::SwitchToWork(const TActorContext& ctx) {
4646 EnqueueProgressTx (ctx);
4747 }
4848 EnqueueBackgroundActivities ();
49- ctx.Schedule (ActivationPeriod , new TEvPrivate::TEvPeriodicWakeup ());
49+ ctx.Send ( SelfId () , new TEvPrivate::TEvPeriodicWakeup ());
5050}
5151
5252void TColumnShard::OnActivateExecutor (const TActorContext& ctx) {
@@ -158,7 +158,7 @@ void TColumnShard::Handle(TEvPrivate::TEvPeriodicWakeup::TPtr& ev, const TActorC
158158 SendWaitPlanStep (GetOutdatedStep ());
159159
160160 SendPeriodicStats ();
161- ctx.Schedule (ActivationPeriod , new TEvPrivate::TEvPeriodicWakeup ());
161+ ctx.Schedule (PeriodicWakeupActivationPeriod , new TEvPrivate::TEvPeriodicWakeup ());
162162 }
163163}
164164
@@ -293,15 +293,106 @@ void TColumnShard::UpdateResourceMetrics(const TActorContext& ctx, const TUsage&
293293 metrics->TryUpdate (ctx);
294294}
295295
296+ void TColumnShard::ConfigureStats (const NOlap::TColumnEngineStats& indexStats, ::NKikimrTableStats::TTableStats * tabletStats) {
297+ NOlap::TSnapshot lastIndexUpdate = TablesManager.GetPrimaryIndexSafe ().LastUpdate ();
298+ auto activeIndexStats = indexStats.Active (); // data stats excluding inactive and evicted
299+
300+ if (activeIndexStats.Rows < 0 || activeIndexStats.Bytes < 0 ) {
301+ LOG_S_WARN (" Negative stats counter. Rows: " << activeIndexStats.Rows
302+ << " Bytes: " << activeIndexStats.Bytes << TabletID ());
303+
304+ activeIndexStats.Rows = (activeIndexStats.Rows < 0 ) ? 0 : activeIndexStats.Rows ;
305+ activeIndexStats.Bytes = (activeIndexStats.Bytes < 0 ) ? 0 : activeIndexStats.Bytes ;
306+ }
307+
308+ tabletStats->SetRowCount (activeIndexStats.Rows );
309+ tabletStats->SetDataSize (activeIndexStats.Bytes + TabletCounters->Simple ()[COUNTER_COMMITTED_BYTES].Get ());
310+
311+ // TODO: we need row/dataSize counters for evicted data (managed by tablet but stored outside)
312+ // tabletStats->SetIndexSize(); // TODO: calc size of internal tables
313+
314+ tabletStats->SetLastAccessTime (LastAccessTime.MilliSeconds ());
315+ tabletStats->SetLastUpdateTime (lastIndexUpdate.GetPlanStep ());
316+ }
317+
318+ TDuration TColumnShard::GetControllerPeriodicWakeupActivationPeriod () {
319+ return NYDBTest::TControllers::GetColumnShardController ()->GetPeriodicWakeupActivationPeriod (TSettings::DefaultPeriodicWakeupActivationPeriod);
320+ }
321+
322+ TDuration TColumnShard::GetControllerStatsReportInterval () {
323+ return NYDBTest::TControllers::GetColumnShardController ()->GetStatsReportInterval (TSettings::DefaultStatsReportInterval);
324+ }
325+
326+ void TColumnShard::FillTxTableStats (::NKikimrTableStats::TTableStats* tableStats) const {
327+ tableStats->SetTxRejectedByOverload (TabletCounters->Cumulative ()[COUNTER_WRITE_OVERLOAD].Get ());
328+ tableStats->SetTxRejectedBySpace (TabletCounters->Cumulative ()[COUNTER_OUT_OF_SPACE].Get ());
329+ tableStats->SetInFlightTxCount (Executor ()->GetStats ().TxInFly );
330+ }
331+
332+ void TColumnShard::FillOlapStats (const TActorContext& ctx, std::unique_ptr<TEvDataShard::TEvPeriodicTableStats>& ev) {
333+ ev->Record .SetShardState (2 ); // NKikimrTxDataShard.EDatashardState.Ready
334+ ev->Record .SetGeneration (Executor ()->Generation ());
335+ ev->Record .SetRound (StatsReportRound++);
336+ ev->Record .SetNodeId (ctx.ExecutorThread .ActorSystem ->NodeId );
337+ ev->Record .SetStartTime (StartTime ().MilliSeconds ());
338+ if (auto * resourceMetrics = Executor ()->GetResourceMetrics ()) {
339+ resourceMetrics->Fill (*ev->Record .MutableTabletMetrics ());
340+ }
341+ auto * tabletStats = ev->Record .MutableTableStats ();
342+ FillTxTableStats (tabletStats);
343+ if (TablesManager.HasPrimaryIndex ()) {
344+ const auto & indexStats = TablesManager.MutablePrimaryIndex ().GetTotalStats ();
345+ ConfigureStats (indexStats, tabletStats);
346+ }
347+ }
348+
349+ void TColumnShard::FillColumnTableStats (const TActorContext& ctx, std::unique_ptr<TEvDataShard::TEvPeriodicTableStats>& ev) {
350+ if (!TablesManager.HasPrimaryIndex ()) {
351+ return ;
352+ }
353+ const auto & tablesIndexStats = TablesManager.MutablePrimaryIndex ().GetStats ();
354+ LOG_S_DEBUG (" There are stats for " << tablesIndexStats.size () << " tables" );
355+ for (const auto & [tableLocalID, columnStats] : tablesIndexStats) {
356+ if (!columnStats) {
357+ LOG_S_ERROR (" SendPeriodicStats: empty stats" );
358+ continue ;
359+ }
360+
361+ auto * periodicTableStats = ev->Record .AddTables ();
362+ periodicTableStats->SetDatashardId (TabletID ());
363+ periodicTableStats->SetTableLocalId (tableLocalID);
364+
365+ periodicTableStats->SetShardState (2 ); // NKikimrTxDataShard.EDatashardState.Ready
366+ periodicTableStats->SetGeneration (Executor ()->Generation ());
367+ periodicTableStats->SetRound (StatsReportRound++);
368+ periodicTableStats->SetNodeId (ctx.ExecutorThread .ActorSystem ->NodeId );
369+ periodicTableStats->SetStartTime (StartTime ().MilliSeconds ());
370+
371+ if (auto * resourceMetrics = Executor ()->GetResourceMetrics ()) {
372+ resourceMetrics->Fill (*periodicTableStats->MutableTabletMetrics ());
373+ }
374+
375+ auto * tableStats = periodicTableStats->MutableTableStats ();
376+ FillTxTableStats (tableStats);
377+ ConfigureStats (*columnStats, tableStats);
378+
379+ LOG_S_TRACE (" Add stats for table, tableLocalID=" << tableLocalID);
380+ }
381+ }
382+
296383void TColumnShard::SendPeriodicStats () {
384+ LOG_S_DEBUG (" Send periodic stats." );
385+
297386 if (!CurrentSchemeShardId || !OwnerPathId) {
298387 LOG_S_DEBUG (" Disabled periodic stats at tablet " << TabletID ());
299388 return ;
300389 }
301390
302391 const TActorContext& ctx = ActorContext ();
303- TInstant now = TAppData::TimeProvider->Now ();
392+ const TInstant now = TAppData::TimeProvider->Now ();
393+
304394 if (LastStatsReport + StatsReportInterval > now) {
395+ LOG_S_TRACE (" Skip send periodic stats: report interavl = " << StatsReportInterval);
305396 return ;
306397 }
307398 LastStatsReport = now;
@@ -313,45 +404,10 @@ void TColumnShard::SendPeriodicStats() {
313404 }
314405
315406 auto ev = std::make_unique<TEvDataShard::TEvPeriodicTableStats>(TabletID (), OwnerPathId);
316- {
317- ev->Record .SetShardState (2 ); // NKikimrTxDataShard.EDatashardState.Ready
318- ev->Record .SetGeneration (Executor ()->Generation ());
319- ev->Record .SetRound (StatsReportRound++);
320- ev->Record .SetNodeId (ctx.ExecutorThread .ActorSystem ->NodeId );
321- ev->Record .SetStartTime (StartTime ().MilliSeconds ());
322-
323- if (auto * resourceMetrics = Executor ()->GetResourceMetrics ()) {
324- resourceMetrics->Fill (*ev->Record .MutableTabletMetrics ());
325- }
326407
327- auto * tabletStats = ev->Record .MutableTableStats ();
328- tabletStats->SetTxRejectedByOverload (TabletCounters->Cumulative ()[COUNTER_WRITE_OVERLOAD].Get ());
329- tabletStats->SetTxRejectedBySpace (TabletCounters->Cumulative ()[COUNTER_OUT_OF_SPACE].Get ());
330- tabletStats->SetInFlightTxCount (Executor ()->GetStats ().TxInFly );
331-
332- if (TablesManager.HasPrimaryIndex ()) {
333- const auto & indexStats = TablesManager.MutablePrimaryIndex ().GetTotalStats ();
334- NOlap::TSnapshot lastIndexUpdate = TablesManager.GetPrimaryIndexSafe ().LastUpdate ();
335- auto activeIndexStats = indexStats.Active (); // data stats excluding inactive and evicted
336-
337- if (activeIndexStats.Rows < 0 || activeIndexStats.Bytes < 0 ) {
338- LOG_S_WARN (" Negative stats counter. Rows: " << activeIndexStats.Rows
339- << " Bytes: " << activeIndexStats.Bytes << TabletID ());
340-
341- activeIndexStats.Rows = (activeIndexStats.Rows < 0 ) ? 0 : activeIndexStats.Rows ;
342- activeIndexStats.Bytes = (activeIndexStats.Bytes < 0 ) ? 0 : activeIndexStats.Bytes ;
343- }
344-
345- tabletStats->SetRowCount (activeIndexStats.Rows );
346- tabletStats->SetDataSize (activeIndexStats.Bytes + TabletCounters->Simple ()[COUNTER_COMMITTED_BYTES].Get ());
347- // TODO: we need row/dataSize counters for evicted data (managed by tablet but stored outside)
348- // tabletStats->SetIndexSize(); // TODO: calc size of internal tables
349- tabletStats->SetLastAccessTime (LastAccessTime.MilliSeconds ());
350- tabletStats->SetLastUpdateTime (lastIndexUpdate.GetPlanStep ());
351- }
352- }
353-
354- LOG_S_DEBUG (" Sending periodic stats at tablet " << TabletID ());
408+ FillOlapStats (ctx, ev);
409+ FillColumnTableStats (ctx, ev);
410+
355411 NTabletPipe::SendData (ctx, StatsReportPipe, ev.release ());
356412}
357413
0 commit comments