2014-05-26 10:41:40 +00:00
|
|
|
#pragma once
|
2017-08-14 18:16:11 +00:00
|
|
|
|
|
|
|
#include <Storages/MergeTree/MergeTreePartInfo.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Types.h>
|
2017-08-15 11:59:08 +00:00
|
|
|
#include <map>
|
2014-05-26 10:41:40 +00:00
|
|
|
|
2017-04-18 20:38:07 +00:00
|
|
|
|
2014-05-26 10:41:40 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/** Supports multiple names of active parts of data.
|
|
|
|
* Repeats part of the MergeTreeData functionality.
|
2018-05-21 13:49:54 +00:00
|
|
|
* TODO: generalize with MergeTreeData
|
2014-05-26 10:41:40 +00:00
|
|
|
*/
|
|
|
|
class ActiveDataPartSet
|
|
|
|
{
|
|
|
|
public:
|
2017-08-25 20:41:45 +00:00
|
|
|
ActiveDataPartSet(MergeTreeDataFormatVersion format_version_) : format_version(format_version_) {}
|
|
|
|
ActiveDataPartSet(MergeTreeDataFormatVersion format_version_, const Strings & names);
|
2014-10-10 00:46:37 +00:00
|
|
|
|
2018-05-10 15:01:10 +00:00
|
|
|
ActiveDataPartSet(const ActiveDataPartSet & other)
|
|
|
|
: format_version(other.format_version)
|
|
|
|
, part_info_to_name(other.part_info_to_name)
|
|
|
|
{}
|
|
|
|
|
|
|
|
ActiveDataPartSet(ActiveDataPartSet && other) noexcept { swap(other); }
|
|
|
|
|
|
|
|
void swap(ActiveDataPartSet & other) noexcept
|
|
|
|
{
|
|
|
|
std::swap(format_version, other.format_version);
|
|
|
|
std::swap(part_info_to_name, other.part_info_to_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
ActiveDataPartSet & operator=(const ActiveDataPartSet & other)
|
|
|
|
{
|
|
|
|
if (&other != this)
|
|
|
|
{
|
|
|
|
ActiveDataPartSet tmp(other);
|
|
|
|
swap(tmp);
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-06-22 10:43:35 +00:00
|
|
|
/// Returns true if the part was actually added. If out_replaced_parts != nullptr, it will contain
|
|
|
|
/// parts that were replaced from the set by the newly added part.
|
2018-06-18 12:17:46 +00:00
|
|
|
bool add(const String & name, Strings * out_replaced_parts = nullptr);
|
2014-10-13 17:28:59 +00:00
|
|
|
|
2018-05-10 15:01:10 +00:00
|
|
|
bool remove(const MergeTreePartInfo & part_info)
|
|
|
|
{
|
|
|
|
return part_info_to_name.erase(part_info) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool remove(const String & part_name)
|
|
|
|
{
|
|
|
|
return remove(MergeTreePartInfo::fromPartName(part_name, format_version));
|
|
|
|
}
|
|
|
|
|
2020-02-05 16:30:02 +00:00
|
|
|
/// Remove part and all covered parts from active set
|
|
|
|
bool removePartAndCoveredParts(const String & part_name)
|
|
|
|
{
|
|
|
|
Strings parts_covered_by = getPartsCoveredBy(MergeTreePartInfo::fromPartName(part_name, format_version));
|
|
|
|
bool result = true;
|
|
|
|
result &= remove(part_name);
|
|
|
|
for (const auto & part : parts_covered_by)
|
|
|
|
result &= remove(part);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-05-10 15:01:10 +00:00
|
|
|
/// If not found, return an empty string.
|
|
|
|
String getContainingPart(const MergeTreePartInfo & part_info) const;
|
2017-04-01 07:20:54 +00:00
|
|
|
String getContainingPart(const String & name) const;
|
2014-05-26 18:14:52 +00:00
|
|
|
|
2018-05-10 15:01:10 +00:00
|
|
|
Strings getPartsCoveredBy(const MergeTreePartInfo & part_info) const;
|
|
|
|
|
2018-05-21 13:49:54 +00:00
|
|
|
/// Returns parts in ascending order of the partition_id and block number.
|
|
|
|
Strings getParts() const;
|
2014-08-08 08:28:13 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t size() const;
|
2014-05-26 10:41:40 +00:00
|
|
|
|
2020-02-05 16:30:02 +00:00
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
part_info_to_name.clear();
|
|
|
|
}
|
|
|
|
|
2018-06-21 15:54:01 +00:00
|
|
|
MergeTreeDataFormatVersion getFormatVersion() const { return format_version; }
|
|
|
|
|
2014-05-26 10:41:40 +00:00
|
|
|
private:
|
2017-08-25 20:41:45 +00:00
|
|
|
MergeTreeDataFormatVersion format_version;
|
2017-08-15 11:59:08 +00:00
|
|
|
std::map<MergeTreePartInfo, String> part_info_to_name;
|
2014-10-10 00:46:37 +00:00
|
|
|
|
2018-05-10 15:01:10 +00:00
|
|
|
std::map<MergeTreePartInfo, String>::const_iterator getContainingPartImpl(const MergeTreePartInfo & part_info) const;
|
2014-05-26 10:41:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|