Skip to content

Commit fec2654

Browse files
authored
Persist config upon being changed by distconf (#14809)
1 parent cb222c2 commit fec2654

File tree

4 files changed

+69
-18
lines changed

4 files changed

+69
-18
lines changed

ydb/core/blobstorage/nodewarden/distconf.cpp

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,15 @@ namespace NKikimr::NStorage {
7474
MainConfigFetchYamlHash = 0;
7575

7676
if (config.HasConfigComposite()) {
77-
try {
78-
// parse the composite stream
79-
TStringInput ss(config.GetConfigComposite());
80-
TZstdDecompress zstd(&ss);
81-
MainConfigYaml = TString::Uninitialized(LoadSize(&zstd));
82-
zstd.LoadOrFail(MainConfigYaml.Detach(), MainConfigYaml.size());
83-
MainConfigFetchYaml = TString::Uninitialized(LoadSize(&zstd));
84-
zstd.LoadOrFail(MainConfigFetchYaml.Detach(), MainConfigFetchYaml.size());
85-
86-
// extract _current_ config version
87-
auto metadata = NYamlConfig::GetMainMetadata(MainConfigYaml);
88-
Y_DEBUG_ABORT_UNLESS(metadata.Version.has_value());
89-
MainConfigYamlVersion = metadata.Version.value_or(0);
90-
91-
// and _fetched_ config hash
92-
MainConfigFetchYamlHash = NYaml::GetConfigHash(MainConfigFetchYaml);
93-
} catch (const std::exception& ex) {
94-
Y_ABORT("ConfigComposite format incorrect: %s", ex.what());
77+
// parse the composite stream
78+
auto error = DecomposeConfig(config.GetConfigComposite(), &MainConfigYaml,
79+
&MainConfigYamlVersion.emplace(), &MainConfigFetchYaml);
80+
if (error) {
81+
Y_ABORT("ConfigComposite format incorrect: %s", error->data());
9582
}
83+
84+
// and _fetched_ config hash
85+
MainConfigFetchYamlHash = NYaml::GetConfigHash(MainConfigFetchYaml);
9686
}
9787

9888
// now extract the additional storage section
@@ -380,6 +370,34 @@ namespace NKikimr::NStorage {
380370
TActivationContext::Send(ev.Release());
381371
}
382372

373+
374+
std::optional<TString> DecomposeConfig(const TString& configComposite, TString *mainConfigYaml,
375+
ui64 *mainConfigVersion, TString *mainConfigFetchYaml) {
376+
try {
377+
TStringInput ss(configComposite);
378+
TZstdDecompress zstd(&ss);
379+
380+
TString yaml = TString::Uninitialized(LoadSize(&zstd));
381+
zstd.LoadOrFail(yaml.Detach(), yaml.size());
382+
if (mainConfigVersion) {
383+
auto metadata = NYamlConfig::GetMainMetadata(yaml);
384+
Y_DEBUG_ABORT_UNLESS(metadata.Version.has_value());
385+
*mainConfigVersion = metadata.Version.value_or(0);
386+
}
387+
if (mainConfigYaml) {
388+
*mainConfigYaml = std::move(yaml);
389+
}
390+
391+
if (mainConfigFetchYaml) {
392+
*mainConfigFetchYaml = TString::Uninitialized(LoadSize(&zstd));
393+
zstd.LoadOrFail(mainConfigFetchYaml->Detach(), mainConfigFetchYaml->size());
394+
}
395+
} catch (const std::exception& ex) {
396+
return ex.what();
397+
}
398+
return std::nullopt;
399+
}
400+
383401
} // NKikimr::NStorage
384402

385403
template<>

ydb/core/blobstorage/nodewarden/distconf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,9 @@ namespace NKikimr::NStorage {
738738

739739
std::optional<TString> ValidateConfig(const NKikimrBlobStorage::TStorageConfig& config);
740740

741+
std::optional<TString> DecomposeConfig(const TString& configComposite, TString *mainConfigYaml,
742+
ui64 *mainConfigVersion, TString *mainConfigFetchYaml);
743+
741744
} // NKikimr::NStorage
742745

743746
template<>

ydb/core/blobstorage/nodewarden/node_warden_impl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,10 @@ void TNodeWarden::PersistConfig(const TString& configYaml, ui64 version, std::op
640640
return;
641641
}
642642

643+
if (YamlConfig && version <= YamlConfig->GetConfigVersion()) {
644+
return; // some kind of a race
645+
}
646+
643647
struct TSaveContext {
644648
TString ConfigStorePath;
645649
TString ConfigYaml;

ydb/core/blobstorage/nodewarden/node_warden_resource.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#include "node_warden.h"
22
#include "node_warden_impl.h"
3+
#include "distconf.h"
34
#include <ydb/core/base/statestorage_impl.h>
45
#include <ydb/core/blobstorage/crypto/default.h>
56
#include <ydb/core/blobstorage/incrhuge/incrhuge_keeper.h>
67
#include <ydb/core/blobstorage/nodewarden/node_warden_events.h>
78
#include <ydb/library/pdisk_io/file_params.h>
89
#include <ydb/library/pdisk_io/wcache.h>
10+
#include <library/cpp/streams/zstd/zstd.h>
911
#include <util/string/split.h>
1012

1113
using namespace NKikimr;
@@ -112,6 +114,30 @@ void TNodeWarden::Handle(TEvNodeWardenStorageConfig::TPtr ev) {
112114
Send(subscriber, new TEvNodeWardenStorageConfig(StorageConfig, nullptr, SelfManagementEnabled));
113115
}
114116

117+
if (StorageConfig.HasConfigComposite()) {
118+
TString mainConfigYaml;
119+
ui64 mainConfigYamlVersion;
120+
auto error = DecomposeConfig(StorageConfig.GetConfigComposite(), &mainConfigYaml, &mainConfigYamlVersion, nullptr);
121+
if (error) {
122+
STLOG_DEBUG_FAIL(BS_NODE, NW49, "failed to decompose yaml configuration", (Error, error));
123+
} else if (mainConfigYaml) {
124+
std::optional<TString> storageConfigYaml;
125+
if (StorageConfig.HasCompressedStorageYaml()) {
126+
try {
127+
TStringInput s(StorageConfig.GetCompressedStorageYaml());
128+
storageConfigYaml.emplace(TZstdDecompress(&s).ReadAll());
129+
} catch (const std::exception& ex) {
130+
Y_ABORT("CompressedStorageYaml format incorrect: %s", ex.what());
131+
}
132+
}
133+
134+
// TODO(alexvru): make this blocker for confirmation?
135+
PersistConfig(std::move(mainConfigYaml), mainConfigYamlVersion, std::move(storageConfigYaml));
136+
}
137+
} else {
138+
Y_DEBUG_ABORT_UNLESS(!StorageConfig.HasCompressedStorageYaml());
139+
}
140+
115141
TActivationContext::Send(new IEventHandle(TEvBlobStorage::EvNodeWardenStorageConfigConfirm, 0, ev->Sender, SelfId(),
116142
nullptr, ev->Cookie));
117143
}

0 commit comments

Comments
 (0)