@@ -407,6 +407,10 @@ void TStatisticsAggregator::Handle(TEvStatistics::TEvStatTableCreationResponse::
407407 PendingSaveStatistics = false ;
408408 SaveStatisticsToTable ();
409409 }
410+ if (PendingDeleteStatistics) {
411+ PendingDeleteStatistics = false ;
412+ DeleteStatisticsFromTable ();
413+ }
410414}
411415
412416void TStatisticsAggregator::Initialize () {
@@ -484,6 +488,17 @@ void TStatisticsAggregator::SaveStatisticsToTable() {
484488 std::move (columnNames), std::move (data)));
485489}
486490
491+ void TStatisticsAggregator::DeleteStatisticsFromTable () {
492+ if (!IsStatisticsTableCreated) {
493+ PendingDeleteStatistics = true ;
494+ return ;
495+ }
496+
497+ PendingDeleteStatistics = false ;
498+
499+ Register (CreateDeleteStatisticsQuery (ScanTableId.PathId ));
500+ }
501+
487502void TStatisticsAggregator::ScheduleNextScan () {
488503 while (!ScanTablesByTime.empty ()) {
489504 auto & topTable = ScanTablesByTime.top ();
@@ -539,6 +554,38 @@ void TStatisticsAggregator::ResetScanState(NIceDb::TNiceDb& db) {
539554 ColumnNames.clear ();
540555}
541556
557+ void TStatisticsAggregator::RescheduleScanTable (NIceDb::TNiceDb& db) {
558+ if (ScanTablesByTime.empty ()) {
559+ return ;
560+ }
561+ auto & topTable = ScanTablesByTime.top ();
562+ auto pathId = topTable.PathId ;
563+ if (pathId == ScanTableId.PathId ) {
564+ TScanTable scanTable;
565+ scanTable.PathId = pathId;
566+ scanTable.SchemeShardId = topTable.SchemeShardId ;
567+ scanTable.LastUpdateTime = ScanStartTime;
568+
569+ ScanTablesByTime.pop ();
570+ ScanTablesByTime.push (scanTable);
571+
572+ db.Table <Schema::ScanTables>().Key (pathId.OwnerId , pathId.LocalPathId ).Update (
573+ NIceDb::TUpdate<Schema::ScanTables::LastUpdateTime>(ScanStartTime.MicroSeconds ()));
574+ }
575+ }
576+
577+ void TStatisticsAggregator::DropScanTable (NIceDb::TNiceDb& db) {
578+ if (ScanTablesByTime.empty ()) {
579+ return ;
580+ }
581+ auto & topTable = ScanTablesByTime.top ();
582+ auto pathId = topTable.PathId ;
583+ if (pathId == ScanTableId.PathId ) {
584+ ScanTablesByTime.pop ();
585+ db.Table <Schema::ScanTables>().Key (pathId.OwnerId , pathId.LocalPathId ).Delete ();
586+ }
587+ }
588+
542589template <typename T, typename S>
543590void PrintContainerStart (const T& container, size_t count, TStringStream& str,
544591 std::function<S(const typename T::value_type&)> extractor)
0 commit comments