ClickHouse/src/Storages/MergeTree/ReplicatedMergeTreeCleanupThread.h

73 lines
2.0 KiB
C++
Raw Normal View History

2014-10-15 01:22:06 +00:00
#pragma once
2020-09-15 09:55:57 +00:00
#include <common/types.h>
#include <Common/ZooKeeper/Types.h>
#include <Common/ZooKeeper/ZooKeeper.h>
2015-09-29 19:19:54 +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
#include <map>
2018-08-27 23:59:49 +00:00
#include <unordered_map>
#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:
ReplicatedMergeTreeCleanupThread(StorageReplicatedMergeTree & storage_);
2014-10-15 01:22:06 +00:00
void start() { task->activateAndSchedule(); }
void wakeup() { task->schedule(); }
void stop() { task->deactivate(); }
2014-10-15 01:22:06 +00:00
private:
StorageReplicatedMergeTree & storage;
String log_name;
2020-05-30 21:57:37 +00:00
Poco::Logger * log;
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();
2014-10-15 01:22:06 +00:00
2017-04-16 15:00:33 +00:00
/// Remove old records from ZooKeeper.
void clearOldLogs();
2014-10-15 01:22:06 +00:00
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);
/// Remove old block hashes from ZooKeeper. This is done by the leader replica.
void clearOldBlocks();
/// Remove old mutations that are done from ZooKeeper. This is done by the leader replica.
void clearOldMutations();
using NodeCTimeCache = std::map<String, Int64>;
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<NodeWithStat> & timed_blocks);
2017-04-16 15:00:33 +00:00
/// TODO Removing old quorum/failed_parts
2014-10-15 01:22:06 +00:00
};
}