Skip to content

Commit 6238290

Browse files
authored
Fix Console version handling (#15679)
1 parent 61f9619 commit 6238290

File tree

2 files changed

+59
-31
lines changed

2 files changed

+59
-31
lines changed

ydb/core/cms/console/console_handshake.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,13 @@ void TConfigsManager::Handle(TEvBlobStorage::TEvControllerProposeConfigRequest::
137137
responseRecord.SetYAML(MainYamlConfig);
138138
} else if (YamlVersion == proposedConfigVersion) {
139139
responseRecord.SetStatus(NKikimrBlobStorage::TEvControllerProposeConfigResponse::CommitIsNeeded);
140-
} else if (YamlVersion != proposedConfigVersion && (proposedConfigVersion && YamlVersion != proposedConfigVersion - 1)) {
140+
} else if (YamlVersion != proposedConfigVersion + 1) {
141141
responseRecord.SetStatus(NKikimrBlobStorage::TEvControllerProposeConfigResponse::UnexpectedConfig);
142142
responseRecord.SetProposedConfigVersion(proposedConfigVersion);
143143
responseRecord.SetConsoleConfigVersion(YamlVersion);
144+
if (proposedConfigVersion + 1 < YamlVersion) {
145+
responseRecord.SetYAML(MainYamlConfig);
146+
}
144147
LOG_ALERT_S(ctx, NKikimrServices::CMS, "Unexpected proposed config.");
145148
} else if (proposedConfigHash != currentConfigHash) {
146149
responseRecord.SetStatus(NKikimrBlobStorage::TEvControllerProposeConfigResponse::HashMismatch);

ydb/core/mind/bscontroller/console_interaction.cpp

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,66 @@ namespace NKikimr::NBsController {
7171
if (!Working) {
7272
return;
7373
}
74-
STLOG(PRI_DEBUG, BS_CONTROLLER, BSC19, "Console proposed config response", (Response, ev->Get()->Record));
75-
switch (auto& record = ev->Get()->Record; record.GetStatus()) {
74+
75+
auto& record = ev->Get()->Record;
76+
STLOG(PRI_DEBUG, BS_CONTROLLER, BSC19, "Console proposed config response", (Response, record));
77+
78+
auto overwriteConfig = [&] {
79+
TString yamlReturnedByFetch = record.GetYAML();
80+
if (!yamlReturnedByFetch) {
81+
return; // no yaml config stored in Console
82+
}
83+
try {
84+
NKikimrConfig::TAppConfig appConfig = NYaml::Parse(yamlReturnedByFetch);
85+
NKikimrBlobStorage::TStorageConfig storageConfig;
86+
TString temp;
87+
if (!NKikimr::NStorage::DeriveStorageConfig(appConfig, &storageConfig, &temp)) {
88+
STLOG(PRI_ERROR, BS_CONTROLLER, BSC21, "failed to derive storage config from one stored in Console",
89+
(ErrorReason, temp), (AppConfig, appConfig));
90+
} else if (auto errorReason = NKikimr::NStorage::ValidateConfig(storageConfig)) {
91+
STLOG(PRI_ERROR, BS_CONTROLLER, BSC23, "failed to validate StorageConfig",
92+
(ErrorReason, errorReason), (StorageConfig, storageConfig));
93+
} else {
94+
// try to obtain original config, without version incremented
95+
TString yaml;
96+
ui64 version = record.GetConsoleConfigVersion() - 1; // Console config version is the next expected one
97+
if (auto m = NYamlConfig::GetMainMetadata(yamlReturnedByFetch); m.Version.value_or(0)) {
98+
version = m.Version.emplace(*m.Version - 1);
99+
yaml = NYamlConfig::ReplaceMetadata(yamlReturnedByFetch, m);
100+
}
101+
102+
TYamlConfig yamlConfig(std::move(yaml), version, std::move(yamlReturnedByFetch));
103+
Self.Execute(Self.CreateTxCommitConfig(std::move(yamlConfig), std::nullopt,
104+
std::move(storageConfig), std::nullopt, nullptr));
105+
CommitInProgress = true;
106+
}
107+
} catch (const std::exception& ex) {
108+
STLOG(PRI_ERROR, BS_CONTROLLER, BSC26, "failed to parse config obtained from Console",
109+
(ErrorReason, ex.what()), (Yaml, yamlReturnedByFetch));
110+
}
111+
};
112+
113+
switch (record.GetStatus()) {
76114
case NKikimrBlobStorage::TEvControllerProposeConfigResponse::HashMismatch:
77115
STLOG(PRI_CRIT, BS_CONTROLLER, BSC25, "Config hash mismatch.");
78116
Y_DEBUG_ABORT();
79117
break;
80118

81119
case NKikimrBlobStorage::TEvControllerProposeConfigResponse::UnexpectedConfig:
82-
MakeGetBlock();
120+
if (record.GetProposedConfigVersion() + 1 < record.GetConsoleConfigVersion()) {
121+
// console has a newer config, possibly updated during older version of server running
122+
if (Self.StorageYamlConfig) {
123+
STLOG(PRI_ERROR, BS_CONTROLLER, BSC30, "Console has newer config, but BSC has dedicated storage"
124+
" yaml config section, config not updated");
125+
} else if (record.HasYAML()) {
126+
overwriteConfig();
127+
} else {
128+
STLOG(PRI_ERROR, BS_CONTROLLER, BSC32, "Console has newer config, but no yaml was returned");
129+
}
130+
} else {
131+
STLOG(PRI_CRIT, BS_CONTROLLER, BSC31, "Console has older config version than BSC");
132+
Y_DEBUG_ABORT();
133+
}
83134
break;
84135

85136
case NKikimrBlobStorage::TEvControllerProposeConfigResponse::CommitIsNotNeeded:
@@ -102,33 +153,7 @@ namespace NKikimr::NBsController {
102153

103154
case NKikimrBlobStorage::TEvControllerProposeConfigResponse::ReverseCommit:
104155
if (!Self.YamlConfig && !Self.StorageYamlConfig) {
105-
const TString& yamlReturnedByFetch = record.GetYAML();
106-
const ui64 version = record.GetConsoleConfigVersion();
107-
if (!version) {
108-
// there is no config in Console
109-
} else {
110-
try {
111-
NKikimrConfig::TAppConfig appConfig = NYaml::Parse(yamlReturnedByFetch);
112-
NKikimrBlobStorage::TStorageConfig storageConfig;
113-
TString temp;
114-
if (!NKikimr::NStorage::DeriveStorageConfig(appConfig, &storageConfig, &temp)) {
115-
STLOG(PRI_ERROR, BS_CONTROLLER, BSC21, "failed to derive storage config from one stored in Console",
116-
(ErrorReason, temp), (Version, version), (AppConfig, appConfig));
117-
} else if (auto errorReason = NKikimr::NStorage::ValidateConfig(storageConfig)) {
118-
STLOG(PRI_ERROR, BS_CONTROLLER, BSC23, "failed to validate StorageConfig",
119-
(ErrorReason, errorReason), (StorageConfig, storageConfig));
120-
} else {
121-
// execute initial migration transaction: restore cluster.yaml part from Console
122-
TYamlConfig yamlConfig(TString(), record.GetConsoleConfigVersion(), yamlReturnedByFetch);
123-
Self.Execute(Self.CreateTxCommitConfig(std::move(yamlConfig), std::nullopt,
124-
std::move(storageConfig), std::nullopt, nullptr));
125-
CommitInProgress = true;
126-
}
127-
} catch (const std::exception& ex) {
128-
STLOG(PRI_ERROR, BS_CONTROLLER, BSC26, "failed to parse config obtained from Console",
129-
(ErrorReason, ex.what()), (Yaml, yamlReturnedByFetch));
130-
}
131-
}
156+
overwriteConfig();
132157
} else {
133158
STLOG(PRI_CRIT, BS_CONTROLLER, BSC29, "ReverseCommit status received when BSC has YamlConfig/StorageYamlConfig",
134159
(YamlConfig, Self.YamlConfig), (StorageYamlConfig, Self.StorageYamlConfig), (Record, record));

0 commit comments

Comments
 (0)