1#pragma once
2#include <IO/WriteBufferFromFile.h>
3#include <IO/ReadBufferFromFile.h>
4
5#include <unordered_map>
6
7namespace DB
8{
9
10/// Minimal and maximal ttl for column or table
11struct MergeTreeDataPartTTLInfo
12{
13 time_t min = 0;
14 time_t max = 0;
15
16 void update(time_t time)
17 {
18 if (time && (!min || time < min))
19 min = time;
20
21 max = std::max(time, max);
22 }
23
24 void update(const MergeTreeDataPartTTLInfo & other_info)
25 {
26 if (other_info.min && (!min || other_info.min < min))
27 min = other_info.min;
28
29 max = std::max(other_info.max, max);
30 }
31};
32
33/// PartTTLInfo for all columns and table with minimal ttl for whole part
34struct MergeTreeDataPartTTLInfos
35{
36 std::unordered_map<String, MergeTreeDataPartTTLInfo> columns_ttl;
37 MergeTreeDataPartTTLInfo table_ttl;
38
39 /// `part_min_ttl` and `part_max_ttl` are TTLs which are used for selecting parts
40 /// to merge in order to remove expired rows.
41 time_t part_min_ttl = 0;
42 time_t part_max_ttl = 0;
43
44 std::unordered_map<String, MergeTreeDataPartTTLInfo> moves_ttl;
45
46 void read(ReadBuffer & in);
47 void write(WriteBuffer & out) const;
48 void update(const MergeTreeDataPartTTLInfos & other_infos);
49
50 void updatePartMinMaxTTL(time_t time_min, time_t time_max)
51 {
52 if (time_min && (!part_min_ttl || time_min < part_min_ttl))
53 part_min_ttl = time_min;
54
55 if (time_max && (!part_max_ttl || time_max > part_max_ttl))
56 part_max_ttl = time_max;
57 }
58
59 bool empty()
60 {
61 return !part_min_ttl && moves_ttl.empty();
62 }
63};
64
65}
66