2014-10-15 01:22:06 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2017-08-09 21:09:44 +00:00
|
|
|
#include <Common/ZooKeeper/Types.h>
|
2018-03-24 01:00:12 +00:00
|
|
|
#include <Common/ZooKeeper/ZooKeeper.h>
|
2022-04-27 15:05:45 +00:00
|
|
|
#include <Common/logger_useful.h>
|
2020-06-15 02:12:06 +00:00
|
|
|
#include <Common/randomSeed.h>
|
2018-08-20 15:34:37 +00:00
|
|
|
#include <Core/BackgroundSchedulePool.h>
|
2014-10-15 01:22:06 +00:00
|
|
|
#include <thread>
|
2018-08-27 23:59:49 +00:00
|
|
|
|
2017-08-06 21:40:38 +00:00
|
|
|
#include <map>
|
2018-08-27 23:59:49 +00:00
|
|
|
#include <unordered_map>
|
2018-04-06 19:43:37 +00:00
|
|
|
#include <pcg_random.hpp>
|
|
|
|
|
2014-10-15 01:22:06 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class StorageReplicatedMergeTree;
|
|
|
|
|
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/** Removes obsolete data from a table of type ReplicatedMergeTree.
|
2014-10-15 01:22:06 +00:00
|
|
|
*/
|
|
|
|
class ReplicatedMergeTreeCleanupThread
|
|
|
|
{
|
|
|
|
public:
|
2022-03-13 12:23:51 +00:00
|
|
|
explicit ReplicatedMergeTreeCleanupThread(StorageReplicatedMergeTree & storage_);
|
2014-10-15 01:22:06 +00:00
|
|
|
|
2018-08-22 13:43:27 +00:00
|
|
|
void start() { task->activateAndSchedule(); }
|
2018-07-30 17:34:55 +00:00
|
|
|
|
|
|
|
void wakeup() { task->schedule(); }
|
|
|
|
|
|
|
|
void stop() { task->deactivate(); }
|
2017-12-29 22:32:04 +00:00
|
|
|
|
2014-10-15 01:22:06 +00:00
|
|
|
private:
|
|
|
|
StorageReplicatedMergeTree & storage;
|
2018-05-31 13:05:05 +00:00
|
|
|
String log_name;
|
2020-05-30 21:57:37 +00:00
|
|
|
Poco::Logger * log;
|
2018-05-31 13:05:05 +00:00
|
|
|
BackgroundSchedulePool::TaskHolder task;
|
2020-06-15 02:12:06 +00:00
|
|
|
pcg64 rng{randomSeed()};
|
2014-10-15 01:22:06 +00:00
|
|
|
|
|
|
|
void run();
|
|
|
|
void iterate();
|
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// Remove old records from ZooKeeper.
|
2014-10-15 01:22:06 +00:00
|
|
|
void clearOldLogs();
|
|
|
|
|
2018-08-27 23:59:49 +00:00
|
|
|
/// The replica is marked as "lost" if it is inactive and its log pointer
|
|
|
|
/// is far behind and we are not going to keep logs for it.
|
|
|
|
/// Lost replicas will use different strategy for repair.
|
2018-08-27 15:44:51 +00:00
|
|
|
void markLostReplicas(const std::unordered_map<String, UInt32> & host_versions_lost_replicas,
|
|
|
|
const std::unordered_map<String, String> & log_pointers_candidate_lost_replicas,
|
2018-08-23 15:58:29 +00:00
|
|
|
size_t replicas_count, const zkutil::ZooKeeperPtr & zookeeper);
|
2018-08-09 15:06:39 +00:00
|
|
|
|
2017-11-15 16:32:47 +00:00
|
|
|
/// Remove old block hashes from ZooKeeper. This is done by the leader replica.
|
2014-10-15 01:22:06 +00:00
|
|
|
void clearOldBlocks();
|
2015-09-20 11:02:59 +00:00
|
|
|
|
2018-07-31 11:36:08 +00:00
|
|
|
/// Remove old mutations that are done from ZooKeeper. This is done by the leader replica.
|
|
|
|
void clearOldMutations();
|
|
|
|
|
2021-04-19 09:52:37 +00:00
|
|
|
using NodeCTimeAndVersionCache = std::map<String, std::pair<Int64, Int32>>;
|
|
|
|
NodeCTimeAndVersionCache cached_block_stats;
|
2017-08-09 21:09:44 +00:00
|
|
|
|
2017-11-15 16:32:47 +00:00
|
|
|
struct NodeWithStat;
|
|
|
|
/// Returns list of blocks (with their stat) sorted by ctime in descending order.
|
|
|
|
void getBlocksSortedByTime(zkutil::ZooKeeper & zookeeper, std::vector<NodeWithStat> & timed_blocks);
|
2017-08-06 21:40:38 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// TODO Removing old quorum/failed_parts
|
2014-10-15 01:22:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|