2019-04-15 09:30:45 +00:00
|
|
|
#pragma once
|
|
|
|
#include <IO/WriteBufferFromFile.h>
|
|
|
|
#include <IO/ReadBufferFromFile.h>
|
2020-09-02 12:16:12 +00:00
|
|
|
#include <Storages/TTLDescription.h>
|
2019-04-15 09:30:45 +00:00
|
|
|
|
2020-02-28 20:27:25 +00:00
|
|
|
#include <map>
|
2019-04-15 09:30:45 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Minimal and maximal ttl for column or table
|
|
|
|
struct MergeTreeDataPartTTLInfo
|
|
|
|
{
|
|
|
|
time_t min = 0;
|
|
|
|
time_t max = 0;
|
|
|
|
|
|
|
|
void update(time_t time)
|
|
|
|
{
|
|
|
|
if (time && (!min || time < min))
|
|
|
|
min = time;
|
|
|
|
|
|
|
|
max = std::max(time, max);
|
|
|
|
}
|
|
|
|
|
|
|
|
void update(const MergeTreeDataPartTTLInfo & other_info)
|
|
|
|
{
|
|
|
|
if (other_info.min && (!min || other_info.min < min))
|
|
|
|
min = other_info.min;
|
|
|
|
|
|
|
|
max = std::max(other_info.max, max);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-02 12:16:12 +00:00
|
|
|
/// Order is important as it would be serialized and hashed for checksums
|
|
|
|
using TTLInfoMap = std::map<String, MergeTreeDataPartTTLInfo>;
|
|
|
|
|
2019-04-15 09:30:45 +00:00
|
|
|
/// PartTTLInfo for all columns and table with minimal ttl for whole part
|
|
|
|
struct MergeTreeDataPartTTLInfos
|
|
|
|
{
|
2020-09-02 12:16:12 +00:00
|
|
|
TTLInfoMap columns_ttl;
|
2019-04-15 09:30:45 +00:00
|
|
|
MergeTreeDataPartTTLInfo table_ttl;
|
2019-11-29 05:41:09 +00:00
|
|
|
|
|
|
|
/// `part_min_ttl` and `part_max_ttl` are TTLs which are used for selecting parts
|
2020-08-31 12:12:51 +00:00
|
|
|
/// to merge in order to remove expired rows.
|
2019-04-15 09:30:45 +00:00
|
|
|
time_t part_min_ttl = 0;
|
2019-07-28 10:30:46 +00:00
|
|
|
time_t part_max_ttl = 0;
|
2019-04-15 09:30:45 +00:00
|
|
|
|
2020-09-02 12:16:12 +00:00
|
|
|
TTLInfoMap moves_ttl;
|
2019-10-17 16:01:28 +00:00
|
|
|
|
2020-09-02 12:16:12 +00:00
|
|
|
TTLInfoMap recompression_ttl;
|
2020-08-31 12:12:51 +00:00
|
|
|
|
2020-10-27 11:04:03 +00:00
|
|
|
/// Return the smallest max recompression TTL value
|
2020-09-09 09:15:42 +00:00
|
|
|
time_t getMinimalMaxRecompressionTTL() const;
|
2020-09-07 07:59:14 +00:00
|
|
|
|
2020-09-02 10:30:04 +00:00
|
|
|
|
2019-04-15 09:30:45 +00:00
|
|
|
void read(ReadBuffer & in);
|
|
|
|
void write(WriteBuffer & out) const;
|
|
|
|
void update(const MergeTreeDataPartTTLInfos & other_infos);
|
|
|
|
|
2019-07-28 10:30:46 +00:00
|
|
|
void updatePartMinMaxTTL(time_t time_min, time_t time_max)
|
2019-04-15 09:30:45 +00:00
|
|
|
{
|
2019-07-28 10:30:46 +00:00
|
|
|
if (time_min && (!part_min_ttl || time_min < part_min_ttl))
|
|
|
|
part_min_ttl = time_min;
|
|
|
|
|
|
|
|
if (time_max && (!part_max_ttl || time_max > part_max_ttl))
|
|
|
|
part_max_ttl = time_max;
|
2019-04-15 09:30:45 +00:00
|
|
|
}
|
2019-10-17 18:55:07 +00:00
|
|
|
|
2020-09-03 08:59:41 +00:00
|
|
|
bool empty() const
|
2019-10-17 18:55:07 +00:00
|
|
|
{
|
2020-09-02 16:15:41 +00:00
|
|
|
return !part_min_ttl && moves_ttl.empty() && recompression_ttl.empty();
|
2019-10-17 18:55:07 +00:00
|
|
|
}
|
2019-04-15 09:30:45 +00:00
|
|
|
};
|
|
|
|
|
2020-09-07 07:59:14 +00:00
|
|
|
/// Selects the most appropriate TTLDescription using TTL info and current time.
|
|
|
|
std::optional<TTLDescription> selectTTLDescriptionForTTLInfos(const TTLDescriptions & descriptions, const TTLInfoMap & ttl_info_map, time_t current_time, bool use_max);
|
2020-09-02 12:16:12 +00:00
|
|
|
|
2019-04-15 09:30:45 +00:00
|
|
|
}
|