ClickHouse/src/Storages/MergeTree/DropPartsRanges.cpp

66 lines
2.1 KiB
C++
Raw Normal View History

2021-07-05 19:58:36 +00:00
#include <Storages/MergeTree/DropPartsRanges.h>
namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
2021-07-06 08:36:39 +00:00
bool DropPartsRanges::isAffectedByDropRange(const std::string & new_part_name, std::string & postpone_reason) const
2021-07-05 19:58:36 +00:00
{
2021-07-06 08:36:39 +00:00
if (new_part_name.empty())
2021-07-05 19:58:36 +00:00
return false;
2021-07-06 08:36:39 +00:00
MergeTreePartInfo entry_info = MergeTreePartInfo::fromPartName(new_part_name, format_version);
2021-07-05 19:58:36 +00:00
for (const auto & [znode, drop_range] : drop_ranges)
{
if (!drop_range.isDisjoint(entry_info))
{
2021-07-06 10:58:53 +00:00
postpone_reason = fmt::format("Has DROP RANGE affecting entry {} producing part {}. Will postpone it's execution.", drop_range.getPartName(), new_part_name);
2021-07-05 19:58:36 +00:00
return true;
}
}
return false;
}
2021-07-06 08:36:39 +00:00
bool DropPartsRanges::isAffectedByDropRange(const ReplicatedMergeTreeLogEntry & entry, std::string & postpone_reason) const
{
return isAffectedByDropRange(entry.new_part_name, postpone_reason);
}
2021-07-06 10:58:53 +00:00
void DropPartsRanges::addDropRange(const ReplicatedMergeTreeLogEntryPtr & entry)
2021-07-05 19:58:36 +00:00
{
if (entry->type != ReplicatedMergeTreeLogEntry::DROP_RANGE)
throw Exception(ErrorCodes::LOGICAL_ERROR, "Trying to add entry of type {} to drop ranges, expected DROP_RANGE", entry->typeToString());
MergeTreePartInfo entry_info = MergeTreePartInfo::fromPartName(*entry->getDropRange(format_version), format_version);
drop_ranges.emplace(entry->znode_name, entry_info);
}
2021-07-06 10:58:53 +00:00
void DropPartsRanges::removeDropRange(const ReplicatedMergeTreeLogEntryPtr & entry)
2021-07-05 19:58:36 +00:00
{
if (entry->type != ReplicatedMergeTreeLogEntry::DROP_RANGE)
throw Exception(ErrorCodes::LOGICAL_ERROR, "Trying to remove entry of type {} from drop ranges, expected DROP_RANGE", entry->typeToString());
2021-07-06 16:51:23 +00:00
auto it = drop_ranges.find(entry->znode_name);
assert(it != drop_ranges.end());
drop_ranges.erase(it);
2021-07-05 19:58:36 +00:00
}
bool DropPartsRanges::hasDropRange(const MergeTreePartInfo & new_drop_range_info) const
{
for (const auto & [znode_name, drop_range] : drop_ranges)
{
if (drop_range.contains(new_drop_range_info))
return true;
}
return false;
}
}