@@ -71,15 +71,66 @@ namespace NKikimr::NBsController {
71
71
if (!Working) {
72
72
return ;
73
73
}
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 ()) {
76
114
case NKikimrBlobStorage::TEvControllerProposeConfigResponse::HashMismatch:
77
115
STLOG (PRI_CRIT, BS_CONTROLLER, BSC25, " Config hash mismatch." );
78
116
Y_DEBUG_ABORT ();
79
117
break ;
80
118
81
119
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
+ }
83
134
break ;
84
135
85
136
case NKikimrBlobStorage::TEvControllerProposeConfigResponse::CommitIsNotNeeded:
@@ -102,33 +153,7 @@ namespace NKikimr::NBsController {
102
153
103
154
case NKikimrBlobStorage::TEvControllerProposeConfigResponse::ReverseCommit:
104
155
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 ();
132
157
} else {
133
158
STLOG (PRI_CRIT, BS_CONTROLLER, BSC29, " ReverseCommit status received when BSC has YamlConfig/StorageYamlConfig" ,
134
159
(YamlConfig, Self.YamlConfig ), (StorageYamlConfig, Self.StorageYamlConfig ), (Record, record));
0 commit comments