@@ -52,6 +52,14 @@ namespace Setting
5252{
5353 extern const SettingsBool async_query_sending_for_remote;
5454 extern const SettingsBool async_socket_for_remote;
55+ extern const SettingsUInt64 input_format_parquet_max_block_size;
56+ extern const SettingsUInt64 max_block_size;
57+ extern const SettingsUInt64 max_insert_block_size;
58+ extern const SettingsUInt64 min_insert_block_size_rows;
59+ extern const SettingsUInt64 min_insert_block_size_bytes_for_materialized_views;
60+ extern const SettingsUInt64 min_external_table_block_size_rows;
61+ extern const SettingsUInt64 max_joined_block_size_rows;
62+ extern const SettingsMaxThreads max_threads;
5563 extern const SettingsUInt64 query_profiler_cpu_time_period_ns;
5664 extern const SettingsUInt64 query_profiler_real_time_period_ns;
5765 extern const SettingsBool use_hedged_requests;
@@ -101,51 +109,43 @@ void applySettingsQuirks(Settings & settings, LoggerPtr log)
101109
102110void doSettingsSanityCheckClamp (Settings & current_settings, LoggerPtr log)
103111{
104- auto get_current_value = [¤t_settings](const std::string_view name) -> Field
105- {
106- Field current_value;
107- bool has_current_value = current_settings.tryGet (name, current_value);
108- chassert (has_current_value);
109- return current_value;
110- };
111-
112- UInt64 max_threads = get_current_value (" max_threads" ).safeGet <UInt64>();
112+ UInt64 max_threads = current_settings[Setting::max_threads];
113113 UInt64 max_threads_max_value = 256 * getNumberOfCPUCoresToUse ();
114114 if (max_threads > max_threads_max_value)
115115 {
116116 if (log)
117117 LOG_WARNING (log, " Sanity check: Too many threads requested ({}). Reduced to {}" , max_threads, max_threads_max_value);
118- current_settings. set ( " max_threads" , max_threads_max_value) ;
118+ current_settings[Setting:: max_threads] = max_threads_max_value;
119119 }
120120
121121 static constexpr UInt64 max_sane_block_rows_size = 4294967296 ; // 2^32
122122
123123 using namespace std ::literals;
124- static constexpr std::array block_rows_settings{
125- " max_block_size" sv,
126- " max_insert_block_size" sv,
127- " min_insert_block_size_rows" sv,
128- " min_insert_block_size_bytes_for_materialized_views" sv,
129- " min_external_table_block_size_rows" sv,
130- " max_joined_block_size_rows" sv,
131- " input_format_parquet_max_block_size" sv};
132-
133- for (auto const setting : block_rows_settings)
134- {
135- if (auto block_size = get_current_value (setting).safeGet <UInt64>();
136- block_size > max_sane_block_rows_size)
137- {
138- if (log)
139- LOG_WARNING (log, " Sanity check: '{}' value is too high ({}). Reduced to {}" , setting, block_size, max_sane_block_rows_size);
140- current_settings.set (setting, max_sane_block_rows_size);
141- }
124+ #define CHECK_MAX_VALUE (SETTING_VALUE ) \
125+ if (UInt64 block_size = current_settings[Setting::SETTING_VALUE]; block_size > max_sane_block_rows_size) \
126+ { \
127+ if (log) \
128+ LOG_WARNING ( \
129+ log, " Sanity check: '{}' value is too high ({}). Reduced to {}" , #SETTING_VALUE, block_size, max_sane_block_rows_size); \
130+ current_settings[Setting::SETTING_VALUE] = max_sane_block_rows_size; \
142131 }
143132
144- if (auto max_block_size = get_current_value (" max_block_size" ).safeGet <UInt64>(); max_block_size == 0 )
133+ CHECK_MAX_VALUE (max_block_size)
134+ CHECK_MAX_VALUE (max_insert_block_size)
135+ CHECK_MAX_VALUE (min_insert_block_size_rows)
136+ CHECK_MAX_VALUE (min_insert_block_size_bytes_for_materialized_views)
137+ CHECK_MAX_VALUE (min_external_table_block_size_rows)
138+ CHECK_MAX_VALUE (max_joined_block_size_rows)
139+ CHECK_MAX_VALUE (input_format_parquet_max_block_size)
140+
141+ #undef CHECK_MAX_VALUE
142+
143+
144+ if (auto max_block_size = current_settings[Setting::max_block_size]; max_block_size == 0 )
145145 {
146146 if (log)
147147 LOG_WARNING (log, " Sanity check: 'max_block_size' cannot be 0. Set to default value {}" , DEFAULT_BLOCK_SIZE);
148- current_settings. set ( " max_block_size" , DEFAULT_BLOCK_SIZE) ;
148+ current_settings[Setting:: max_block_size] = DEFAULT_BLOCK_SIZE;
149149 }
150150}
151151
0 commit comments