2017-08-14 18:16:11 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-09-17 03:44:29 +00:00
|
|
|
#include <tuple>
|
2020-09-15 09:55:57 +00:00
|
|
|
#include <common/types.h>
|
2018-09-17 03:09:56 +00:00
|
|
|
#include <common/DayNum.h>
|
2017-08-25 20:41:45 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeDataFormatVersion.h>
|
2017-08-14 18:16:11 +00:00
|
|
|
|
2017-08-16 19:24:50 +00:00
|
|
|
|
2017-08-14 18:16:11 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Information about partition and the range of blocks contained in the part.
|
|
|
|
/// Allows determining if parts are disjoint or one part fully contains the other.
|
|
|
|
struct MergeTreePartInfo
|
|
|
|
{
|
|
|
|
String partition_id;
|
2017-08-16 19:24:50 +00:00
|
|
|
Int64 min_block = 0;
|
|
|
|
Int64 max_block = 0;
|
|
|
|
UInt32 level = 0;
|
2018-05-13 00:24:23 +00:00
|
|
|
Int64 mutation = 0; /// If the part has been mutated or contains mutated parts, is equal to mutation version number.
|
2017-08-16 19:24:50 +00:00
|
|
|
|
2021-05-14 12:55:30 +00:00
|
|
|
bool use_leagcy_max_level = false; /// For compatibility. TODO remove it
|
|
|
|
|
2017-08-16 19:24:50 +00:00
|
|
|
MergeTreePartInfo() = default;
|
2018-05-13 00:24:23 +00:00
|
|
|
|
2017-08-16 19:24:50 +00:00
|
|
|
MergeTreePartInfo(String partition_id_, Int64 min_block_, Int64 max_block_, UInt32 level_)
|
|
|
|
: partition_id(std::move(partition_id_)), min_block(min_block_), max_block(max_block_), level(level_)
|
|
|
|
{
|
|
|
|
}
|
2017-08-14 18:16:11 +00:00
|
|
|
|
2018-05-13 00:24:23 +00:00
|
|
|
MergeTreePartInfo(String partition_id_, Int64 min_block_, Int64 max_block_, UInt32 level_, Int64 mutation_)
|
|
|
|
: partition_id(std::move(partition_id_)), min_block(min_block_), max_block(max_block_), level(level_), mutation(mutation_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-08-14 18:16:11 +00:00
|
|
|
bool operator<(const MergeTreePartInfo & rhs) const
|
|
|
|
{
|
2018-05-13 00:24:23 +00:00
|
|
|
return std::forward_as_tuple(partition_id, min_block, max_block, level, mutation)
|
|
|
|
< std::forward_as_tuple(rhs.partition_id, rhs.min_block, rhs.max_block, rhs.level, rhs.mutation);
|
2017-08-14 18:16:11 +00:00
|
|
|
}
|
|
|
|
|
2018-02-19 15:31:43 +00:00
|
|
|
bool operator==(const MergeTreePartInfo & rhs) const
|
|
|
|
{
|
2018-05-10 15:01:10 +00:00
|
|
|
return !(*this != rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const MergeTreePartInfo & rhs) const
|
|
|
|
{
|
|
|
|
return *this < rhs || rhs < *this;
|
2018-02-19 15:31:43 +00:00
|
|
|
}
|
|
|
|
|
2018-05-13 00:24:23 +00:00
|
|
|
/// Get block number that can be used to determine which mutations we still need to apply to this part
|
|
|
|
/// (all mutations with version greater than this block number).
|
|
|
|
Int64 getDataVersion() const { return mutation ? mutation : min_block; }
|
|
|
|
|
|
|
|
/// True if contains rhs (this part is obtained by merging rhs with some other parts or mutating rhs)
|
2017-08-14 18:16:11 +00:00
|
|
|
bool contains(const MergeTreePartInfo & rhs) const
|
|
|
|
{
|
|
|
|
return partition_id == rhs.partition_id /// Parts for different partitions are not merged
|
|
|
|
&& min_block <= rhs.min_block
|
|
|
|
&& max_block >= rhs.max_block
|
2018-05-13 00:24:23 +00:00
|
|
|
&& level >= rhs.level
|
|
|
|
&& mutation >= rhs.mutation;
|
2017-08-14 18:16:11 +00:00
|
|
|
}
|
|
|
|
|
2018-02-19 16:12:16 +00:00
|
|
|
/// True if parts do not intersect in any way.
|
|
|
|
bool isDisjoint(const MergeTreePartInfo & rhs) const
|
|
|
|
{
|
|
|
|
return partition_id != rhs.partition_id
|
|
|
|
|| min_block > rhs.max_block
|
|
|
|
|| max_block < rhs.min_block;
|
|
|
|
}
|
|
|
|
|
2021-05-30 21:29:37 +00:00
|
|
|
bool isFakeDropRangePart() const
|
|
|
|
{
|
|
|
|
/// Another max level was previously used for REPLACE/MOVE PARTITION
|
|
|
|
auto another_max_level = std::numeric_limits<decltype(level)>::max();
|
|
|
|
return level == MergeTreePartInfo::MAX_LEVEL || level == another_max_level;
|
|
|
|
}
|
|
|
|
|
2017-08-25 20:41:45 +00:00
|
|
|
String getPartName() const;
|
2018-05-25 13:29:15 +00:00
|
|
|
String getPartNameV0(DayNum left_date, DayNum right_date) const;
|
2018-02-21 17:06:29 +00:00
|
|
|
UInt64 getBlocksCount() const
|
|
|
|
{
|
|
|
|
return static_cast<UInt64>(max_block - min_block + 1);
|
|
|
|
}
|
2017-08-14 18:16:11 +00:00
|
|
|
|
2017-08-25 20:41:45 +00:00
|
|
|
static MergeTreePartInfo fromPartName(const String & part_name, MergeTreeDataFormatVersion format_version);
|
2017-08-14 18:16:11 +00:00
|
|
|
|
2020-03-09 02:31:05 +00:00
|
|
|
static bool tryParsePartName(const String & part_name, MergeTreePartInfo * part_info, MergeTreeDataFormatVersion format_version);
|
2017-08-14 18:16:11 +00:00
|
|
|
|
2018-05-25 13:29:15 +00:00
|
|
|
static void parseMinMaxDatesFromPartName(const String & part_name, DayNum & min_date, DayNum & max_date);
|
2017-08-14 18:16:11 +00:00
|
|
|
|
2017-08-25 20:41:45 +00:00
|
|
|
static bool contains(const String & outer_part_name, const String & inner_part_name, MergeTreeDataFormatVersion format_version);
|
2018-06-04 11:23:47 +00:00
|
|
|
|
|
|
|
static constexpr UInt32 MAX_LEVEL = 999999999;
|
|
|
|
static constexpr UInt32 MAX_BLOCK_NUMBER = 999999999;
|
2021-05-14 12:55:30 +00:00
|
|
|
|
|
|
|
static constexpr UInt32 LEGACY_MAX_LEVEL = std::numeric_limits<decltype(level)>::max();
|
2017-08-14 18:16:11 +00:00
|
|
|
};
|
|
|
|
|
2019-05-20 16:24:36 +00:00
|
|
|
/// Information about detached part, which includes its prefix in
|
|
|
|
/// addition to the above fields.
|
|
|
|
struct DetachedPartInfo : public MergeTreePartInfo
|
|
|
|
{
|
2019-07-26 20:04:45 +00:00
|
|
|
String dir_name;
|
2019-05-20 16:24:36 +00:00
|
|
|
String prefix;
|
2019-07-23 19:43:33 +00:00
|
|
|
|
2019-11-19 06:44:10 +00:00
|
|
|
String disk;
|
|
|
|
|
2019-07-26 20:04:45 +00:00
|
|
|
/// If false, MergeTreePartInfo is in invalid state (directory name was not successfully parsed).
|
2019-07-23 19:43:33 +00:00
|
|
|
bool valid_name;
|
|
|
|
|
2019-07-26 20:04:45 +00:00
|
|
|
static bool tryParseDetachedPartName(const String & dir_name, DetachedPartInfo & part_info, MergeTreeDataFormatVersion format_version);
|
2019-05-20 16:24:36 +00:00
|
|
|
};
|
|
|
|
|
2019-07-31 14:44:55 +00:00
|
|
|
using DetachedPartsInfo = std::vector<DetachedPartInfo>;
|
|
|
|
|
2017-08-14 18:16:11 +00:00
|
|
|
}
|