Skip to content

Commit 555fbb8

Browse files
authored
Fix distconf configuration fetch machinery (#14864)
1 parent 23aa667 commit 555fbb8

File tree

7 files changed

+83
-24
lines changed

7 files changed

+83
-24
lines changed

ydb/core/blobstorage/nodewarden/distconf_invoke.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ namespace NKikimr::NStorage {
145145
case TQuery::kAdvanceGeneration:
146146
return AdvanceGeneration();
147147

148-
case TQuery::kFetchStorageConfig:
149-
return FetchStorageConfig(record.GetFetchStorageConfig().GetManual());
148+
case TQuery::kFetchStorageConfig: {
149+
const auto& request = record.GetFetchStorageConfig();
150+
return FetchStorageConfig(request.GetManual(), request.GetMainConfig(), request.GetStorageConfig());
151+
}
150152

151153
case TQuery::kReplaceStorageConfig:
152154
return ReplaceStorageConfig(record.GetReplaceStorageConfig());
@@ -632,18 +634,27 @@ namespace NKikimr::NStorage {
632634
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
633635
// Storage configuration YAML manipulation
634636

635-
void FetchStorageConfig(bool manual) {
637+
void FetchStorageConfig(bool manual, bool fetchMain, bool fetchStorage) {
636638
if (!Self->StorageConfig) {
637639
FinishWithError(TResult::ERROR, "no agreed StorageConfig");
638640
} else if (!Self->MainConfigFetchYaml) {
639641
FinishWithError(TResult::ERROR, "no stored YAML for storage config");
640642
} else {
641643
auto ev = PrepareResult(TResult::OK, std::nullopt);
642644
auto *record = &ev->Record;
643-
record->MutableFetchStorageConfig()->SetYAML(Self->MainConfigFetchYaml);
645+
auto *res = record->MutableFetchStorageConfig();
646+
if (fetchMain) {
647+
res->SetYAML(Self->MainConfigFetchYaml);
648+
}
649+
if (fetchStorage && Self->StorageConfigYaml) {
650+
auto metadata = NYamlConfig::GetStorageMetadata(*Self->StorageConfigYaml);
651+
metadata.Cluster = metadata.Cluster.value_or("unknown"); // TODO: fix this
652+
metadata.Version = metadata.Version.value_or(0) + 1;
653+
res->SetStorageYAML(NYamlConfig::ReplaceMetadata(*Self->StorageConfigYaml, metadata));
654+
}
644655

645656
if (manual) {
646-
// add BlobStorageConfig, NameserviceConfig, DomainsConfig
657+
// add BlobStorageConfig, NameserviceConfig, DomainsConfig into main/storage config
647658
}
648659

649660
Finish(Sender, SelfId(), ev.release(), 0, Cookie);

ydb/core/grpc_services/rpc_config.cpp

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,20 +222,49 @@ class TFetchStorageConfigRequest : public TBSConfigRequestGrpc<TFetchStorageConf
222222
}
223223

224224
void FillDistconfQuery(NStorage::TEvNodeConfigInvokeOnRoot& ev) const {
225-
ev.Record.MutableFetchStorageConfig();
225+
auto *record = ev.Record.MutableFetchStorageConfig();
226+
227+
switch (auto& request = *GetProtoRequest(); request.mode_case()) {
228+
case Ydb::Config::FetchConfigRequest::ModeCase::kAll:
229+
record->SetMainConfig(true);
230+
record->SetStorageConfig(true);
231+
break;
232+
233+
case Ydb::Config::FetchConfigRequest::ModeCase::kTarget:
234+
// TODO: implement
235+
break;
236+
237+
case Ydb::Config::FetchConfigRequest::ModeCase::MODE_NOT_SET:
238+
break;
239+
}
226240
}
227241

228242
void FillDistconfResult(NKikimrBlobStorage::TEvNodeConfigInvokeOnRootResult& record,
229243
Ydb::Config::FetchConfigResult& result) {
230-
auto conf = record.GetFetchStorageConfig().GetYAML();
231-
auto metadata = NYamlConfig::GetMainMetadata(conf);
232-
// TODO: !imp error if empty
233-
auto& config = *result.add_config();
234-
auto& identity = *config.mutable_identity();
235-
identity.set_version(*metadata.Version);
236-
identity.set_cluster(AppData()->ClusterName);
237-
identity.mutable_main();
238-
config.set_config(conf);
244+
const auto& res = record.GetFetchStorageConfig();
245+
246+
if (res.HasYAML()) {
247+
auto conf = record.GetFetchStorageConfig().GetYAML();
248+
auto metadata = NYamlConfig::GetMainMetadata(conf);
249+
// TODO: !imp error if empty
250+
auto& config = *result.add_config();
251+
auto& identity = *config.mutable_identity();
252+
identity.set_version(*metadata.Version);
253+
identity.set_cluster(AppData()->ClusterName);
254+
identity.mutable_main();
255+
config.set_config(conf);
256+
}
257+
if (res.HasStorageYAML()) {
258+
auto conf = record.GetFetchStorageConfig().GetStorageYAML();
259+
auto metadata = NYamlConfig::GetStorageMetadata(conf);
260+
// TODO: !imp error if empty
261+
auto& config = *result.add_config();
262+
auto& identity = *config.mutable_identity();
263+
identity.set_version(*metadata.Version);
264+
identity.set_cluster(AppData()->ClusterName);
265+
identity.mutable_storage();
266+
config.set_config(conf);
267+
}
239268
}
240269

241270
bool IsDistconfEnableQuery() const {

ydb/core/protos/blobstorage_distributed_config.proto

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ message TEvNodeConfigInvokeOnRoot {
193193

194194
message TFetchStorageConfig {
195195
bool Manual = 1; // when set to true, distconf returns conventional configuration
196+
bool MainConfig = 2;
197+
bool StorageConfig = 3;
196198
}
197199

198200
message TReplaceStorageConfig {
@@ -241,7 +243,8 @@ message TEvNodeConfigInvokeOnRootResult {
241243
}
242244

243245
message TFetchStorageConfig {
244-
string YAML = 1;
246+
optional string YAML = 1;
247+
optional string StorageYAML = 2;
245248
}
246249

247250
EStatus Status = 1;

ydb/library/yaml_config/public/yaml_config.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,17 @@ TString ReplaceMetadata(const TString& config, const TDatabaseMetadata& metadata
777777
return ReplaceMetadata(config, serializeMetadata);
778778
}
779779

780+
TString ReplaceMetadata(const TString& config, const TStorageMetadata& metadata) {
781+
auto serializeMetadata = [&](TStringStream& sstr) {
782+
sstr
783+
<< "metadata:"
784+
<< "\n kind: StorageConfig"
785+
<< "\n cluster: \"" << *metadata.Cluster << "\""
786+
<< "\n version: " << *metadata.Version;
787+
};
788+
return ReplaceMetadata(config, serializeMetadata);
789+
}
790+
780791
TString ReplaceMetadata(const TString& config, const TVolatileMetadata& metadata) {
781792
auto serializeMetadata = [&](TStringStream& sstr) {
782793
sstr

ydb/library/yaml_config/public/yaml_config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ TString ReplaceMetadata(const TString& config, const TMainMetadata& metadata);
250250
*/
251251
TString ReplaceMetadata(const TString& config, const TDatabaseMetadata& metadata);
252252

253+
/**
254+
* Replaces metadata in storage config
255+
*/
256+
TString ReplaceMetadata(const TString& config, const TStorageMetadata& metadata);
257+
253258
/**
254259
* Replaces volatile metadata in config
255260
*/

ydb/public/lib/ydb_cli/commands/ydb_storage_config.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,8 @@ int TCommandStorageConfigFetch::Run(TConfig& config) {
6464
auto driver = std::make_unique<NYdb::TDriver>(CreateDriver(config));
6565
auto client = NYdb::NConfig::TConfigClient(*driver);
6666

67-
bool needDetach = DedicatedStorageSection || DedicatedClusterSection;
68-
6967
NYdb::NConfig::TFetchAllConfigsSettings settings;
7068

71-
if (needDetach) {
72-
settings.Transform(NYdb::NConfig::EFetchAllConfigsTransform::DETACH_STORAGE_CONFIG_SECTION);
73-
}
74-
7569
auto result = client.FetchAllConfigs(settings).GetValueSync();
7670
NStatusHelpers::ThrowOnError(result);
7771

@@ -82,9 +76,13 @@ int TCommandStorageConfigFetch::Run(TConfig& config) {
8276
std::visit([&](auto&& arg) {
8377
using T = std::decay_t<decltype(arg)>;
8478
if constexpr (std::is_same_v<T, NYdb::NConfig::TMainConfigIdentity>) {
85-
clusterConfig = entry.Config;
79+
if (DedicatedClusterSection || !DedicatedStorageSection) {
80+
clusterConfig = entry.Config;
81+
}
8682
} else if constexpr (std::is_same_v<T, NYdb::NConfig::TStorageConfigIdentity>) {
87-
storageConfig = entry.Config;
83+
if (DedicatedStorageSection || !DedicatedClusterSection) {
84+
storageConfig = entry.Config;
85+
}
8886
}
8987
}, entry.Identity);
9088
}

ydb/public/sdk/cpp/src/client/config/config.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class TConfigClient::TImpl : public TClientImplCommon<TConfigClient::TImpl> {
6868

6969
TAsyncFetchConfigResult FetchAllConfigs(const TFetchAllConfigsSettings& settings = {}) {
7070
auto request = MakeOperationRequest<Ydb::Config::FetchConfigRequest>(settings);
71+
request.mutable_all();
72+
7173
auto promise = NThreading::NewPromise<TFetchConfigResult>();
7274

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

0 commit comments

Comments
 (0)