Skip to content

Commit 587d6bb

Browse files
committed
Refactor TConfSetting
commit_hash:2ca0a7e131758036bd15ba9e58dce176b9eff6c9
1 parent ae913bc commit 587d6bb

File tree

3 files changed

+301
-227
lines changed

3 files changed

+301
-227
lines changed

yql/essentials/providers/common/config/yql_dispatch.h

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,23 @@ TParser<TInstant> GetDefaultParser<TInstant>();
7676
YQL_PRIMITIVE_SETTING_PARSER_TYPES(YQL_DECLARE_SETTING_PARSER)
7777
YQL_CONTAINER_SETTING_PARSER_TYPES(YQL_DECLARE_SETTING_PARSER)
7878

79+
#ifdef YQL_BETTER_CONF_SETTING_API
80+
template<typename TType>
81+
TMaybe<TType> GetValue(const NCommon::TConfSetting<TType, NCommon::EConfSettingType::StaticPerCluster>& setting, const TString& cluster) {
82+
return setting.Get(cluster);
83+
}
84+
85+
template<typename TType>
86+
TMaybe<TType> GetValue(const NCommon::TConfSetting<TType, NCommon::EConfSettingType::Dynamic>& setting, const TString& cluster) {
87+
return setting.Get(cluster);
88+
}
89+
90+
template<typename TType>
91+
TMaybe<TType> GetValue(const NCommon::TConfSetting<TType, NCommon::EConfSettingType::Static>& setting, const TString& cluster) {
92+
Y_UNUSED(cluster);
93+
return setting.Get();
94+
}
95+
#else
7996
template<typename TType>
8097
TMaybe<TType> GetValue(const NCommon::TConfSetting<TType, true, false>& setting, const TString& cluster) {
8198
return setting.Get(cluster);
@@ -96,6 +113,7 @@ TMaybe<TType> GetValue(const NCommon::TConfSetting<TType, false, false>& setting
96113
Y_UNUSED(cluster);
97114
return setting.Get();
98115
}
116+
#endif
99117

100118
}
101119

@@ -135,15 +153,23 @@ class TSettingDispatcher: public TThrRefBase {
135153
TString Name_;
136154
};
137155

156+
#ifdef YQL_BETTER_CONF_SETTING_API
157+
template <typename TType, EConfSettingType SettingType>
158+
#else
138159
template <typename TType, bool RUNTIME, bool PERCLUSTER>
139-
class TSettingHandlerImpl: public TSettingHandler {
160+
#endif
161+
class TSettingHandlerImpl : public TSettingHandler {
140162
public:
141163
using TValueCallback = std::function<void(const TString&, TType)>;
142164

143165
private:
144166
friend class TSettingDispatcher;
145167

168+
#ifdef YQL_BETTER_CONF_SETTING_API
169+
TSettingHandlerImpl(const TString& name, TConfSetting<TType, SettingType>& setting)
170+
#else
146171
TSettingHandlerImpl(const TString& name, TConfSetting<TType, RUNTIME, PERCLUSTER>& setting)
172+
#endif
147173
: TSettingHandler(name)
148174
, Setting_(setting)
149175
, Parser_(::NYql::NPrivate::GetDefaultParser<TType>())
@@ -322,8 +348,13 @@ class TSettingDispatcher: public TThrRefBase {
322348
}
323349

324350
private:
351+
#ifdef YQL_BETTER_CONF_SETTING_API
352+
TConfSetting<TType, SettingType>& Setting_;
353+
TMaybe<TConfSetting<TType, SettingType>> Defaul_;
354+
#else
325355
TConfSetting<TType, RUNTIME, PERCLUSTER>& Setting_;
326356
TMaybe<TConfSetting<TType, RUNTIME, PERCLUSTER>> Defaul_;
357+
#endif
327358
::NYql::NPrivate::TParser<TType> Parser_;
328359
TValueCallback ValueSetter_;
329360
TVector<TValueCallback> Validators_;
@@ -349,9 +380,15 @@ class TSettingDispatcher: public TThrRefBase {
349380
ValidClusters.insert(cluster);
350381
}
351382

383+
#ifdef YQL_BETTER_CONF_SETTING_API
384+
template <typename TType, EConfSettingType SettingType>
385+
TSettingHandlerImpl<TType, SettingType>& AddSetting(const TString& name, TConfSetting<TType, SettingType>& setting) {
386+
TIntrusivePtr<TSettingHandlerImpl<TType, SettingType>> handler = new TSettingHandlerImpl<TType, SettingType>(name, setting);
387+
#else
352388
template <typename TType, bool RUNTIME, bool PERCLUSTER>
353389
TSettingHandlerImpl<TType, RUNTIME, PERCLUSTER>& AddSetting(const TString& name, TConfSetting<TType, RUNTIME, PERCLUSTER>& setting) {
354390
TIntrusivePtr<TSettingHandlerImpl<TType, RUNTIME, PERCLUSTER>> handler = new TSettingHandlerImpl<TType, RUNTIME, PERCLUSTER>(name, setting);
391+
#endif
355392
if (!Handlers.insert({NormalizeName(name), handler}).second) {
356393
ythrow yexception() << "Duplicate configuration setting name " << name.Quote();
357394
}

yql/essentials/providers/common/config/yql_setting.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@ namespace NCommon {
1212

1313
const TString ALL_CLUSTERS = "$all";
1414

15-
// TODO: replace RUNTIME/PERCLUSTER with enum
15+
enum class EConfSettingType {
16+
Static,
17+
StaticPerCluster,
18+
Dynamic,
19+
};
20+
21+
#ifdef YQL_BETTER_CONF_SETTING_API
22+
template <typename TType, EConfSettingType SettingType = EConfSettingType::Dynamic>
23+
#else
1624
template <typename TType, bool RUNTIME = true, bool PERCLUSTER = false>
25+
#endif
1726
class TConfSetting {
1827
public:
1928
TConfSetting() = default;
@@ -25,7 +34,11 @@ class TConfSetting {
2534
~TConfSetting() = default;
2635

2736
bool IsRuntime() const {
37+
#ifdef YQL_BETTER_CONF_SETTING_API
38+
return SettingType == EConfSettingType::Dynamic;
39+
#else
2840
return RUNTIME;
41+
#endif
2942
}
3043

3144
TType& operator[](const TString& cluster) {
@@ -81,7 +94,11 @@ class TConfSetting {
8194
};
8295

8396
template <typename TType>
97+
#ifdef YQL_BETTER_CONF_SETTING_API
98+
class TConfSetting<TType, EConfSettingType::Static> {
99+
#else
84100
class TConfSetting<TType, false, false> {
101+
#endif
85102
public:
86103
TConfSetting() = default;
87104
TConfSetting(const TType& value)

0 commit comments

Comments
 (0)