diff options
author | monster <monster@ydb.tech> | 2023-10-20 11:50:18 +0300 |
---|---|---|
committer | monster <monster@ydb.tech> | 2023-10-20 12:18:34 +0300 |
commit | 6033da49587212f1ea3e17981de0fc4e8cfa70b6 (patch) | |
tree | 0c8de08b8bc2ae7251265b9ef9509490e4d3d151 | |
parent | 529421651ffae182d6df0efd887099790b3931fc (diff) | |
download | ydb-6033da49587212f1ea3e17981de0fc4e8cfa70b6.tar.gz |
add EnableStatistics feature flag KIKIMR-18323
-rw-r--r-- | ydb/core/protos/config.proto | 1 | ||||
-rw-r--r-- | ydb/core/statistics/stat_service.cpp | 43 | ||||
-rw-r--r-- | ydb/core/statistics/ut/ut_common.cpp | 1 | ||||
-rw-r--r-- | ydb/core/tx/schemeshard/schemeshard_impl.cpp | 26 | ||||
-rw-r--r-- | ydb/core/tx/schemeshard/schemeshard_impl.h | 1 |
5 files changed, 61 insertions, 11 deletions
diff --git a/ydb/core/protos/config.proto b/ydb/core/protos/config.proto index 5f15c0dcdf8..9235b59ed99 100644 --- a/ydb/core/protos/config.proto +++ b/ydb/core/protos/config.proto @@ -843,6 +843,7 @@ message TFeatureFlags { optional bool SuppressCompatibilityCheck = 103 [default = false]; optional bool EnableUniqConstraint = 104 [default = false]; optional bool EnableChangefeedDebeziumJsonFormat = 105 [default = false]; + optional bool EnableStatistics = 106 [default = false]; } message THttpProxyConfig { diff --git a/ydb/core/statistics/stat_service.cpp b/ydb/core/statistics/stat_service.cpp index a5e4df2e928..c01c3b1132c 100644 --- a/ydb/core/statistics/stat_service.cpp +++ b/ydb/core/statistics/stat_service.cpp @@ -4,6 +4,8 @@ #include <ydb/library/services/services.pb.h> #include <ydb/core/tx/scheme_cache/scheme_cache.h> #include <ydb/core/base/tablet_pipecache.h> +#include <ydb/core/cms/console/configs_dispatcher.h> +#include <ydb/core/cms/console/console.h> #include <library/cpp/actors/core/actor_bootstrapped.h> #include <library/cpp/actors/core/hfunc.h> @@ -21,6 +23,12 @@ public: } void Bootstrap() { + EnableStatistics = AppData()->FeatureFlags.GetEnableStatistics(); + + ui32 configKind = (ui32) NKikimrConsole::TConfigItem::FeatureFlagsItem; + Send(NConsole::MakeConfigsDispatcherID(SelfId().NodeId()), + new NConsole::TEvConfigsDispatcher::TEvSetConfigSubscriptionRequest({configKind})); + Become(&TStatService::StateWork); } @@ -31,6 +39,8 @@ public: hFunc(TEvStatistics::TEvBroadcastStatistics, Handle); hFunc(TEvTabletPipe::TEvClientConnected, Handle); hFunc(TEvTabletPipe::TEvClientDestroyed, Handle); + hFunc(NConsole::TEvConfigsDispatcher::TEvSetConfigSubscriptionResponse, HandleConfig) + hFunc(NConsole::TEvConsole::TEvConfigNotificationRequest, HandleConfig) cFunc(TEvents::TEvPoison::EventType, PassAway); default: LOG_CRIT_S(TlsActivationContext->AsActorContext(), NKikimrServices::STATISTICS, @@ -47,6 +57,11 @@ private: request.EvCookie = ev->Cookie; request.StatRequests.swap(ev->Get()->StatRequests); + if (!EnableStatistics) { + ReplyFailed(requestId); + return; + } + using TNavigate = NSchemeCache::TSchemeCacheNavigate; auto navigate = std::make_unique<TNavigate>(); for (const auto& req : request.StatRequests) { @@ -74,6 +89,11 @@ private: return; } + if (!EnableStatistics) { + ReplyFailed(requestId); + return; + } + std::unordered_set<ui64> ssIds; bool isServerless = false; for (const auto& entry : navigate->ResultSet) { @@ -191,6 +211,20 @@ private: RegisterNode(); } + void HandleConfig(NConsole::TEvConfigsDispatcher::TEvSetConfigSubscriptionResponse::TPtr&) { + LOG_INFO_S(TlsActivationContext->AsActorContext(), NKikimrServices::STATISTICS, + "Subscribed for config changes"); + } + + void HandleConfig(NConsole::TEvConsole::TEvConfigNotificationRequest::TPtr& ev) { + const auto& record = ev->Get()->Record; + const auto& featureFlags = record.GetConfig().GetFeatureFlags(); + EnableStatistics = featureFlags.GetEnableStatistics(); + + auto response = std::make_unique<NConsole::TEvConsole::TEvConfigNotificationResponse>(record); + Send(ev->Sender, response.release(), 0, ev->Cookie); + } + void EstablishPipe() { if (!SchemeShardPipeClient && SchemeShardId) { auto policy = NTabletPipe::TClientRetryPolicy::WithRetries(); @@ -270,6 +304,12 @@ private: TResponse rsp; rsp.Success = false; rsp.Req = req; + + TStatSimple stat; + stat.RowCount = 0; + stat.BytesSize = 0; + rsp.Statistics = stat; + result->StatResponses.push_back(rsp); } @@ -286,11 +326,12 @@ private: } private: + bool EnableStatistics = false; + struct TRequestState { NActors::TActorId ReplyToActorId; ui64 EvCookie = 0; std::vector<TRequest> StatRequests; - bool WaitingForStatistics = false; }; std::map<ui64, TRequestState> InFlight; // request id -> state ui64 NextRequestId = 1; diff --git a/ydb/core/statistics/ut/ut_common.cpp b/ydb/core/statistics/ut/ut_common.cpp index 1bb5c5ee87c..80b20972264 100644 --- a/ydb/core/statistics/ut/ut_common.cpp +++ b/ydb/core/statistics/ut/ut_common.cpp @@ -35,6 +35,7 @@ TTestEnv::TTestEnv(ui32 staticNodes, ui32 dynamicNodes, ui32 storagePools) { Settings->SetDynamicNodeCount(dynamicNodes); NKikimrConfig::TFeatureFlags featureFlags; + featureFlags.SetEnableStatistics(true); Settings->SetFeatureFlags(featureFlags); for (ui32 i : xrange(storagePools)) { diff --git a/ydb/core/tx/schemeshard/schemeshard_impl.cpp b/ydb/core/tx/schemeshard/schemeshard_impl.cpp index 02143caf761..8d92948bccc 100644 --- a/ydb/core/tx/schemeshard/schemeshard_impl.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_impl.cpp @@ -4177,6 +4177,7 @@ void TSchemeShard::OnActivateExecutor(const TActorContext &ctx) { EnableMoveIndex = appData->FeatureFlags.GetEnableMoveIndex(); EnableAlterDatabaseCreateHiveFirst = appData->FeatureFlags.GetEnableAlterDatabaseCreateHiveFirst(); EnablePQConfigTransactionsAtSchemeShard = appData->FeatureFlags.GetEnablePQConfigTransactionsAtSchemeShard(); + EnableStatistics = appData->FeatureFlags.GetEnableStatistics(); ConfigureCompactionQueues(appData->CompactionConfig, ctx); ConfigureStatsBatching(appData->SchemeShardConfig, ctx); @@ -6606,6 +6607,7 @@ void TSchemeShard::ApplyConsoleConfigs(const NKikimrConfig::TFeatureFlags& featu EnableMoveIndex = featureFlags.GetEnableMoveIndex(); EnableAlterDatabaseCreateHiveFirst = featureFlags.GetEnableAlterDatabaseCreateHiveFirst(); EnablePQConfigTransactionsAtSchemeShard = featureFlags.GetEnablePQConfigTransactionsAtSchemeShard(); + EnableStatistics = featureFlags.GetEnableStatistics(); } void TSchemeShard::ConfigureStatsBatching(const NKikimrConfig::TSchemeShardConfig& config, const TActorContext& ctx) { @@ -6827,17 +6829,19 @@ void TSchemeShard::GenerateStatisticsMap() { auto broadcast = std::make_unique<NStat::TEvStatistics::TEvBroadcastStatistics>(); auto* record = broadcast->MutableRecord(); - for (const auto& [pathId, tableInfo] : Tables) { - const auto& aggregated = tableInfo->GetStats().Aggregated; - auto* entry = record->AddEntries(); - auto* entryPathId = entry->MutablePathId(); - entryPathId->SetOwnerId(pathId.OwnerId); - entryPathId->SetLocalId(pathId.LocalPathId); - entry->SetRowCount(aggregated.RowCount); - entry->SetBytesSize(aggregated.DataSize); - ++count; + if (EnableStatistics) { + for (const auto& [pathId, tableInfo] : Tables) { + const auto& aggregated = tableInfo->GetStats().Aggregated; + auto* entry = record->AddEntries(); + auto* entryPathId = entry->MutablePathId(); + entryPathId->SetOwnerId(pathId.OwnerId); + entryPathId->SetLocalId(pathId.LocalPathId); + entry->SetRowCount(aggregated.RowCount); + entry->SetBytesSize(aggregated.DataSize); + ++count; + } + // TODO: column tables } - // TODO: column tables PreSerializedStatisticsMapData.clear(); Y_PROTOBUF_SUPPRESS_NODISCARD record->SerializeToString(&PreSerializedStatisticsMapData); @@ -6862,6 +6866,7 @@ void TSchemeShard::BroadcastStatistics() { auto broadcast = std::make_unique<NStat::TEvStatistics::TEvBroadcastStatistics>(); auto* record = broadcast->MutableRecord(); + record->MutableNodeIds()->Reserve(StatNodes.size()); for (const auto& [nodeId, _] : StatNodes) { if (nodeId == leadingNodeId) { continue; @@ -6888,6 +6893,7 @@ void TSchemeShard::BroadcastStatisticsFast() { auto broadcast = std::make_unique<NStat::TEvStatistics::TEvBroadcastStatistics>(); auto* record = broadcast->MutableRecord(); + record->MutableNodeIds()->Reserve(StatFastBroadcastNodes.size()); for (const auto& nodeId : StatFastBroadcastNodes) { if (nodeId == leadingNodeId) { continue; diff --git a/ydb/core/tx/schemeshard/schemeshard_impl.h b/ydb/core/tx/schemeshard/schemeshard_impl.h index 82e1edcc7c7..17e75315c1f 100644 --- a/ydb/core/tx/schemeshard/schemeshard_impl.h +++ b/ydb/core/tx/schemeshard/schemeshard_impl.h @@ -265,6 +265,7 @@ public: bool EnableMoveIndex = true; bool EnableAlterDatabaseCreateHiveFirst = false; bool EnablePQConfigTransactionsAtSchemeShard = false; + bool EnableStatistics = false; TShardDeleter ShardDeleter; |