Add keep_free_space_ratio param

This commit is contained in:
Igor Mineev 2019-05-21 20:57:17 +03:00
parent 320d509b42
commit a209f45f62
2 changed files with 25 additions and 3 deletions

View File

@ -22,11 +22,32 @@ DiskSelector::DiskSelector(const Poco::Util::AbstractConfiguration & config, con
throw Exception("Disk name can contain only alphanumeric and '_' (" + disk_name + ")", ErrorCodes::EXCESSIVE_ELEMENT_IN_CONFIG);
auto disk_config_prefix = config_prefix + "." + disk_name;
bool has_space_ratio = config.has(disk_config_prefix + ".keep_free_space_ratio");
if (config.has(disk_config_prefix + ".keep_free_space_bytes") && has_space_ratio)
throw Exception("Only one of 'keep_free_space_bytes' and 'keep_free_space_ratio' can be specified",
ErrorCodes::EXCESSIVE_ELEMENT_IN_CONFIG);
UInt64 keep_free_space_bytes = config.getUInt64(disk_config_prefix + ".keep_free_space_bytes", 0);
String path;
if (config.has(disk_config_prefix + ".path"))
path = config.getString(disk_config_prefix + ".path");
if (has_space_ratio) {
auto ratio = config.getDouble(config_prefix + ".keep_free_space_ratio");
if (ratio < 0 || ratio > 1)
throw Exception("'keep_free_space_ratio' have to be between 0 and 1",
ErrorCodes::EXCESSIVE_ELEMENT_IN_CONFIG);
String tmp_path = path;
if (tmp_path.empty())
tmp_path = default_path;
// Create tmp disk for getting total disk space.
keep_free_space_bytes = static_cast<UInt64>(Disk("tmp", tmp_path, 0).getTotalSpace() * ratio);
}
if (disk_name == default_disk_name)
{
has_default_disk = true;
@ -135,9 +156,10 @@ DiskSpaceMonitor::ReservationPtr Schema::Volume::reserve(UInt64 expected_size) c
return {};
size_t start_from = last_used.fetch_add(1u, std::memory_order_relaxed);
for (size_t i = 0; i != disks.size(); ++i)
size_t disks_num = disks.size();
for (size_t i = 0; i != disks_num; ++i)
{
size_t index = (start_from + i) % disks.size();
size_t index = (start_from + i) % disks_num;
auto reservation = DiskSpaceMonitor::tryToReserve(disks[index], expected_size);
if (reservation && *reservation)

View File

@ -190,7 +190,7 @@ MergeTreeData::MergeTreeData(
version_file_path = getFullPathOnDisk(schema.getAnyDisk()) + "format_version.txt";
///@TODO_IGR ASK LOGIC
auto version_file_exists = Poco::File(version_file_path).exists();
bool version_file_exists = Poco::File(version_file_path).exists();
// When data path or file not exists, ignore the format_version check
if (!attach || !version_file_exists)