@@ -396,15 +396,26 @@ size_t TStatisticsAggregator::PropagatePart(const std::vector<TNodeId>& nodeIds,
396
396
}
397
397
398
398
void TStatisticsAggregator::Handle (TEvPipeCache::TEvDeliveryProblem::TPtr& ev) {
399
- auto tabletId = ev->Get ()->TabletId ;
400
- if (ShardRanges.empty ()) {
399
+ if (!ScanTableId.PathId ) {
401
400
return ;
402
401
}
403
- auto & range = ShardRanges.front ();
404
- if (tabletId != range.DataShardId ) {
405
- return ;
402
+ auto tabletId = ev->Get ()->TabletId ;
403
+ if (IsColumnTable) {
404
+ if (tabletId == HiveId) {
405
+ Schedule (HiveRetryInterval, new TEvPrivate::TEvRequestDistribution);
406
+ } else {
407
+ SA_LOG_CRIT (" [" << TabletID () << " ] TEvDeliveryProblem with unexpected tablet " << tabletId);
408
+ }
409
+ } else {
410
+ if (ShardRanges.empty ()) {
411
+ return ;
412
+ }
413
+ auto & range = ShardRanges.front ();
414
+ if (tabletId != range.DataShardId ) {
415
+ return ;
416
+ }
417
+ Resolve ();
406
418
}
407
- Resolve ();
408
419
}
409
420
410
421
void TStatisticsAggregator::Handle (TEvStatistics::TEvStatTableCreationResponse::TPtr&) {
@@ -439,6 +450,30 @@ void TStatisticsAggregator::Handle(TEvStatistics::TEvGetScanStatus::TPtr& ev) {
439
450
Send (ev->Sender , response.release (), 0 , ev->Cookie );
440
451
}
441
452
453
+ void TStatisticsAggregator::Handle (TEvPrivate::TEvResolve::TPtr&) {
454
+ Resolve ();
455
+ }
456
+
457
+ void TStatisticsAggregator::Handle (TEvPrivate::TEvRequestDistribution::TPtr&) {
458
+ ++HiveRequestRound;
459
+
460
+ auto reqDistribution = std::make_unique<TEvHive::TEvRequestTabletDistribution>();
461
+ reqDistribution->Record .MutableTabletIds ()->Reserve (TabletsForReqDistribution.size ());
462
+ for (auto & tablet : TabletsForReqDistribution) {
463
+ reqDistribution->Record .AddTabletIds (tablet);
464
+ }
465
+
466
+ Send (MakePipePerNodeCacheID (false ),
467
+ new TEvPipeCache::TEvForward (reqDistribution.release (), HiveId, true ));
468
+ }
469
+
470
+ void TStatisticsAggregator::Handle (TEvStatistics::TEvAggregateKeepAlive::TPtr& ev) {
471
+ auto ack = std::make_unique<TEvStatistics::TEvAggregateKeepAliveAck>();
472
+ ack->Record .SetRound (ev->Get ()->Record .GetRound ());
473
+ Send (ev->Sender , ack.release ());
474
+ Schedule (KeepAliveTimeout, new TEvPrivate::TEvAckTimeout (++KeepAliveSeqNo));
475
+ }
476
+
442
477
void TStatisticsAggregator::InitializeStatisticsTable () {
443
478
if (!EnableColumnStatistics) {
444
479
return ;
@@ -460,6 +495,8 @@ void TStatisticsAggregator::Navigate() {
460
495
}
461
496
462
497
void TStatisticsAggregator::Resolve () {
498
+ ++ResolveRound;
499
+
463
500
TVector<TCell> plusInf;
464
501
TTableRange range (StartKey.GetCells (), true , plusInf, true , false );
465
502
auto keyDesc = MakeHolder<TKeyDesc>(
@@ -500,6 +537,9 @@ void TStatisticsAggregator::SaveStatisticsToTable() {
500
537
std::vector<ui32> columnTags;
501
538
std::vector<TString> data;
502
539
auto count = CountMinSketches.size ();
540
+ if (count == 0 ) {
541
+ return ;
542
+ }
503
543
columnTags.reserve (count);
504
544
data.reserve (count);
505
545
@@ -533,28 +573,44 @@ void TStatisticsAggregator::ScheduleNextScan(NIceDb::TNiceDb& db) {
533
573
auto * operation = ScanOperations.Front ();
534
574
ReplyToActorIds.swap (operation->ReplyToActorIds );
535
575
536
- StartScan (db, operation->PathId );
537
-
576
+ bool doStartScan = true ;
577
+ bool isColumnTable = false ;
578
+ auto pathId = operation->PathId ;
579
+ auto itPath = ScanTables.find (pathId);
580
+ if (itPath != ScanTables.end ()) {
581
+ isColumnTable = itPath->second .IsColumnTable ;
582
+ } else {
583
+ doStartScan = false ;
584
+ }
585
+ if (doStartScan) {
586
+ StartScan (db, pathId, isColumnTable);
587
+ }
538
588
db.Table <Schema::ScanOperations>().Key (operation->OperationId ).Delete ();
539
589
ScanOperations.PopFront ();
540
- ScanOperationsByPathId.erase (operation-> PathId );
590
+ ScanOperationsByPathId.erase (pathId );
541
591
return ;
542
592
}
543
593
if (ScanTablesByTime.Empty ()) {
544
594
return ;
545
595
}
546
596
auto * topTable = ScanTablesByTime.Top ();
547
- auto now = TInstant::Now ();
548
- auto updateTime = topTable->LastUpdateTime ;
549
- if (now - updateTime < ScanIntervalTime) {
597
+ if (TInstant::Now () < topTable->LastUpdateTime + ScanIntervalTime) {
598
+ return ;
599
+ }
600
+ bool isColumnTable = false ;
601
+ auto itPath = ScanTables.find (topTable->PathId );
602
+ if (itPath != ScanTables.end ()) {
603
+ isColumnTable = itPath->second .IsColumnTable ;
604
+ } else {
550
605
return ;
551
606
}
552
- StartScan (db, topTable->PathId );
607
+ StartScan (db, topTable->PathId , isColumnTable );
553
608
}
554
609
555
- void TStatisticsAggregator::StartScan (NIceDb::TNiceDb& db, TPathId pathId) {
610
+ void TStatisticsAggregator::StartScan (NIceDb::TNiceDb& db, TPathId pathId, bool isColumnTable ) {
556
611
ScanTableId.PathId = pathId;
557
612
ScanStartTime = TInstant::Now ();
613
+ IsColumnTable = isColumnTable;
558
614
PersistCurrentScan (db);
559
615
560
616
StartKey = TSerializedCellVec ();
@@ -590,6 +646,7 @@ void TStatisticsAggregator::PersistCurrentScan(NIceDb::TNiceDb& db) {
590
646
PersistSysParam (db, Schema::SysParam_ScanTableOwnerId, ToString (ScanTableId.PathId .OwnerId ));
591
647
PersistSysParam (db, Schema::SysParam_ScanTableLocalPathId, ToString (ScanTableId.PathId .LocalPathId ));
592
648
PersistSysParam (db, Schema::SysParam_ScanStartTime, ToString (ScanStartTime.MicroSeconds ()));
649
+ PersistSysParam (db, Schema::SysParam_IsColumnTable, ToString (IsColumnTable));
593
650
}
594
651
595
652
void TStatisticsAggregator::PersistStartKey (NIceDb::TNiceDb& db) {
@@ -600,6 +657,10 @@ void TStatisticsAggregator::PersistLastScanOperationId(NIceDb::TNiceDb& db) {
600
657
PersistSysParam (db, Schema::SysParam_LastScanOperationId, ToString (LastScanOperationId));
601
658
}
602
659
660
+ void TStatisticsAggregator::PersistGlobalTraversalRound (NIceDb::TNiceDb& db) {
661
+ PersistSysParam (db, Schema::SysParam_GlobalTraversalRound, ToString (GlobalTraversalRound));
662
+ }
663
+
603
664
void TStatisticsAggregator::ResetScanState (NIceDb::TNiceDb& db) {
604
665
ScanTableId.PathId = TPathId ();
605
666
ScanStartTime = TInstant::MicroSeconds (0 );
@@ -620,6 +681,12 @@ void TStatisticsAggregator::ResetScanState(NIceDb::TNiceDb& db) {
620
681
KeyColumnTypes.clear ();
621
682
Columns.clear ();
622
683
ColumnNames.clear ();
684
+
685
+ TabletsForReqDistribution.clear ();
686
+
687
+ ResolveRound = 0 ;
688
+ HiveRequestRound = 0 ;
689
+ TraversalRound = 0 ;
623
690
}
624
691
625
692
template <typename T, typename S>
0 commit comments