2020-10-13 14:25:42 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Storages/MergeTree/MergeTreeData.h>
|
|
|
|
#include <Common/ThreadPool.h>
|
|
|
|
#include <Core/BackgroundSchedulePool.h>
|
2020-10-14 12:32:35 +00:00
|
|
|
#include <pcg_random.hpp>
|
2020-10-13 14:25:42 +00:00
|
|
|
|
2020-10-14 12:44:10 +00:00
|
|
|
namespace CurrentMetrics
|
|
|
|
{
|
|
|
|
extern const Metric BackgroundPoolTask;
|
|
|
|
}
|
|
|
|
|
2020-10-13 14:25:42 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2020-10-14 12:44:10 +00:00
|
|
|
enum PoolType
|
|
|
|
{
|
|
|
|
MERGE_MUTATING,
|
|
|
|
MOVING,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PoolSettings
|
|
|
|
{
|
|
|
|
double thread_sleep_seconds = 10;
|
|
|
|
double thread_sleep_seconds_random_part = 1.0;
|
|
|
|
double thread_sleep_seconds_if_nothing_to_do = 0.1;
|
|
|
|
|
|
|
|
/// For exponential backoff.
|
|
|
|
double task_sleep_seconds_when_no_work_min = 10;
|
|
|
|
double task_sleep_seconds_when_no_work_max = 600;
|
|
|
|
double task_sleep_seconds_when_no_work_multiplier = 1.1;
|
|
|
|
double task_sleep_seconds_when_no_work_random_part = 1.0;
|
|
|
|
|
|
|
|
CurrentMetrics::Metric tasks_metric = CurrentMetrics::BackgroundPoolTask;
|
|
|
|
|
|
|
|
PoolSettings() noexcept {}
|
|
|
|
};
|
2020-10-13 14:25:42 +00:00
|
|
|
|
|
|
|
class BackgroundJobsExecutor
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
MergeTreeData & data;
|
2020-10-14 07:22:48 +00:00
|
|
|
Context & global_context;
|
2020-10-14 12:32:35 +00:00
|
|
|
size_t max_pool_size;
|
2020-10-13 14:25:42 +00:00
|
|
|
ThreadPool data_processing_pool;
|
|
|
|
ThreadPool move_pool;
|
2020-10-14 12:32:35 +00:00
|
|
|
std::atomic<size_t> errors_count{0};
|
|
|
|
pcg64 rng;
|
2020-10-14 12:44:10 +00:00
|
|
|
PoolSettings settings;
|
2020-10-13 14:25:42 +00:00
|
|
|
|
|
|
|
BackgroundSchedulePool::TaskHolder data_processing_task;
|
2020-10-14 07:22:48 +00:00
|
|
|
BackgroundSchedulePool::TaskHolder data_moving_task;
|
2020-10-13 14:25:42 +00:00
|
|
|
|
|
|
|
void dataProcessingTask();
|
2020-10-14 07:22:48 +00:00
|
|
|
void dataMovingTask();
|
2020-10-13 14:25:42 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
BackgroundJobsExecutor(
|
|
|
|
MergeTreeData & data_,
|
|
|
|
Context & global_context_);
|
|
|
|
|
2020-10-14 07:22:48 +00:00
|
|
|
void startMovingTaskIfNeeded();
|
2020-10-13 14:25:42 +00:00
|
|
|
void triggerDataProcessing();
|
|
|
|
void triggerMovesProcessing();
|
|
|
|
void start();
|
|
|
|
void finish();
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|