2019-04-15 09:30:45 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-07-28 14:38:34 +00:00
|
|
|
#include <Core/Types.h>
|
2019-04-15 09:30:45 +00:00
|
|
|
#include <Storages/MergeTree/MergeSelector.h>
|
|
|
|
|
2020-07-28 14:38:34 +00:00
|
|
|
#include <map>
|
|
|
|
|
2019-04-15 09:30:45 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Merge selector, which is used to remove values with expired ttl.
|
|
|
|
* It selects parts to merge by greedy algorithm:
|
|
|
|
* 1. Finds part with the most earliest expired ttl and includes it to result.
|
|
|
|
* 2. Tries to find the longest range of parts with expired ttl, that includes part from step 1.
|
2020-07-28 14:38:34 +00:00
|
|
|
* Finally, merge selector updates TTL merge timer for the selected partition
|
2019-04-15 09:30:45 +00:00
|
|
|
*/
|
|
|
|
class TTLMergeSelector : public IMergeSelector
|
|
|
|
{
|
|
|
|
public:
|
2020-07-28 14:38:34 +00:00
|
|
|
using PartitionIdToTTLs = std::map<String, time_t>;
|
|
|
|
|
|
|
|
explicit TTLMergeSelector(PartitionIdToTTLs & merge_due_times_, time_t current_time_, Int64 merge_cooldown_time_, bool only_drop_parts_)
|
|
|
|
: merge_due_times(merge_due_times_),
|
|
|
|
current_time(current_time_),
|
|
|
|
merge_cooldown_time(merge_cooldown_time_),
|
|
|
|
only_drop_parts(only_drop_parts_) {}
|
2019-04-15 09:30:45 +00:00
|
|
|
|
|
|
|
PartsInPartition select(
|
|
|
|
const Partitions & partitions,
|
|
|
|
const size_t max_total_size_to_merge) override;
|
2020-07-28 14:38:34 +00:00
|
|
|
|
2019-04-15 09:30:45 +00:00
|
|
|
private:
|
2020-07-28 14:38:34 +00:00
|
|
|
PartitionIdToTTLs & merge_due_times;
|
2019-04-15 09:30:45 +00:00
|
|
|
time_t current_time;
|
2020-07-28 14:38:34 +00:00
|
|
|
Int64 merge_cooldown_time;
|
2019-07-28 10:30:46 +00:00
|
|
|
bool only_drop_parts;
|
2019-04-15 09:30:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|