Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions ydb/core/client/flat_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2950,7 +2950,8 @@ Y_UNIT_TEST_SUITE(TFlatTest) {
UNIT_ASSERT_VALUES_EQUAL(partitions.size(), 1);

// Force stats reporting without delays
NDataShard::gDbStatsReportInterval = TDuration::Seconds(0);
cleverServer.GetRuntime()->GetAppData()
.DataShardConfig.SetStatsReportIntervalSeconds(0);

cleverServer.GetRuntime()->SetLogPriority(NKikimrServices::FLAT_TX_SCHEMESHARD, NActors::NLog::PRI_DEBUG);
// cleverServer.GetRuntime()->SetLogPriority(NKikimrServices::TABLET_EXECUTOR, NActors::NLog::PRI_DEBUG);
Expand Down Expand Up @@ -3123,7 +3124,8 @@ Y_UNIT_TEST_SUITE(TFlatTest) {
UNIT_ASSERT_VALUES_EQUAL(partitions.size(), 4);

// Force stats reporting without delays
NDataShard::gDbStatsReportInterval = TDuration::Seconds(0);
cleverServer.GetRuntime()->GetAppData()
.DataShardConfig.SetStatsReportIntervalSeconds(0);

cleverServer.GetRuntime()->SetLogPriority(NKikimrServices::FLAT_TX_SCHEMESHARD, NActors::NLog::PRI_DEBUG);
// cleverServer.GetRuntime()->SetLogPriority(NKikimrServices::TABLET_EXECUTOR, NActors::NLog::PRI_DEBUG);
Expand Down Expand Up @@ -3229,7 +3231,8 @@ Y_UNIT_TEST_SUITE(TFlatTest) {
TVector<ui64> initialPartitions = annoyingClient.GetTablePartitions("/dc-1/Dir/T1");

// Force stats reporting without delays
NDataShard::gDbStatsReportInterval = TDuration::Seconds(0);
cleverServer.GetRuntime()->GetAppData()
.DataShardConfig.SetStatsReportIntervalSeconds(0);
NDataShard::gDbStatsDataSizeResolution = 80000;

TString bigValue(100*1024, '0');
Expand Down
2 changes: 2 additions & 0 deletions ydb/core/protos/datashard_config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ message TDataShardConfig {
optional string CdcInitialScanTaskName = 17 [default = "cdc_initial_scan"];
optional uint32 CdcInitialScanTaskPriority = 18 [default = 10];
optional bool DisabledOnSchemeShard = 19 [default = false];
optional uint32 StatsReportIntervalSeconds = 25 [default = 10];
optional uint32 BackupTableStatsReportIntervalSeconds = 26 [default = 30];
}
10 changes: 9 additions & 1 deletion ydb/core/sys_view/ut_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ NKikimrSubDomains::TSubDomainSettings GetSubDomainDefaultSettings(const TString
return subdomain;
}

TTestEnv::TTestEnv(ui32 staticNodes, ui32 dynamicNodes, ui32 storagePools, ui32 pqTabletsN, bool enableSVP, bool disableSources) {
TTestEnv::TTestEnv(
ui32 staticNodes, ui32 dynamicNodes, ui32 storagePools,
ui32 pqTabletsN, bool enableSVP, bool disableSources,
std::optional<ui32> dataShardStatsReportIntervalSeconds) {
auto mbusPort = PortManager.GetPort();
auto grpcPort = PortManager.GetPort();

Expand Down Expand Up @@ -56,6 +59,11 @@ TTestEnv::TTestEnv(ui32 staticNodes, ui32 dynamicNodes, ui32 storagePools, ui32
Settings->AppConfig->MutableTableServiceConfig()->SetEnableKqpDataQuerySourceRead(!disableSources);
Settings->AppConfig->MutableHiveConfig()->AddBalancerIgnoreTabletTypes(NKikimrTabletBase::TTabletTypes::SysViewProcessor);

if (dataShardStatsReportIntervalSeconds) {
Settings->AppConfig->MutableDataShardConfig()
->SetStatsReportIntervalSeconds(*dataShardStatsReportIntervalSeconds);
}

Server = new Tests::TServer(*Settings);
Server->EnableGRpc(grpcPort);

Expand Down
3 changes: 2 additions & 1 deletion ydb/core/sys_view/ut_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class TTestEnv {

public:
TTestEnv(ui32 staticNodes = 1, ui32 dynamicNodes = 4, ui32 storagePools = 0,
ui32 pqTabletsN = 0, bool enableSVP = false, bool disableSources = false);
ui32 pqTabletsN = 0, bool enableSVP = false, bool disableSources = false,
std::optional<ui32> dataShardStatsReportIntervalSeconds = std::nullopt);

template<typename... Args>
TTestEnv(TDisableSourcesTag, Args&&... args)
Expand Down
16 changes: 4 additions & 12 deletions ydb/core/sys_view/ut_kqp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,11 +717,9 @@ Y_UNIT_TEST_SUITE(SystemView) {
}

Y_UNIT_TEST(PartitionStatsFields) {
NDataShard::gDbStatsReportInterval = TDuration::Seconds(0);

auto nowUs = TInstant::Now().MicroSeconds();

TTestEnv env;
TTestEnv env(1, 4, 0, 0, false, false, 0);
CreateRootTable(env);

TTableClient client(env.GetDriver());
Expand Down Expand Up @@ -1210,11 +1208,9 @@ Y_UNIT_TEST_SUITE(SystemView) {
}

Y_UNIT_TEST(TopPartitionsFields) {
NDataShard::gDbStatsReportInterval = TDuration::Seconds(0);

auto nowUs = TInstant::Now().MicroSeconds();

TTestEnv env(1, 4, 0, 0, true);
TTestEnv env(1, 4, 0, 0, true, false, 0);
CreateTenantsAndTables(env);

TTableClient client(env.GetDriver());
Expand Down Expand Up @@ -1262,11 +1258,9 @@ Y_UNIT_TEST_SUITE(SystemView) {
}

Y_UNIT_TEST(TopPartitionsTables) {
NDataShard::gDbStatsReportInterval = TDuration::Seconds(0);

constexpr ui64 partitionCount = 5;

TTestEnv env(1, 4, 0, 0, true);
TTestEnv env(1, 4, 0, 0, true, false, 0);
CreateTenantsAndTables(env, true, partitionCount);

TTableClient client(env.GetDriver());
Expand All @@ -1292,11 +1286,9 @@ Y_UNIT_TEST_SUITE(SystemView) {
}

Y_UNIT_TEST(TopPartitionsRanges) {
NDataShard::gDbStatsReportInterval = TDuration::Seconds(0);

constexpr ui64 partitionCount = 5;

TTestEnv env(1, 4, 0, 0, true);
TTestEnv env(1, 4, 0, 0, true, false, 0);
CreateTenantsAndTables(env, true, partitionCount);

TTableClient client(env.GetDriver());
Expand Down
1 change: 1 addition & 0 deletions ydb/core/testlib/test_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ namespace Tests {
appData.DataStreamsAuthFactory = Settings->DataStreamsAuthFactory.get();
appData.PersQueueMirrorReaderFactory = Settings->PersQueueMirrorReaderFactory.get();
appData.HiveConfig.MergeFrom(Settings->AppConfig->GetHiveConfig());
appData.DataShardConfig.MergeFrom(Settings->AppConfig->GetDataShardConfig());
appData.GraphConfig.MergeFrom(Settings->AppConfig->GetGraphConfig());
appData.SqsConfig.MergeFrom(Settings->AppConfig->GetSqsConfig());

Expand Down
1 change: 0 additions & 1 deletion ydb/core/tx/datashard/datashard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ using namespace NTabletFlatExecutor;
// But in unit tests we want to test both scenarios
bool gAllowLogBatchingDefaultValue = true;

TDuration gDbStatsReportInterval = TDuration::Seconds(10);
ui64 gDbStatsDataSizeResolution = 10*1024*1024;
ui64 gDbStatsRowCountResolution = 100000;
ui32 gDbStatsHistogramBucketsCount = 10;
Expand Down
1 change: 0 additions & 1 deletion ydb/core/tx/datashard/datashard.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ namespace NDataShard {

// NOTE: this switch should be modified only in tests !!!
extern bool gAllowLogBatchingDefaultValue;
extern TDuration gDbStatsReportInterval;
extern ui64 gDbStatsDataSizeResolution;
extern ui64 gDbStatsRowCountResolution;
extern ui32 gDbStatsHistogramBucketsCount;
Expand Down
22 changes: 20 additions & 2 deletions ydb/core/tx/datashard/datashard__stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,13 +597,31 @@ class TDataShard::TTxInitiateStatsUpdate : public NTabletFlatExecutor::TTransact
}
};

TDuration TDataShard::GetStatsReportInterval(const TAppData& appData) const {
const auto& userTables = GetUserTables();
const bool isBackup = !userTables.empty() && std::all_of(userTables.begin(), userTables.end(),
[](const auto& kv) { return kv.second->IsBackup; });

if (isBackup) {
// Clamp the interval for backup tables to the value for ordinary tables, as it
// makes no sense for the latter to be longer than the former.
auto interval = std::max(
appData.DataShardConfig.GetBackupTableStatsReportIntervalSeconds(),
appData.DataShardConfig.GetStatsReportIntervalSeconds());
return TDuration::Seconds(interval);
} else {
return TDuration::Seconds(appData.DataShardConfig.GetStatsReportIntervalSeconds());
}
}

void TDataShard::UpdateTableStats(const TActorContext &ctx) {
if (StatisticsDisabled)
return;

TInstant now = AppData(ctx)->TimeProvider->Now();
auto* appData = AppData(ctx);
TInstant now = appData->TimeProvider->Now();

if (LastDbStatsUpdateTime + gDbStatsReportInterval > now)
if (LastDbStatsUpdateTime + GetStatsReportInterval(*appData) > now)
return;

if (State != TShardState::Ready)
Expand Down
7 changes: 5 additions & 2 deletions ydb/core/tx/datashard/datashard_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3209,13 +3209,16 @@ class TDataShard
NTabletPipe::SendData(ctx, StateReportPipe, ev.Release());
}

TDuration GetStatsReportInterval(const TAppData&) const;

void SendPeriodicTableStats(const TActorContext &ctx) {
if (StatisticsDisabled)
return;

TInstant now = AppData(ctx)->TimeProvider->Now();
auto* appData = AppData(ctx);
TInstant now = appData->TimeProvider->Now();

if (LastDbStatsReportTime + gDbStatsReportInterval > now)
if (LastDbStatsReportTime + GetStatsReportInterval(*appData) > now)
return;

auto* resourceMetrics = Executor()->GetResourceMetrics();
Expand Down
45 changes: 43 additions & 2 deletions ydb/core/tx/datashard/datashard_ut_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ Y_UNIT_TEST_SUITE(DataShardStats) {
TServerSettings serverSettings(pm.GetPort(2134));
serverSettings.SetDomainName("Root")
.SetUseRealThreads(false);
serverSettings.AppConfig->MutableDataShardConfig()
->SetStatsReportIntervalSeconds(0);

TServer::TPtr server = new TServer(serverSettings);
auto& runtime = *server->GetRuntime();
Expand All @@ -399,8 +401,6 @@ Y_UNIT_TEST_SUITE(DataShardStats) {

InitRoot(server, sender);

NDataShard::gDbStatsReportInterval = TDuration::Seconds(0);

NLocalDb::TCompactionPolicyPtr policy = NLocalDb::CreateDefaultUserTablePolicy();
policy->InMemForceStepsToSnapshot = 1;

Expand Down Expand Up @@ -696,6 +696,47 @@ Y_UNIT_TEST_SUITE(DataShardStats) {
WaitTableStats(runtime, shard1, DoesNotHaveSchemaChangesCondition());
}

Y_UNIT_TEST(BackupTableStatsReportInterval) {
TPortManager pm;
TServerSettings serverSettings(pm.GetPort(2134));
serverSettings.SetDomainName("Root")
.SetUseRealThreads(false);

TServer::TPtr server = new TServer(serverSettings);
auto& runtime = *server->GetRuntime();
auto sender = runtime.AllocateEdgeActor();

runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE);

InitRoot(server, sender);

auto [shards, tableId1] = CreateShardedTable(server, sender, "/Root", "table-1", 1);

// Create a backup copy table
{
auto senderCopy = runtime.AllocateEdgeActor();
ui64 txId = AsyncCreateCopyTable(
server, senderCopy, "/Root", "table-2", "/Root/table-1", /*isBackup=*/true);
WaitTxNotification(server, senderCopy, txId);
}
auto tableId2 = ResolveTableId(server, sender, "/Root/table-2");

std::unordered_map<TLocalPathId, size_t> tableToStatsCount;
auto observerFunc = [&](auto& ev) {
const NKikimrTxDataShard::TEvPeriodicTableStats& record = ev->Get()->Record;
++tableToStatsCount[record.GetTableLocalId()];
};
auto observer = runtime.AddObserver<TEvDataShard::TEvPeriodicTableStats>(observerFunc);

runtime.WaitFor("First stats event", [&]{ return !tableToStatsCount.empty(); });
runtime.SimulateSleep(TDuration::Seconds(45));
// Once every 10 seconds
UNIT_ASSERT_GE(tableToStatsCount[tableId1.PathId.LocalPathId], 4);
UNIT_ASSERT_LE(tableToStatsCount[tableId1.PathId.LocalPathId], 5);
// Once every 30 seconds
UNIT_ASSERT_GE(tableToStatsCount[tableId2.PathId.LocalPathId], 1);
UNIT_ASSERT_LE(tableToStatsCount[tableId2.PathId.LocalPathId], 2);
}
}

}
4 changes: 3 additions & 1 deletion ydb/core/tx/datashard/ut_common/datashard_ut_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1254,12 +1254,14 @@ ui64 AsyncCreateCopyTable(
TActorId sender,
const TString &root,
const TString &name,
const TString &from)
const TString &from,
bool isBackup)
{
auto request = SchemeTxTemplate(NKikimrSchemeOp::ESchemeOpCreateTable, root);
auto& desc = *request->Record.MutableTransaction()->MutableModifyScheme()->MutableCreateTable();
desc.SetName(name);
desc.SetCopyFromTable(from);
desc.SetIsBackup(isBackup);

return RunSchemeTx(*server->GetRuntime(), std::move(request), sender);
}
Expand Down
3 changes: 2 additions & 1 deletion ydb/core/tx/datashard/ut_common/datashard_ut_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,8 @@ ui64 AsyncCreateCopyTable(Tests::TServer::TPtr server,
TActorId sender,
const TString &root,
const TString &name,
const TString &from);
const TString &from,
bool isBackup = false);

NKikimrTxDataShard::TEvCompactTableResult CompactTable(
TTestActorRuntime& runtime, ui64 shardId, const TTableId& tableId, bool compactBorrowed = false);
Expand Down
2 changes: 1 addition & 1 deletion ydb/core/tx/schemeshard/ut_base/ut_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10568,12 +10568,12 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) {

TTestEnvOptions opts;
opts.EnableBackgroundCompaction(false);
opts.DataShardStatsReportIntervalSeconds(1);

TTestEnv env(runtime, opts);

ui64 txId = 100;

NDataShard::gDbStatsReportInterval = TDuration::Seconds(1);
NDataShard::gDbStatsDataSizeResolution = 10;
NDataShard::gDbStatsRowCountResolution = 10;

Expand Down
18 changes: 12 additions & 6 deletions ydb/core/tx/schemeshard/ut_compaction/ut_compaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,12 +768,14 @@ Y_UNIT_TEST_SUITE(TSchemeshardBorrowedCompactionTest) {
// 1. Copy table is not compacted until we want to split it
// 2. After borrow compaction both src and dst tables are background compacted

NDataShard::gDbStatsReportInterval = TDuration::Seconds(1);
NDataShard::gDbStatsDataSizeResolution = 10;
NDataShard::gDbStatsRowCountResolution = 10;

TTestEnvOptions opts;
opts.DataShardStatsReportIntervalSeconds(1);

TTestBasicRuntime runtime;
TTestEnv env(runtime);
TTestEnv env(runtime, opts);

runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_DEBUG);
runtime.SetLogPriority(NKikimrServices::FLAT_TX_SCHEMESHARD, NActors::NLog::PRI_TRACE);
Expand Down Expand Up @@ -899,12 +901,14 @@ Y_UNIT_TEST_SUITE(TSchemeshardBorrowedCompactionTest) {
// I.e. we compact borrowed data ASAP except copy table case, when
// we don't want to compact at all.

NDataShard::gDbStatsReportInterval = TDuration::Seconds(1);
NDataShard::gDbStatsDataSizeResolution = 10;
NDataShard::gDbStatsRowCountResolution = 10;

TTestEnvOptions opts;
opts.DataShardStatsReportIntervalSeconds(1);

TTestBasicRuntime runtime;
TTestEnv env(runtime);
TTestEnv env(runtime, opts);

runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_DEBUG);
runtime.SetLogPriority(NKikimrServices::FLAT_TX_SCHEMESHARD, NActors::NLog::PRI_TRACE);
Expand Down Expand Up @@ -973,12 +977,14 @@ Y_UNIT_TEST_SUITE(TSchemeshardBorrowedCompactionTest) {

Y_UNIT_TEST(SchemeshardShouldNotCompactBorrowedAfterSplitMergeWhenDisabled) {

NDataShard::gDbStatsReportInterval = TDuration::Seconds(1);
NDataShard::gDbStatsDataSizeResolution = 10;
NDataShard::gDbStatsRowCountResolution = 10;

TTestEnvOptions opts;
opts.DataShardStatsReportIntervalSeconds(1);

TTestBasicRuntime runtime;
TTestEnv env(runtime);
TTestEnv env(runtime, opts);

runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_DEBUG);
runtime.SetLogPriority(NKikimrServices::FLAT_TX_SCHEMESHARD, NActors::NLog::PRI_TRACE);
Expand Down
5 changes: 5 additions & 0 deletions ydb/core/tx/schemeshard/ut_helpers/test_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,11 @@ NSchemeShardUT_Private::TTestEnv::TTestEnv(TTestActorRuntime& runtime, const TTe
app.AddSystemBackupSID(sid);
}

if (opts.DataShardStatsReportIntervalSeconds_) {
app.DataShardConfig.SetStatsReportIntervalSeconds(
*opts.DataShardStatsReportIntervalSeconds_);
}

AddDomain(runtime, app, TTestTxConfig::DomainUid, hive, schemeRoot);

SetupLogging(runtime);
Expand Down
1 change: 1 addition & 0 deletions ydb/core/tx/schemeshard/ut_helpers/test_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace NSchemeShardUT_Private {
OPTION(std::optional<bool>, EnableChangefeedsOnIndexTables, std::nullopt);
OPTION(std::optional<bool>, EnableTieringInColumnShard, std::nullopt);
OPTION(std::optional<bool>, EnableParameterizedDecimal, std::nullopt);
OPTION(std::optional<ui32>, DataShardStatsReportIntervalSeconds, std::nullopt);

#undef OPTION
};
Expand Down
5 changes: 2 additions & 3 deletions ydb/core/tx/schemeshard/ut_index_build/ut_index_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
NLs::PathVersionEqual(3)});

// Force stats reporting without delays
NDataShard::gDbStatsReportInterval = TDuration::Seconds(0);
runtime.GetAppData().DataShardConfig.SetStatsReportIntervalSeconds(0);
NDataShard::gDbStatsDataSizeResolution = 80000;

auto upgradeEvent = [&](TAutoPtr<IEventHandle>& ev) -> auto {
Expand Down Expand Up @@ -768,10 +768,9 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
TTestEnvOptions opts;
opts.EnableBackgroundCompaction(false);
opts.DisableStatsBatching(true);
opts.DataShardStatsReportIntervalSeconds(0);
TTestEnv env(runtime, opts);

NDataShard::gDbStatsReportInterval = TDuration::Seconds(0);

ui64 txId = 100;

TestCreateTable(runtime, ++txId, "/MyRoot", R"(
Expand Down
Loading
Loading