Skip to content

Commit 12c70a0

Browse files
committed
datashard: add setting for backup table stats report interval
1 parent ce2b0c3 commit 12c70a0

File tree

5 files changed

+54
-3
lines changed

5 files changed

+54
-3
lines changed

ydb/core/protos/datashard_config.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ message TDataShardConfig {
2727
optional uint64 IncrementalRestoreReadAheadHi = 21 [default = 1048576];
2828
optional uint64 InMemoryStateMigrationTimeoutMs = 24 [default = 1000];
2929
optional uint32 StatsReportIntervalSeconds = 25 [default = 10];
30+
optional uint32 BackupTableStatsReportIntervalSeconds = 26 [default = 30];
3031
}

ydb/core/tx/datashard/datashard__stats.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,14 @@ class TDataShard::TTxInitiateStatsUpdate : public NTabletFlatExecutor::TTransact
579579
};
580580

581581
TDuration TDataShard::GetStatsReportInterval(const TAppData& appData) const {
582+
const auto& userTables = GetUserTables();
583+
const bool isBackup = !userTables.empty() && std::all_of(userTables.begin(), userTables.end(),
584+
[](const auto& kv) { return kv.second->IsBackup; });
585+
582586
return TDuration::Seconds(
583-
appData.DataShardConfig.GetStatsReportIntervalSeconds());
587+
isBackup
588+
? appData.DataShardConfig.GetBackupTableStatsReportIntervalSeconds()
589+
: appData.DataShardConfig.GetStatsReportIntervalSeconds());
584590
}
585591

586592
void TDataShard::UpdateTableStats(const TActorContext &ctx) {

ydb/core/tx/datashard/datashard_ut_stats.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,47 @@ Y_UNIT_TEST_SUITE(DataShardStats) {
834834
WaitTableStats(runtime, shard1, DoesNotHaveSchemaChangesCondition());
835835
}
836836

837+
Y_UNIT_TEST(BackupTableStatsReportInterval) {
838+
TPortManager pm;
839+
TServerSettings serverSettings(pm.GetPort(2134));
840+
serverSettings.SetDomainName("Root")
841+
.SetUseRealThreads(false);
842+
843+
TServer::TPtr server = new TServer(serverSettings);
844+
auto& runtime = *server->GetRuntime();
845+
auto sender = runtime.AllocateEdgeActor();
846+
847+
runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE);
848+
849+
InitRoot(server, sender);
850+
851+
auto [shards, tableId1] = CreateShardedTable(server, sender, "/Root", "table-1", 1);
852+
853+
// Create a backup copy table
854+
{
855+
auto senderCopy = runtime.AllocateEdgeActor();
856+
ui64 txId = AsyncCreateCopyTable(
857+
server, senderCopy, "/Root", "table-2", "/Root/table-1", /*isBackup=*/true);
858+
WaitTxNotification(server, senderCopy, txId);
859+
}
860+
auto tableId2 = ResolveTableId(server, sender, "/Root/table-2");
861+
862+
std::unordered_map<TLocalPathId, size_t> tableToStatsCount;
863+
auto observerFunc = [&](auto& ev) {
864+
const NKikimrTxDataShard::TEvPeriodicTableStats& record = ev->Get()->Record;
865+
++tableToStatsCount[record.GetTableLocalId()];
866+
};
867+
auto observer = runtime.AddObserver<TEvDataShard::TEvPeriodicTableStats>(observerFunc);
868+
869+
runtime.WaitFor("First stats event", [&]{ return !tableToStatsCount.empty(); });
870+
runtime.SimulateSleep(TDuration::Seconds(45));
871+
// Once every 10 seconds
872+
UNIT_ASSERT_GE(tableToStatsCount[tableId1.PathId.LocalPathId], 4);
873+
UNIT_ASSERT_LE(tableToStatsCount[tableId1.PathId.LocalPathId], 5);
874+
// Once every 30 seconds
875+
UNIT_ASSERT_GE(tableToStatsCount[tableId2.PathId.LocalPathId], 1);
876+
UNIT_ASSERT_LE(tableToStatsCount[tableId2.PathId.LocalPathId], 2);
877+
}
837878
}
838879

839880
}

ydb/core/tx/datashard/ut_common/datashard_ut_common.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,12 +1319,14 @@ ui64 AsyncCreateCopyTable(
13191319
TActorId sender,
13201320
const TString &root,
13211321
const TString &name,
1322-
const TString &from)
1322+
const TString &from,
1323+
bool isBackup)
13231324
{
13241325
auto request = SchemeTxTemplate(NKikimrSchemeOp::ESchemeOpCreateTable, root);
13251326
auto& desc = *request->Record.MutableTransaction()->MutableModifyScheme()->MutableCreateTable();
13261327
desc.SetName(name);
13271328
desc.SetCopyFromTable(from);
1329+
desc.SetIsBackup(isBackup);
13281330

13291331
return RunSchemeTx(*server->GetRuntime(), std::move(request), sender);
13301332
}

ydb/core/tx/datashard/ut_common/datashard_ut_common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,8 @@ ui64 AsyncCreateCopyTable(Tests::TServer::TPtr server,
531531
TActorId sender,
532532
const TString &root,
533533
const TString &name,
534-
const TString &from);
534+
const TString &from,
535+
bool isBackup = false);
535536

536537
NKikimrTxDataShard::TEvCompactTableResult CompactTable(
537538
TTestActorRuntime& runtime, ui64 shardId, const TTableId& tableId, bool compactBorrowed = false);

0 commit comments

Comments
 (0)