aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Rutkovsky <alexvru@ydb.tech>2025-03-13 16:33:22 +0300
committerGitHub <noreply@github.com>2025-03-13 16:33:22 +0300
commit623829051c534fa4e4aa43590597a6f7f7119378 (patch)
tree7e8be429f8800416c7ec104ef1f86a4814f9f406
parent61f9619e63c85ecdb13d7a035e3e36186f503b2f (diff)
downloadydb-623829051c534fa4e4aa43590597a6f7f7119378.tar.gz
Fix Console version handling (#15679)
-rw-r--r--ydb/core/cms/console/console_handshake.cpp5
-rw-r--r--ydb/core/mind/bscontroller/console_interaction.cpp85
2 files changed, 59 insertions, 31 deletions
diff --git a/ydb/core/cms/console/console_handshake.cpp b/ydb/core/cms/console/console_handshake.cpp
index c486ff1b405..f393e867ab6 100644
--- a/ydb/core/cms/console/console_handshake.cpp
+++ b/ydb/core/cms/console/console_handshake.cpp
@@ -137,10 +137,13 @@ void TConfigsManager::Handle(TEvBlobStorage::TEvControllerProposeConfigRequest::
responseRecord.SetYAML(MainYamlConfig);
} else if (YamlVersion == proposedConfigVersion) {
responseRecord.SetStatus(NKikimrBlobStorage::TEvControllerProposeConfigResponse::CommitIsNeeded);
- } else if (YamlVersion != proposedConfigVersion && (proposedConfigVersion && YamlVersion != proposedConfigVersion - 1)) {
+ } else if (YamlVersion != proposedConfigVersion + 1) {
responseRecord.SetStatus(NKikimrBlobStorage::TEvControllerProposeConfigResponse::UnexpectedConfig);
responseRecord.SetProposedConfigVersion(proposedConfigVersion);
responseRecord.SetConsoleConfigVersion(YamlVersion);
+ if (proposedConfigVersion + 1 < YamlVersion) {
+ responseRecord.SetYAML(MainYamlConfig);
+ }
LOG_ALERT_S(ctx, NKikimrServices::CMS, "Unexpected proposed config.");
} else if (proposedConfigHash != currentConfigHash) {
responseRecord.SetStatus(NKikimrBlobStorage::TEvControllerProposeConfigResponse::HashMismatch);
diff --git a/ydb/core/mind/bscontroller/console_interaction.cpp b/ydb/core/mind/bscontroller/console_interaction.cpp
index d58f55cda04..652cd528ae5 100644
--- a/ydb/core/mind/bscontroller/console_interaction.cpp
+++ b/ydb/core/mind/bscontroller/console_interaction.cpp
@@ -71,15 +71,66 @@ namespace NKikimr::NBsController {
if (!Working) {
return;
}
- STLOG(PRI_DEBUG, BS_CONTROLLER, BSC19, "Console proposed config response", (Response, ev->Get()->Record));
- switch (auto& record = ev->Get()->Record; record.GetStatus()) {
+
+ auto& record = ev->Get()->Record;
+ STLOG(PRI_DEBUG, BS_CONTROLLER, BSC19, "Console proposed config response", (Response, record));
+
+ auto overwriteConfig = [&] {
+ TString yamlReturnedByFetch = record.GetYAML();
+ if (!yamlReturnedByFetch) {
+ return; // no yaml config stored in Console
+ }
+ try {
+ NKikimrConfig::TAppConfig appConfig = NYaml::Parse(yamlReturnedByFetch);
+ NKikimrBlobStorage::TStorageConfig storageConfig;
+ TString temp;
+ if (!NKikimr::NStorage::DeriveStorageConfig(appConfig, &storageConfig, &temp)) {
+ STLOG(PRI_ERROR, BS_CONTROLLER, BSC21, "failed to derive storage config from one stored in Console",
+ (ErrorReason, temp), (AppConfig, appConfig));
+ } else if (auto errorReason = NKikimr::NStorage::ValidateConfig(storageConfig)) {
+ STLOG(PRI_ERROR, BS_CONTROLLER, BSC23, "failed to validate StorageConfig",
+ (ErrorReason, errorReason), (StorageConfig, storageConfig));
+ } else {
+ // try to obtain original config, without version incremented
+ TString yaml;
+ ui64 version = record.GetConsoleConfigVersion() - 1; // Console config version is the next expected one
+ if (auto m = NYamlConfig::GetMainMetadata(yamlReturnedByFetch); m.Version.value_or(0)) {
+ version = m.Version.emplace(*m.Version - 1);
+ yaml = NYamlConfig::ReplaceMetadata(yamlReturnedByFetch, m);
+ }
+
+ TYamlConfig yamlConfig(std::move(yaml), version, std::move(yamlReturnedByFetch));
+ Self.Execute(Self.CreateTxCommitConfig(std::move(yamlConfig), std::nullopt,
+ std::move(storageConfig), std::nullopt, nullptr));
+ CommitInProgress = true;
+ }
+ } catch (const std::exception& ex) {
+ STLOG(PRI_ERROR, BS_CONTROLLER, BSC26, "failed to parse config obtained from Console",
+ (ErrorReason, ex.what()), (Yaml, yamlReturnedByFetch));
+ }
+ };
+
+ switch (record.GetStatus()) {
case NKikimrBlobStorage::TEvControllerProposeConfigResponse::HashMismatch:
STLOG(PRI_CRIT, BS_CONTROLLER, BSC25, "Config hash mismatch.");
Y_DEBUG_ABORT();
break;
case NKikimrBlobStorage::TEvControllerProposeConfigResponse::UnexpectedConfig:
- MakeGetBlock();
+ if (record.GetProposedConfigVersion() + 1 < record.GetConsoleConfigVersion()) {
+ // console has a newer config, possibly updated during older version of server running
+ if (Self.StorageYamlConfig) {
+ STLOG(PRI_ERROR, BS_CONTROLLER, BSC30, "Console has newer config, but BSC has dedicated storage"
+ " yaml config section, config not updated");
+ } else if (record.HasYAML()) {
+ overwriteConfig();
+ } else {
+ STLOG(PRI_ERROR, BS_CONTROLLER, BSC32, "Console has newer config, but no yaml was returned");
+ }
+ } else {
+ STLOG(PRI_CRIT, BS_CONTROLLER, BSC31, "Console has older config version than BSC");
+ Y_DEBUG_ABORT();
+ }
break;
case NKikimrBlobStorage::TEvControllerProposeConfigResponse::CommitIsNotNeeded:
@@ -102,33 +153,7 @@ namespace NKikimr::NBsController {
case NKikimrBlobStorage::TEvControllerProposeConfigResponse::ReverseCommit:
if (!Self.YamlConfig && !Self.StorageYamlConfig) {
- const TString& yamlReturnedByFetch = record.GetYAML();
- const ui64 version = record.GetConsoleConfigVersion();
- if (!version) {
- // there is no config in Console
- } else {
- try {
- NKikimrConfig::TAppConfig appConfig = NYaml::Parse(yamlReturnedByFetch);
- NKikimrBlobStorage::TStorageConfig storageConfig;
- TString temp;
- if (!NKikimr::NStorage::DeriveStorageConfig(appConfig, &storageConfig, &temp)) {
- STLOG(PRI_ERROR, BS_CONTROLLER, BSC21, "failed to derive storage config from one stored in Console",
- (ErrorReason, temp), (Version, version), (AppConfig, appConfig));
- } else if (auto errorReason = NKikimr::NStorage::ValidateConfig(storageConfig)) {
- STLOG(PRI_ERROR, BS_CONTROLLER, BSC23, "failed to validate StorageConfig",
- (ErrorReason, errorReason), (StorageConfig, storageConfig));
- } else {
- // execute initial migration transaction: restore cluster.yaml part from Console
- TYamlConfig yamlConfig(TString(), record.GetConsoleConfigVersion(), yamlReturnedByFetch);
- Self.Execute(Self.CreateTxCommitConfig(std::move(yamlConfig), std::nullopt,
- std::move(storageConfig), std::nullopt, nullptr));
- CommitInProgress = true;
- }
- } catch (const std::exception& ex) {
- STLOG(PRI_ERROR, BS_CONTROLLER, BSC26, "failed to parse config obtained from Console",
- (ErrorReason, ex.what()), (Yaml, yamlReturnedByFetch));
- }
- }
+ overwriteConfig();
} else {
STLOG(PRI_CRIT, BS_CONTROLLER, BSC29, "ReverseCommit status received when BSC has YamlConfig/StorageYamlConfig",
(YamlConfig, Self.YamlConfig), (StorageYamlConfig, Self.StorageYamlConfig), (Record, record));