ClickHouse/src/Storages/MergeTree/ReplicatedMergeTreeCleanupThread.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
2.1 KiB
C++
Raw Normal View History

2014-10-15 01:22:06 +00:00
#pragma once
2021-10-02 07:13:14 +00:00
#include <base/types.h>
#include <Common/ZooKeeper/Types.h>
#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
#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:
explicit 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();
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);
/// Remove old block hashes from ZooKeeper. This is done by the leader replica.
2014-10-15 01:22:06 +00:00
void clearOldBlocks();
/// 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;
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
};
}