2021-07-14 13:17:30 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Client/IConnections.h>
|
|
|
|
#include <Interpreters/Context_fwd.h>
|
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
#include <Common/ThreadPool.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class ConnectionPoolWithFailover;
|
|
|
|
using ConnectionPoolWithFailoverPtr = std::shared_ptr<ConnectionPoolWithFailover>;
|
|
|
|
|
|
|
|
class ConnectionCollector : boost::noncopyable, WithMutableContext
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static ConnectionCollector & init(ContextMutablePtr global_context_, size_t max_threads);
|
|
|
|
static std::shared_ptr<IConnections>
|
2021-07-21 11:56:32 +00:00
|
|
|
enqueueConnectionCleanup(const ConnectionPoolWithFailoverPtr & pool, std::shared_ptr<IConnections> connections) noexcept;
|
2021-07-14 13:17:30 +00:00
|
|
|
static void drainConnections(IConnections & connections) noexcept;
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit ConnectionCollector(ContextMutablePtr global_context_, size_t max_threads);
|
|
|
|
|
|
|
|
static constexpr size_t reschedule_time_ms = 1000;
|
|
|
|
ThreadPool pool;
|
|
|
|
static std::unique_ptr<ConnectionCollector> connection_collector;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|