Skip to content

Commit

Permalink
Fix distconf configuration fetch machinery (#14864)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvru authored Feb 20, 2025
1 parent 23aa667 commit 555fbb8
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 24 deletions.
21 changes: 16 additions & 5 deletions ydb/core/blobstorage/nodewarden/distconf_invoke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ namespace NKikimr::NStorage {
case TQuery::kAdvanceGeneration:
return AdvanceGeneration();

case TQuery::kFetchStorageConfig:
return FetchStorageConfig(record.GetFetchStorageConfig().GetManual());
case TQuery::kFetchStorageConfig: {
const auto& request = record.GetFetchStorageConfig();
return FetchStorageConfig(request.GetManual(), request.GetMainConfig(), request.GetStorageConfig());
}

case TQuery::kReplaceStorageConfig:
return ReplaceStorageConfig(record.GetReplaceStorageConfig());
Expand Down Expand Up @@ -632,18 +634,27 @@ namespace NKikimr::NStorage {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Storage configuration YAML manipulation

void FetchStorageConfig(bool manual) {
void FetchStorageConfig(bool manual, bool fetchMain, bool fetchStorage) {
if (!Self->StorageConfig) {
FinishWithError(TResult::ERROR, "no agreed StorageConfig");
} else if (!Self->MainConfigFetchYaml) {
FinishWithError(TResult::ERROR, "no stored YAML for storage config");
} else {
auto ev = PrepareResult(TResult::OK, std::nullopt);
auto *record = &ev->Record;
record->MutableFetchStorageConfig()->SetYAML(Self->MainConfigFetchYaml);
auto *res = record->MutableFetchStorageConfig();
if (fetchMain) {
res->SetYAML(Self->MainConfigFetchYaml);
}
if (fetchStorage && Self->StorageConfigYaml) {
auto metadata = NYamlConfig::GetStorageMetadata(*Self->StorageConfigYaml);
metadata.Cluster = metadata.Cluster.value_or("unknown"); // TODO: fix this
metadata.Version = metadata.Version.value_or(0) + 1;
res->SetStorageYAML(NYamlConfig::ReplaceMetadata(*Self->StorageConfigYaml, metadata));
}

if (manual) {
// add BlobStorageConfig, NameserviceConfig, DomainsConfig
// add BlobStorageConfig, NameserviceConfig, DomainsConfig into main/storage config
}

Finish(Sender, SelfId(), ev.release(), 0, Cookie);
Expand Down
49 changes: 39 additions & 10 deletions ydb/core/grpc_services/rpc_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,49 @@ class TFetchStorageConfigRequest : public TBSConfigRequestGrpc<TFetchStorageConf
}

void FillDistconfQuery(NStorage::TEvNodeConfigInvokeOnRoot& ev) const {
ev.Record.MutableFetchStorageConfig();
auto *record = ev.Record.MutableFetchStorageConfig();

switch (auto& request = *GetProtoRequest(); request.mode_case()) {
case Ydb::Config::FetchConfigRequest::ModeCase::kAll:
record->SetMainConfig(true);
record->SetStorageConfig(true);
break;

case Ydb::Config::FetchConfigRequest::ModeCase::kTarget:
// TODO: implement
break;

case Ydb::Config::FetchConfigRequest::ModeCase::MODE_NOT_SET:
break;
}
}

void FillDistconfResult(NKikimrBlobStorage::TEvNodeConfigInvokeOnRootResult& record,
Ydb::Config::FetchConfigResult& result) {
auto conf = record.GetFetchStorageConfig().GetYAML();
auto metadata = NYamlConfig::GetMainMetadata(conf);
// TODO: !imp error if empty
auto& config = *result.add_config();
auto& identity = *config.mutable_identity();
identity.set_version(*metadata.Version);
identity.set_cluster(AppData()->ClusterName);
identity.mutable_main();
config.set_config(conf);
const auto& res = record.GetFetchStorageConfig();

if (res.HasYAML()) {
auto conf = record.GetFetchStorageConfig().GetYAML();
auto metadata = NYamlConfig::GetMainMetadata(conf);
// TODO: !imp error if empty
auto& config = *result.add_config();
auto& identity = *config.mutable_identity();
identity.set_version(*metadata.Version);
identity.set_cluster(AppData()->ClusterName);
identity.mutable_main();
config.set_config(conf);
}
if (res.HasStorageYAML()) {
auto conf = record.GetFetchStorageConfig().GetStorageYAML();
auto metadata = NYamlConfig::GetStorageMetadata(conf);
// TODO: !imp error if empty
auto& config = *result.add_config();
auto& identity = *config.mutable_identity();
identity.set_version(*metadata.Version);
identity.set_cluster(AppData()->ClusterName);
identity.mutable_storage();
config.set_config(conf);
}
}

bool IsDistconfEnableQuery() const {
Expand Down
5 changes: 4 additions & 1 deletion ydb/core/protos/blobstorage_distributed_config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ message TEvNodeConfigInvokeOnRoot {

message TFetchStorageConfig {
bool Manual = 1; // when set to true, distconf returns conventional configuration
bool MainConfig = 2;
bool StorageConfig = 3;
}

message TReplaceStorageConfig {
Expand Down Expand Up @@ -241,7 +243,8 @@ message TEvNodeConfigInvokeOnRootResult {
}

message TFetchStorageConfig {
string YAML = 1;
optional string YAML = 1;
optional string StorageYAML = 2;
}

EStatus Status = 1;
Expand Down
11 changes: 11 additions & 0 deletions ydb/library/yaml_config/public/yaml_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,17 @@ TString ReplaceMetadata(const TString& config, const TDatabaseMetadata& metadata
return ReplaceMetadata(config, serializeMetadata);
}

TString ReplaceMetadata(const TString& config, const TStorageMetadata& metadata) {
auto serializeMetadata = [&](TStringStream& sstr) {
sstr
<< "metadata:"
<< "\n kind: StorageConfig"
<< "\n cluster: \"" << *metadata.Cluster << "\""
<< "\n version: " << *metadata.Version;
};
return ReplaceMetadata(config, serializeMetadata);
}

TString ReplaceMetadata(const TString& config, const TVolatileMetadata& metadata) {
auto serializeMetadata = [&](TStringStream& sstr) {
sstr
Expand Down
5 changes: 5 additions & 0 deletions ydb/library/yaml_config/public/yaml_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ TString ReplaceMetadata(const TString& config, const TMainMetadata& metadata);
*/
TString ReplaceMetadata(const TString& config, const TDatabaseMetadata& metadata);

/**
* Replaces metadata in storage config
*/
TString ReplaceMetadata(const TString& config, const TStorageMetadata& metadata);

/**
* Replaces volatile metadata in config
*/
Expand Down
14 changes: 6 additions & 8 deletions ydb/public/lib/ydb_cli/commands/ydb_storage_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,8 @@ int TCommandStorageConfigFetch::Run(TConfig& config) {
auto driver = std::make_unique<NYdb::TDriver>(CreateDriver(config));
auto client = NYdb::NConfig::TConfigClient(*driver);

bool needDetach = DedicatedStorageSection || DedicatedClusterSection;

NYdb::NConfig::TFetchAllConfigsSettings settings;

if (needDetach) {
settings.Transform(NYdb::NConfig::EFetchAllConfigsTransform::DETACH_STORAGE_CONFIG_SECTION);
}

auto result = client.FetchAllConfigs(settings).GetValueSync();
NStatusHelpers::ThrowOnError(result);

Expand All @@ -82,9 +76,13 @@ int TCommandStorageConfigFetch::Run(TConfig& config) {
std::visit([&](auto&& arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, NYdb::NConfig::TMainConfigIdentity>) {
clusterConfig = entry.Config;
if (DedicatedClusterSection || !DedicatedStorageSection) {
clusterConfig = entry.Config;
}
} else if constexpr (std::is_same_v<T, NYdb::NConfig::TStorageConfigIdentity>) {
storageConfig = entry.Config;
if (DedicatedStorageSection || !DedicatedClusterSection) {
storageConfig = entry.Config;
}
}
}, entry.Identity);
}
Expand Down
2 changes: 2 additions & 0 deletions ydb/public/sdk/cpp/src/client/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class TConfigClient::TImpl : public TClientImplCommon<TConfigClient::TImpl> {

TAsyncFetchConfigResult FetchAllConfigs(const TFetchAllConfigsSettings& settings = {}) {
auto request = MakeOperationRequest<Ydb::Config::FetchConfigRequest>(settings);
request.mutable_all();

auto promise = NThreading::NewPromise<TFetchConfigResult>();

auto extractor = [promise] (google::protobuf::Any* any, TPlainStatus status) mutable {
Expand Down

0 comments on commit 555fbb8

Please sign in to comment.