Default disk initialization bug fix. Stylefix.

This commit is contained in:
Igor Mineev 2019-04-21 23:23:02 +03:00
parent 79abe85328
commit e4c8467b49
3 changed files with 27 additions and 22 deletions

View File

@ -24,6 +24,7 @@ DiskSelector::DiskSelector(const Poco::Util::AbstractConfiguration & config, con
config.keys(config_prefix, keys);
constexpr auto default_disk_name = "default";
bool has_default_disk = false;
for (const auto & disk_name : keys)
{
if (!isAlphaNumeric(disk_name))
@ -37,6 +38,7 @@ DiskSelector::DiskSelector(const Poco::Util::AbstractConfiguration & config, con
if (disk_name == default_disk_name)
{
has_default_disk = true;
if (!path.empty())
throw Exception("It is not possible to specify default disk path", ErrorCodes::UNKNOWN_ELEMENT_IN_CONFIG);
disks.emplace(disk_name, std::make_shared<const Disk>(disk_name, default_path, keep_free_space_bytes));
@ -48,6 +50,8 @@ DiskSelector::DiskSelector(const Poco::Util::AbstractConfiguration & config, con
disks.emplace(disk_name, std::make_shared<const Disk>(disk_name, path, keep_free_space_bytes));
}
}
if (!has_default_disk)
disks.emplace(default_disk_name, std::make_shared<const Disk>(default_disk_name, default_path, 0));
}
const DiskPtr & DiskSelector::operator[](const String & name) const
@ -83,9 +87,8 @@ Schema::Volume::Volume(const Poco::Util::AbstractConfiguration & config, const s
}
}
if (disks.empty()) {
if (disks.empty())
throw Exception("Volume must contain at least one disk", ErrorCodes::EXCESSIVE_ELEMENT_IN_CONFIG);
}
auto has_max_bytes = config.has(config_prefix + ".max_data_part_size_bytes");
auto has_max_ratio = config.has(config_prefix + ".max_data_part_size_ratio");
@ -95,11 +98,15 @@ Schema::Volume::Volume(const Poco::Util::AbstractConfiguration & config, const s
ErrorCodes::EXCESSIVE_ELEMENT_IN_CONFIG);
}
if (has_max_bytes) {
if (has_max_bytes)
{
max_data_part_size = config.getUInt64(config_prefix + ".max_data_part_size_bytes");
} else if (has_max_ratio) {
}
else if (has_max_ratio)
{
auto ratio = config.getDouble(config_prefix + ".max_data_part_size_bytes");
if (ratio < 0 and ratio > 1) {
if (ratio < 0 and ratio > 1)
{
throw Exception("'max_data_part_size_bytes' have to be between 0 and 1",
ErrorCodes::EXCESSIVE_ELEMENT_IN_CONFIG);
}
@ -107,7 +114,9 @@ Schema::Volume::Volume(const Poco::Util::AbstractConfiguration & config, const s
for (const auto & disk : disks)
sum_size += disk->getTotalSpace();
max_data_part_size = static_cast<decltype(max_data_part_size)>(sum_size * ratio);
} else {
}
else
{
max_data_part_size = std::numeric_limits<UInt64>::max();
}
}
@ -151,9 +160,8 @@ Schema::Schema(const Poco::Util::AbstractConfiguration & config, const std::stri
ErrorCodes::UNKNOWN_ELEMENT_IN_CONFIG);
volumes.emplace_back(config, config_prefix + "." + name, disks);
}
if (volumes.empty()) {
if (volumes.empty())
throw Exception("Schema must contain at least one Volume", ErrorCodes::EXCESSIVE_ELEMENT_IN_CONFIG);
}
}
Schema::Disks Schema::getDisks() const

View File

@ -171,7 +171,8 @@ public:
std::lock_guard lock(DiskSpaceMonitor::mutex);
if (size > unreserved) {
if (size > unreserved)
{
/// Can not reserve, not enough space
///@TODO_IGR ASK metric_increment?
size = 0;

View File

@ -165,10 +165,10 @@ MergeTreeData::MergeTreeData(
/// Creating directories, if not exist.
for (const String & path : getFullPaths())
{
std::cerr << "Create path " << path << " by " << table_name << std::endl;
Poco::File(path).createDirectories();
Poco::File(path + "detached").createDirectory();
if (Poco::File{path + "format_version.txt"}.exists()) {
if (Poco::File{path + "format_version.txt"}.exists())
{
if (!version_file_path.empty())
{
LOG_ERROR(log, "Duplication of version file " << version_file_path << " and " << path << "format_file.txt");
@ -179,9 +179,8 @@ MergeTreeData::MergeTreeData(
}
/// If not choose any
if (version_file_path.empty()) {
if (version_file_path.empty())
version_file_path = schema.getDisks()[0]->getPath() + "format_version.txt";
}
///@TODO_IGR ASK LOGIC
auto version_file_exists = Poco::File(version_file_path).exists();
@ -1037,11 +1036,8 @@ void MergeTreeData::dropAllData()
LOG_TRACE(log, "dropAllData: removing data from filesystem.");
for (auto && full_data_path : getFullPaths()) {
for (auto && full_data_path : getFullPaths())
Poco::File(full_data_path).remove(true);
std::cerr << full_data_path << " removed by " << table_name << std::endl;
}
LOG_TRACE(log, "dropAllData: done.");
}
@ -2422,7 +2418,6 @@ MergeTreeData::DataPartsVector MergeTreeData::getAllDataPartsVector(MergeTreeDat
DiskSpaceMonitor::ReservationPtr MergeTreeData::reserveSpaceForPart(UInt64 expected_size)
{
// std::cerr << "Exp size " << expected_size << std::endl;
constexpr UInt64 SIZE_1MB = 1ull << 20; ///@TODO_IGR ASK Is it OK?
constexpr UInt64 MAGIC_CONST = 1;
@ -2648,15 +2643,16 @@ DiskSpaceMonitor::ReservationPtr MergeTreeData::reserveSpaceAtDisk(UInt64 expect
return schema.reserve(expected_size);
}
String MergeTreeData::getFullPathOnDisk(const DiskPtr & disk) const {
String MergeTreeData::getFullPathOnDisk(const DiskPtr & disk) const
{
return disk->getPath() + escapeForFileName(database_name) + '/' + escapeForFileName(table_name) + '/';
}
Strings MergeTreeData::getFullPaths() const {
Strings MergeTreeData::getFullPaths() const
{
Strings res;
for (const auto & disk : schema.getDisks()) {
for (const auto & disk : schema.getDisks())
res.push_back(getFullPathOnDisk(disk));
}
return res;
}