Skip to content

Commit d2a975d

Browse files
authored
Merge 42a1cb3 into 787a642
2 parents 787a642 + 42a1cb3 commit d2a975d

File tree

1 file changed

+56
-56
lines changed

1 file changed

+56
-56
lines changed

ydb/core/driver_lib/cli_utils/cli_cmds_server.cpp

+56-56
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,15 @@ class TClientCommandServerBase : public TClientCommand {
285285
config.Opts->SetFreeArgDefaultTitle("PATH", "path to protobuf file; files are merged in order in which they are enlisted");
286286
}
287287

288-
template<typename TProto>
289-
TProto *MutableConfigPart(TConfig& config, const char *optname,
290-
bool (NKikimrConfig::TAppConfig::*hasConfig)() const,
291-
const TProto& (NKikimrConfig::TAppConfig::*getConfig)() const,
292-
TProto* (NKikimrConfig::TAppConfig::*mutableConfig)(),
293-
ui32 kind,
294-
TCallContext callCtx) {
295-
TProto *res = nullptr;
288+
template<typename TFieldTag>
289+
auto MutableConfigPart(TConfig& config, const char *optname,
290+
TFieldTag tag,
291+
TCallContext callCtx) -> decltype((AppConfig.*std::get<2>(NKikimrConfig::TAppConfig::GetFieldAccessorsByFieldTag(tag)))())
292+
{
293+
auto [hasConfig, getConfig, mutableConfig] = NKikimrConfig::TAppConfig::GetFieldAccessorsByFieldTag(tag);
294+
ui32 kind = NKikimrConfig::TAppConfig::GetFieldIdByFieldTag(tag);
295+
296+
typename std::remove_reference<decltype(*(AppConfig.*mutableConfig)())>::type *res = nullptr;
296297
if ((AppConfig.*hasConfig)()) {
297298
return nullptr; // this field is already provided in AppConfig, so we don't overwrite it
298299
}
@@ -310,15 +311,18 @@ class TClientCommandServerBase : public TClientCommand {
310311
return res;
311312
}
312313

313-
template<typename TProto>
314-
TProto *MutableConfigPartMerge(TConfig& config, const char *optname,
315-
TProto* (NKikimrConfig::TAppConfig::*mutableConfig)(),
316-
ui32 kind,
317-
TCallContext callCtx) {
318-
TProto *res = nullptr;
314+
template<typename TFieldTag>
315+
auto MutableConfigPartMerge(TConfig& config, const char *optname,
316+
TFieldTag tag,
317+
TCallContext callCtx) -> decltype((AppConfig.*std::get<2>(NKikimrConfig::TAppConfig::GetFieldAccessorsByFieldTag(tag)))())
318+
{
319+
auto mutableConfig = std::get<2>(NKikimrConfig::TAppConfig::GetFieldAccessorsByFieldTag(tag));
320+
ui32 kind = NKikimrConfig::TAppConfig::GetFieldIdByFieldTag(tag);
321+
322+
typename std::remove_reference<decltype(*(AppConfig.*mutableConfig)())>::type *res = nullptr;
319323

320324
if (config.ParseResult->Has(optname)) {
321-
TProto cfg;
325+
typename std::remove_reference<decltype(*(AppConfig.*mutableConfig)())>::type cfg;
322326
bool success = ParsePBFromFile(config.ParseResult->Get(optname), &cfg);
323327
Y_ABORT_UNLESS(success);
324328
res = (AppConfig.*mutableConfig)();
@@ -361,19 +365,15 @@ class TClientCommandServerBase : public TClientCommand {
361365
virtual void Parse(TConfig& config) override {
362366
TClientCommand::Parse(config);
363367

364-
#define OPTION(NAME, FIELD) MutableConfigPart(config, NAME, &NKikimrConfig::TAppConfig::Has##FIELD, \
365-
&NKikimrConfig::TAppConfig::Get##FIELD, &NKikimrConfig::TAppConfig::Mutable##FIELD, \
366-
(ui32)NKikimrConsole::TConfigItem:: FIELD ## Item, TCallContext{__FILE__, __LINE__})
367-
#define OPTION_MERGE(NAME, FIELD) MutableConfigPartMerge(config, NAME, &NKikimrConfig::TAppConfig::Mutable##FIELD, \
368-
(ui32)NKikimrConsole::TConfigItem:: FIELD ## Item, TCallContext{__FILE__, __LINE__})
368+
using TCfg = NKikimrConfig::TAppConfig;
369369

370-
OPTION("auth-file", AuthConfig);
370+
MutableConfigPart(config, "auth-file", TCfg::TAuthConfigFieldTag{}, CALL_CTX());
371371
LoadBootstrapConfig(config);
372372
LoadYamlConfig(CALL_CTX());
373-
OPTION_MERGE("auth-token-file", AuthConfig);
373+
MutableConfigPartMerge(config, "auth-token-file", TCfg::TAuthConfigFieldTag{}, CALL_CTX());
374374

375375
// start memorylog as soon as possible
376-
if (auto mem = OPTION("memorylog-file", MemoryLogConfig)) {
376+
if (auto mem = MutableConfigPart(config, "memorylog-file", TCfg::TMemoryLogConfigFieldTag{}, CALL_CTX())) {
377377
if (mem->HasLogBufferSize() && mem->GetLogBufferSize() > 0) {
378378
if (mem->HasLogGrainSize() && mem->GetLogGrainSize() > 0) {
379379
TMemoryLog::CreateMemoryLogBuffer(mem->GetLogBufferSize(), mem->GetLogGrainSize());
@@ -384,7 +384,7 @@ class TClientCommandServerBase : public TClientCommand {
384384
}
385385
}
386386

387-
OPTION("naming-file", NameserviceConfig);
387+
MutableConfigPart(config, "naming-file", TCfg::TNameserviceConfigFieldTag{}, CALL_CTX());
388388

389389
if (config.ParseResult->Has("node")) {
390390
if (NodeIdValue == "static") {
@@ -460,16 +460,16 @@ class TClientCommandServerBase : public TClientCommand {
460460

461461
LoadYamlConfig(CALL_CTX());
462462

463-
OPTION("sys-file", ActorSystemConfig);
463+
MutableConfigPart(config, "sys-file", TCfg::TActorSystemConfigFieldTag{}, CALL_CTX());
464464
if (!AppConfig.HasActorSystemConfig()) {
465465
AppConfig.MutableActorSystemConfig()->CopyFrom(*DummyActorSystemConfig());
466466
TRACE_CONFIG_CHANGE_INPLACE_T(ActorSystemConfig, SetExplicitly);
467467
}
468468

469-
OPTION("domains-file", DomainsConfig);
470-
OPTION("bs-file", BlobStorageConfig);
469+
MutableConfigPart(config, "domains-file", TCfg::TDomainsConfigFieldTag{}, CALL_CTX());
470+
MutableConfigPart(config, "bs-file", TCfg::TBlobStorageConfigFieldTag{}, CALL_CTX());
471471

472-
if (auto logConfig = OPTION("log-file", LogConfig)) {
472+
if (auto logConfig = MutableConfigPart(config, "log-file", TCfg::TLogConfigFieldTag{}, CALL_CTX())) {
473473
if (config.ParseResult->Has("syslog"))
474474
logConfig->SetSysLog(true);
475475
if (config.ParseResult->Has("log-level"))
@@ -495,45 +495,45 @@ class TClientCommandServerBase : public TClientCommand {
495495
TRACE_CONFIG_CHANGE_INPLACE_T(LogConfig, UpdateExplicitly);
496496
}
497497

498-
if (auto interconnectConfig = OPTION("ic-file", InterconnectConfig)) {
498+
if (auto interconnectConfig = MutableConfigPart(config, "ic-file", TCfg::TInterconnectConfigFieldTag{}, CALL_CTX())) {
499499
if (config.ParseResult->Has("tcp")) {
500500
interconnectConfig->SetStartTcp(true);
501501
TRACE_CONFIG_CHANGE_INPLACE_T(InterconnectConfig, UpdateExplicitly);
502502
}
503503
}
504504

505-
OPTION("channels-file", ChannelProfileConfig);
505+
MutableConfigPart(config, "channels-file", TCfg::TChannelProfileConfigFieldTag{}, CALL_CTX());
506506

507-
if (auto bootstrapConfig = OPTION("bootstrap-file", BootstrapConfig)) {
507+
if (auto bootstrapConfig = MutableConfigPart(config, "bootstrap-file", TCfg::TBootstrapConfigFieldTag{}, CALL_CTX())) {
508508
bootstrapConfig->MutableCompileServiceConfig()->SetInflightLimit(CompileInflightLimit);
509509
TRACE_CONFIG_CHANGE_INPLACE_T(BootstrapConfig, UpdateExplicitly);
510510
}
511511

512-
OPTION("vdisk-file", VDiskConfig);
513-
OPTION("drivemodel-file", DriveModelConfig);
514-
OPTION("grpc-file", GRpcConfig);
515-
OPTION("dyn-nodes-file", DynamicNameserviceConfig);
516-
OPTION("cms-file", CmsConfig);
517-
OPTION("pq-file", PQConfig);
518-
OPTION("pqcd-file", PQClusterDiscoveryConfig);
519-
OPTION("netclassifier-file", NetClassifierConfig);
520-
OPTION("auth-file", AuthConfig);
521-
OPTION_MERGE("auth-token-file", AuthConfig);
522-
OPTION("key-file", KeyConfig);
523-
OPTION("pdisk-key-file", PDiskKeyConfig);
524-
OPTION("sqs-file", SqsConfig);
525-
OPTION("http-proxy-file", HttpProxyConfig);
526-
OPTION("public-http-file", PublicHttpConfig);
527-
OPTION("feature-flags-file", FeatureFlags);
528-
OPTION("rb-file", ResourceBrokerConfig);
529-
OPTION("metering-file", MeteringConfig);
530-
OPTION("audit-file", AuditConfig);
531-
OPTION("kqp-file", KQPConfig);
532-
OPTION("incrhuge-file", IncrHugeConfig);
533-
OPTION("alloc-file", AllocatorConfig);
534-
OPTION("fq-file", FederatedQueryConfig);
535-
OPTION(nullptr, TracingConfig);
536-
OPTION(nullptr, FailureInjectionConfig);
512+
MutableConfigPart(config, "vdisk-file", TCfg::TVDiskConfigFieldTag{}, CALL_CTX());
513+
MutableConfigPart(config, "drivemodel-file", TCfg::TDriveModelConfigFieldTag{}, CALL_CTX());
514+
MutableConfigPart(config, "grpc-file", TCfg::TGRpcConfigFieldTag{}, CALL_CTX());
515+
MutableConfigPart(config, "dyn-nodes-file", TCfg::TDynamicNameserviceConfigFieldTag{}, CALL_CTX());
516+
MutableConfigPart(config, "cms-file", TCfg::TCmsConfigFieldTag{}, CALL_CTX());
517+
MutableConfigPart(config, "pq-file", TCfg::TPQConfigFieldTag{}, CALL_CTX());
518+
MutableConfigPart(config, "pqcd-file", TCfg::TPQClusterDiscoveryConfigFieldTag{}, CALL_CTX());
519+
MutableConfigPart(config, "netclassifier-file", TCfg::TNetClassifierConfigFieldTag{}, CALL_CTX());
520+
MutableConfigPart(config, "auth-file", TCfg::TAuthConfigFieldTag{}, CALL_CTX());
521+
MutableConfigPartMerge(config, "auth-token-file", TCfg::TAuthConfigFieldTag{}, CALL_CTX());
522+
MutableConfigPart(config, "key-file", TCfg::TKeyConfigFieldTag{}, CALL_CTX());
523+
MutableConfigPart(config, "pdisk-key-file", TCfg::TPDiskKeyConfigFieldTag{}, CALL_CTX());
524+
MutableConfigPart(config, "sqs-file", TCfg::TSqsConfigFieldTag{}, CALL_CTX());
525+
MutableConfigPart(config, "http-proxy-file", TCfg::THttpProxyConfigFieldTag{}, CALL_CTX());
526+
MutableConfigPart(config, "public-http-file", TCfg::TPublicHttpConfigFieldTag{}, CALL_CTX());
527+
MutableConfigPart(config, "feature-flags-file", TCfg::TFeatureFlagsFieldTag{}, CALL_CTX());
528+
MutableConfigPart(config, "rb-file", TCfg::TResourceBrokerConfigFieldTag{}, CALL_CTX());
529+
MutableConfigPart(config, "metering-file", TCfg::TMeteringConfigFieldTag{}, CALL_CTX());
530+
MutableConfigPart(config, "audit-file", TCfg::TAuditConfigFieldTag{}, CALL_CTX());
531+
MutableConfigPart(config, "kqp-file", TCfg::TKQPConfigFieldTag{}, CALL_CTX());
532+
MutableConfigPart(config, "incrhuge-file", TCfg::TIncrHugeConfigFieldTag{}, CALL_CTX());
533+
MutableConfigPart(config, "alloc-file", TCfg::TAllocatorConfigFieldTag{}, CALL_CTX());
534+
MutableConfigPart(config, "fq-file", TCfg::TFederatedQueryConfigFieldTag{}, CALL_CTX());
535+
MutableConfigPart(config, nullptr, TCfg::TTracingConfigFieldTag{}, CALL_CTX());
536+
MutableConfigPart(config, nullptr, TCfg::TFailureInjectionConfigFieldTag{}, CALL_CTX());
537537

538538
if (!AppConfig.HasAllocatorConfig()) {
539539
AppConfig.MutableAllocatorConfig()->CopyFrom(*DummyAllocatorConfig());

0 commit comments

Comments
 (0)