2020-05-04 20:15:38 +00:00
|
|
|
#include "IVolume.h"
|
|
|
|
|
|
|
|
#include <Common/StringUtils/StringUtils.h>
|
|
|
|
#include <Common/quoteString.h>
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2022-04-26 14:58:09 +00:00
|
|
|
|
2020-05-04 20:15:38 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2020-10-20 15:10:24 +00:00
|
|
|
extern const int NO_ELEMENTS_IN_CONFIG;
|
2022-04-26 14:58:09 +00:00
|
|
|
extern const int EXCESSIVE_ELEMENT_IN_CONFIG;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VolumeLoadBalancing parseVolumeLoadBalancing(const String & config)
|
|
|
|
{
|
|
|
|
if (config == "round_robin")
|
|
|
|
return VolumeLoadBalancing::ROUND_ROBIN;
|
|
|
|
if (config == "least_used")
|
|
|
|
return VolumeLoadBalancing::LEAST_USED;
|
|
|
|
throw Exception(ErrorCodes::EXCESSIVE_ELEMENT_IN_CONFIG, "'{}' is not valid load_balancing value", config);
|
2020-05-28 05:38:55 +00:00
|
|
|
}
|
|
|
|
|
2022-04-26 14:58:09 +00:00
|
|
|
|
2020-05-04 20:15:38 +00:00
|
|
|
IVolume::IVolume(
|
2020-07-30 10:04:49 +00:00
|
|
|
String name_,
|
|
|
|
const Poco::Util::AbstractConfiguration & config,
|
|
|
|
const String & config_prefix,
|
|
|
|
DiskSelectorPtr disk_selector)
|
2020-05-04 20:15:38 +00:00
|
|
|
: name(std::move(name_))
|
2022-04-26 14:58:09 +00:00
|
|
|
, load_balancing(parseVolumeLoadBalancing(config.getString(config_prefix + ".load_balancing", "round_robin")))
|
2020-05-04 20:15:38 +00:00
|
|
|
{
|
|
|
|
Poco::Util::AbstractConfiguration::Keys keys;
|
|
|
|
config.keys(config_prefix, keys);
|
|
|
|
|
|
|
|
for (const auto & disk : keys)
|
|
|
|
{
|
|
|
|
if (startsWith(disk, "disk"))
|
|
|
|
{
|
|
|
|
auto disk_name = config.getString(config_prefix + "." + disk);
|
|
|
|
disks.push_back(disk_selector->get(disk_name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disks.empty())
|
2020-10-20 15:10:24 +00:00
|
|
|
throw Exception("Volume must contain at least one disk", ErrorCodes::NO_ELEMENTS_IN_CONFIG);
|
2020-05-04 20:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UInt64 IVolume::getMaxUnreservedFreeSpace() const
|
|
|
|
{
|
|
|
|
UInt64 res = 0;
|
|
|
|
for (const auto & disk : disks)
|
|
|
|
res = std::max(res, disk->getUnreservedSpace());
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|