2018-03-26 14:12:07 +00:00
|
|
|
#pragma once
|
2018-05-14 19:14:37 +00:00
|
|
|
|
2018-03-26 14:12:07 +00:00
|
|
|
#include <memory>
|
2018-05-14 19:14:37 +00:00
|
|
|
#include <ctime>
|
|
|
|
#include <cstddef>
|
2018-03-26 14:12:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class Context;
|
|
|
|
class BackgroundProcessingPool;
|
|
|
|
class BackgroundProcessingPoolTaskInfo;
|
|
|
|
|
|
|
|
|
|
|
|
/// Add a task to BackgroundProcessingPool that watch for ProfileEvents::NetworkErrors and updates DNS cache if it has increased
|
|
|
|
class DNSCacheUpdater
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2018-04-23 14:40:23 +00:00
|
|
|
explicit DNSCacheUpdater(Context & context);
|
2018-03-26 14:12:07 +00:00
|
|
|
~DNSCacheUpdater();
|
|
|
|
|
|
|
|
/// Checks if it is a network error and increments ProfileEvents::NetworkErrors
|
2018-04-23 14:40:23 +00:00
|
|
|
static bool incrementNetworkErrorEventsIfNeeded();
|
2018-03-26 14:12:07 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool run();
|
|
|
|
|
|
|
|
Context & context;
|
|
|
|
BackgroundProcessingPool & pool;
|
|
|
|
std::shared_ptr<BackgroundProcessingPoolTaskInfo> task_handle;
|
|
|
|
size_t last_num_network_erros = 0;
|
|
|
|
time_t last_update_time = 0;
|
|
|
|
|
|
|
|
static constexpr size_t min_errors_to_update_cache = 3;
|
2018-03-29 20:21:01 +00:00
|
|
|
static constexpr time_t min_update_period_seconds = 45;
|
2018-03-26 14:12:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|