Don't allow 0 for max_block_size

This commit is contained in:
Antonio Andelic 2024-05-15 10:35:10 +02:00
parent 18858ca26f
commit 13fc7c7cf8
5 changed files with 24 additions and 20 deletions

View File

@ -92,7 +92,7 @@ void applySettingsQuirks(Settings & settings, LoggerPtr log)
void doSettingsSanityCheckClamp(Settings & current_settings, LoggerPtr log)
{
auto getCurrentValue = [&current_settings](const std::string_view name) -> Field
auto get_current_value = [&current_settings](const std::string_view name) -> Field
{
Field current_value;
bool has_current_value = current_settings.tryGet(name, current_value);
@ -100,7 +100,7 @@ void doSettingsSanityCheckClamp(Settings & current_settings, LoggerPtr log)
return current_value;
};
UInt64 max_threads = getCurrentValue("max_threads").get<UInt64>();
UInt64 max_threads = get_current_value("max_threads").get<UInt64>();
UInt64 max_threads_max_value = 256 * getNumberOfPhysicalCPUCores();
if (max_threads > max_threads_max_value)
{
@ -109,7 +109,7 @@ void doSettingsSanityCheckClamp(Settings & current_settings, LoggerPtr log)
current_settings.set("max_threads", max_threads_max_value);
}
constexpr UInt64 max_sane_block_rows_size = 4294967296; // 2^32
static constexpr UInt64 max_sane_block_rows_size = 4294967296; // 2^32
std::unordered_set<String> block_rows_settings{
"max_block_size",
"max_insert_block_size",
@ -120,7 +120,7 @@ void doSettingsSanityCheckClamp(Settings & current_settings, LoggerPtr log)
"input_format_parquet_max_block_size"};
for (auto const & setting : block_rows_settings)
{
auto block_size = getCurrentValue(setting).get<UInt64>();
auto block_size = get_current_value(setting).get<UInt64>();
if (block_size > max_sane_block_rows_size)
{
if (log)
@ -128,5 +128,13 @@ void doSettingsSanityCheckClamp(Settings & current_settings, LoggerPtr log)
current_settings.set(setting, max_sane_block_rows_size);
}
}
if (auto max_block_size = get_current_value("max_block_size").get<UInt64>(); max_block_size == 0)
{
if (log)
LOG_WARNING(log, "Sanity check: 'max_block_size' cannot be 0. Set to default value {}", DEFAULT_BLOCK_SIZE);
current_settings.set("max_block_size", DEFAULT_BLOCK_SIZE);
}
}
}

View File

@ -176,9 +176,8 @@ protected:
{
std::lock_guard lock(ranges_state->mutex);
UInt64 need = base_block_size_;
bool without_block_size_limit = need == 0;
UInt64 need = base_block_size_;
UInt64 size = 0; /// how many item found.
/// find start
@ -186,21 +185,14 @@ protected:
end = start;
/// find end
while (without_block_size_limit || need != 0)
while (need != 0)
{
UInt128 can_provide = end.offset_in_ranges == ranges.size() ? static_cast<UInt128>(0)
: ranges[end.offset_in_ranges].size - end.offset_in_range;
if (can_provide == 0)
break;
if (without_block_size_limit)
{
end.offset_in_ranges++;
end.offset_in_range = 0;
size += static_cast<UInt64>(can_provide);
}
else if (can_provide > need)
if (can_provide > need)
{
end.offset_in_range += need;
size += need;
@ -535,7 +527,7 @@ Pipe ReadFromSystemNumbersStep::makePipe()
checkLimits(size_t(total_size));
if (max_block_size != 0 && total_size / max_block_size < num_streams)
if (total_size / max_block_size < num_streams)
num_streams = static_cast<size_t>(total_size / max_block_size);
if (num_streams == 0)

View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CUR_DIR"/../shell_config.sh
$CLICKHOUSE_CLIENT -q "SELECT count(*) FROM numbers(10) AS a, numbers(11) AS b, numbers(12) AS c SETTINGS max_block_size = 0" 2>&1 | grep -q "Sanity check: 'max_block_size' cannot be 0. Set to default value" && echo "OK" || echo "FAIL"

View File

@ -1,2 +0,0 @@
SELECT count(*) FROM numbers(10) AS a, numbers(11) AS b, numbers(12) AS c SETTINGS max_block_size = 0;
SELECT count(*) FROM numbers(10) AS a, numbers(11) AS b, numbers(12) AS c SETTINGS max_block_size = 1;