Skip to content

Commit cf2bd88

Browse files
Enjectionalexvru
andauthored
[stable-25-1] Distconfig fixes part 2 (#16296)
Co-authored-by: Alexander Rutkovsky <alexvru@ydb.tech>
1 parent e14daca commit cf2bd88

File tree

19 files changed

+190
-56
lines changed

19 files changed

+190
-56
lines changed

ydb/core/blobstorage/base/blobstorage_console_events.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,9 @@ namespace NKikimr {
7777
NKikimrBlobStorage::TEvControllerReplaceConfigRequest, EvControllerReplaceConfigRequest> {
7878
TEvControllerReplaceConfigRequest() = default;
7979

80-
TEvControllerReplaceConfigRequest(
81-
std::optional<TString> clusterYaml,
82-
std::optional<TString> storageYaml,
83-
std::optional<bool> switchDedicatedStorageSection,
84-
bool dedicatedConfigMode,
85-
bool allowUnknownFields,
86-
bool bypassMetadataChecks) {
87-
80+
TEvControllerReplaceConfigRequest(std::optional<TString> clusterYaml, std::optional<TString> storageYaml,
81+
std::optional<bool> switchDedicatedStorageSection, bool dedicatedConfigMode, bool allowUnknownFields,
82+
bool bypassMetadataChecks, bool enableConfigV2, bool disableConfigV2) {
8883
if (clusterYaml) {
8984
Record.SetClusterYaml(*clusterYaml);
9085
}
@@ -97,6 +92,11 @@ namespace NKikimr {
9792
Record.SetDedicatedConfigMode(dedicatedConfigMode);
9893
Record.SetAllowUnknownFields(allowUnknownFields);
9994
Record.SetBypassMetadataChecks(bypassMetadataChecks);
95+
if (enableConfigV2) {
96+
Record.SetSwitchEnableConfigV2(true);
97+
} else if (disableConfigV2) {
98+
Record.SetSwitchEnableConfigV2(false);
99+
}
100100
}
101101

102102
TString ToString() const override {

ydb/core/blobstorage/nodewarden/distconf_console.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ namespace NKikimr::NStorage {
213213
if (!fetched) { // fill in 'to-be-fetched' version of config with version incremented by one
214214
try {
215215
auto metadata = NYamlConfig::GetMainMetadata(yaml);
216-
metadata.Cluster = metadata.Cluster.value_or("unknown"); // TODO: fix this
216+
metadata.Cluster = metadata.Cluster.value_or(AppData()->ClusterName);
217217
metadata.Version = metadata.Version.value_or(0) + 1;
218218
temp = NYamlConfig::ReplaceMetadata(yaml, metadata);
219219
} catch (const std::exception& ex) {

ydb/core/blobstorage/nodewarden/distconf_invoke_storage_config.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,17 @@ namespace NKikimr::NStorage {
1313
void TInvokeRequestHandlerActor::FetchStorageConfig(bool manual, bool fetchMain, bool fetchStorage) {
1414
if (!Self->StorageConfig) {
1515
FinishWithError(TResult::ERROR, "no agreed StorageConfig");
16-
} else if (!Self->MainConfigFetchYaml) {
16+
} else if (!Self->MainConfigYaml) {
1717
FinishWithError(TResult::ERROR, "no stored YAML for storage config");
1818
} else {
1919
auto ev = PrepareResult(TResult::OK, std::nullopt);
2020
auto *record = &ev->Record;
2121
auto *res = record->MutableFetchStorageConfig();
2222
if (fetchMain) {
23-
res->SetYAML(Self->MainConfigFetchYaml);
23+
res->SetYAML(Self->MainConfigYaml);
2424
}
2525
if (fetchStorage && Self->StorageConfigYaml) {
26-
auto metadata = NYamlConfig::GetStorageMetadata(*Self->StorageConfigYaml);
27-
metadata.Cluster = metadata.Cluster.value_or("unknown"); // TODO: fix this
28-
metadata.Version = metadata.Version.value_or(0) + 1;
29-
res->SetStorageYAML(NYamlConfig::ReplaceMetadata(*Self->StorageConfigYaml, metadata));
26+
res->SetStorageYAML(*Self->StorageConfigYaml);
3027
}
3128

3229
if (manual) {
@@ -48,6 +45,22 @@ namespace NKikimr::NStorage {
4845
NewYaml = request.HasYAML() ? std::make_optional(request.GetYAML()) : std::nullopt;
4946
NewStorageYaml = request.HasStorageYAML() ? std::make_optional(request.GetStorageYAML()) : std::nullopt;
5047

48+
// check if we are really changing something?
49+
if (NewYaml == Self->MainConfigYaml) {
50+
NewYaml.reset();
51+
}
52+
if (NewStorageYaml == Self->StorageConfigYaml) {
53+
NewStorageYaml.reset();
54+
}
55+
if (!NewYaml && !NewStorageYaml) {
56+
if (request.HasSwitchDedicatedStorageSection()) {
57+
return FinishWithError(TResult::ERROR, "switching dedicated storage section mode without providing any new config");
58+
} else {
59+
// finish this request prematurely: no configs are actually changed
60+
return Finish(Sender, SelfId(), PrepareResult(TResult::OK, std::nullopt).release(), 0, Cookie);
61+
}
62+
}
63+
5164
// start deriving a config from current one
5265
TString state;
5366
NKikimrBlobStorage::TStorageConfig config(*Self->StorageConfig);
@@ -67,6 +80,10 @@ namespace NKikimr::NStorage {
6780
throw yexception() << "missing or invalid kind provided";
6881
}
6982
version = metadata["version"].GetUIntegerRobust();
83+
if (metadata.Has("cluster") && metadata["cluster"] != AppData()->ClusterName) {
84+
throw yexception() << "cluster name mismatch: provided# " << metadata["cluster"]
85+
<< " expected# " << AppData()->ClusterName;
86+
}
7087

7188
state = TStringBuilder() << "validating " << expectedKind << " config section";
7289
if (!json.Has("config") || !json["config"].IsMap()) {

ydb/core/cms/console/console_configs_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void TConfigsManager::ReplaceMainConfigMetadata(const TString &config, bool forc
5656
try {
5757
if (!force) {
5858
auto metadata = NYamlConfig::GetMainMetadata(config);
59-
opCtx.Cluster = metadata.Cluster.value_or(TString("unknown"));
59+
opCtx.Cluster = metadata.Cluster.value_or(ClusterName);
6060
opCtx.Version = metadata.Version.value_or(0);
6161
} else {
6262
opCtx.Cluster = ClusterName;

ydb/core/grpc_services/rpc_config.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ class TReplaceStorageConfigRequest : public TBSConfigRequestGrpc<TReplaceStorage
232232
shim.SwitchDedicatedStorageSection,
233233
shim.DedicatedConfigMode,
234234
request->allow_unknown_fields() || request->bypass_checks(),
235-
request->bypass_checks());
235+
request->bypass_checks(),
236+
false /* TODO: implement */,
237+
false /* TODO: implement */);
236238
}
237239

238240
private:

ydb/core/grpc_services/rpc_config_base.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ class TBSConfigRequestGrpc : public TRpcOperationRequestActor<TDerived, TRequest
284284
if constexpr (std::is_same_v<TResultRecord, Ydb::Config::FetchConfigResult>) {
285285
TResultRecord result;
286286
const auto& record = ev->Get()->Record;
287+
if (record.HasErrorReason()) {
288+
const auto status = record.GetDisabledConfigV2()
289+
? Ydb::StatusIds::UNSUPPORTED
290+
: Ydb::StatusIds::INTERNAL_ERROR;
291+
self->Reply(status, TStringBuilder() << "failed to fetch config: " << record.GetErrorReason(),
292+
NKikimrIssues::TIssuesIds::DEFAULT_ERROR, self->ActorContext());
293+
return;
294+
}
287295
if (record.HasClusterYaml()) {
288296
auto conf = ev->Get()->Record.GetClusterYaml();
289297
auto metadata = NYamlConfig::GetMainMetadata(conf);
@@ -327,7 +335,10 @@ class TBSConfigRequestGrpc : public TRpcOperationRequestActor<TDerived, TRequest
327335
TResultRecord result;
328336
self->ReplyWithResult(Ydb::StatusIds::SUCCESS, result, self->ActorContext());
329337
} else {
330-
self->Reply(Ydb::StatusIds::INTERNAL_ERROR, TStringBuilder() << "failed to replace configuration: "
338+
const auto status = record.GetDisabledConfigV2()
339+
? Ydb::StatusIds::UNSUPPORTED
340+
: Ydb::StatusIds::INTERNAL_ERROR;
341+
self->Reply(status, TStringBuilder() << "failed to replace configuration: "
331342
<< NKikimrBlobStorage::TEvControllerReplaceConfigResponse::EStatus_Name(record.GetStatus())
332343
<< ": " << record.GetErrorReason(), NKikimrIssues::TIssuesIds::DEFAULT_ERROR, self->ActorContext());
333344
}

ydb/core/mind/bscontroller/bsc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ void TBlobStorageController::Handle(TEvBlobStorage::TEvControllerDistconfRequest
442442

443443
// commit it
444444
Execute(CreateTxCommitConfig(std::move(yamlConfig), std::make_optional(std::move(storageYaml)), std::nullopt,
445-
expectedStorageYamlConfigVersion, std::exchange(h, {})));
445+
expectedStorageYamlConfigVersion, std::exchange(h, {}), std::nullopt));
446446
break;
447447
}
448448

ydb/core/mind/bscontroller/commit_config.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace NKikimr::NBsController {
1515
std::optional<NKikimrBlobStorage::TStorageConfig> StorageConfig;
1616
std::optional<ui64> ExpectedStorageYamlConfigVersion;
1717
std::unique_ptr<IEventHandle> Handle;
18+
std::optional<bool> SwitchEnableConfigV2;
1819

1920
ui64 GenerationOnStart = 0;
2021
TString FingerprintOnStart;
@@ -23,13 +24,15 @@ namespace NKikimr::NBsController {
2324
TTxCommitConfig(TBlobStorageController *controller, std::optional<TYamlConfig>&& yamlConfig,
2425
std::optional<std::optional<TString>>&& storageYamlConfig,
2526
std::optional<NKikimrBlobStorage::TStorageConfig>&& storageConfig,
26-
std::optional<ui64> expectedStorageYamlConfigVersion, std::unique_ptr<IEventHandle> handle)
27+
std::optional<ui64> expectedStorageYamlConfigVersion, std::unique_ptr<IEventHandle> handle,
28+
std::optional<bool> switchEnableConfigV2)
2729
: TTransactionBase(controller)
2830
, YamlConfig(std::move(yamlConfig))
2931
, StorageYamlConfig(std::move(storageYamlConfig))
3032
, StorageConfig(std::move(storageConfig))
3133
, ExpectedStorageYamlConfigVersion(expectedStorageYamlConfigVersion)
3234
, Handle(std::move(handle))
35+
, SwitchEnableConfigV2(switchEnableConfigV2)
3336
{}
3437

3538
TTxType GetTxType() const override { return NBlobStorageController::TXTYPE_COMMIT_CONFIG; }
@@ -53,6 +56,9 @@ namespace NKikimr::NBsController {
5356
if (ExpectedStorageYamlConfigVersion) {
5457
row.Update<Schema::State::ExpectedStorageYamlConfigVersion>(*ExpectedStorageYamlConfigVersion);
5558
}
59+
if (SwitchEnableConfigV2) {
60+
row.Update<Schema::State::EnableConfigV2>(*SwitchEnableConfigV2);
61+
}
5662
return true;
5763
}
5864

@@ -104,6 +110,9 @@ namespace NKikimr::NBsController {
104110
if (update && Self->StorageYamlConfig) {
105111
update->SetStorageConfigVersion(NYamlConfig::GetStorageMetadata(*Self->StorageYamlConfig).Version.value_or(0));
106112
}
113+
if (SwitchEnableConfigV2) {
114+
Self->EnableConfigV2 = *SwitchEnableConfigV2;
115+
}
107116

108117
if (Handle) {
109118
TActivationContext::Send(Handle.release());
@@ -126,9 +135,10 @@ namespace NKikimr::NBsController {
126135
ITransaction* TBlobStorageController::CreateTxCommitConfig(std::optional<TYamlConfig>&& yamlConfig,
127136
std::optional<std::optional<TString>>&& storageYamlConfig,
128137
std::optional<NKikimrBlobStorage::TStorageConfig>&& storageConfig,
129-
std::optional<ui64> expectedStorageYamlConfigVersion, std::unique_ptr<IEventHandle> handle) {
138+
std::optional<ui64> expectedStorageYamlConfigVersion, std::unique_ptr<IEventHandle> handle,
139+
std::optional<bool> switchEnableConfigV2) {
130140
return new TTxCommitConfig(this, std::move(yamlConfig), std::move(storageYamlConfig), std::move(storageConfig),
131-
expectedStorageYamlConfigVersion, std::move(handle));
141+
expectedStorageYamlConfigVersion, std::move(handle), switchEnableConfigV2);
132142
}
133143

134144
} // namespace NKikimr::NBsController

0 commit comments

Comments
 (0)