#pragma once #include #include #include #include #include #include #include #include namespace DB { class StorageReplicatedMergeTree; /** Removes obsolete data from a table of type ReplicatedMergeTree. */ class ReplicatedMergeTreeCleanupThread { public: ReplicatedMergeTreeCleanupThread(StorageReplicatedMergeTree & storage_); void schedule() { task->schedule(); } private: StorageReplicatedMergeTree & storage; String log_name; Logger * log; BackgroundSchedulePool::TaskHolder task; pcg64 rng; void run(); void iterate(); /// Remove old records from ZooKeeper. void clearOldLogs(); /// Remove old block hashes from ZooKeeper. This is done by the leader replica. void clearOldBlocks(); using NodeCTimeCache = std::map; NodeCTimeCache cached_block_stats; struct NodeWithStat; /// Returns list of blocks (with their stat) sorted by ctime in descending order. void getBlocksSortedByTime(zkutil::ZooKeeper & zookeeper, std::vector & timed_blocks); /// TODO Removing old quorum/failed_parts }; }