2020-12-04 11:00:32 +00:00
|
|
|
#pragma once
|
2020-12-14 16:16:08 +00:00
|
|
|
|
|
|
|
#if defined(OS_LINUX)
|
|
|
|
|
2021-01-15 20:07:25 +00:00
|
|
|
#include <mutex>
|
|
|
|
#include <atomic>
|
2020-12-10 09:30:43 +00:00
|
|
|
#include <Common/Fiber.h>
|
|
|
|
#include <Common/FiberStack.h>
|
|
|
|
#include <Common/TimerDescriptor.h>
|
2021-01-19 19:21:06 +00:00
|
|
|
#include <Common/Epoll.h>
|
2021-01-15 20:07:25 +00:00
|
|
|
#include <Client/Connection.h>
|
2021-01-19 19:21:06 +00:00
|
|
|
#include <Client/IConnections.h>
|
2021-01-15 20:07:25 +00:00
|
|
|
#include <Poco/Timespan.h>
|
2020-12-04 11:00:32 +00:00
|
|
|
|
2021-01-15 20:07:25 +00:00
|
|
|
namespace Poco::Net
|
2020-12-04 11:00:32 +00:00
|
|
|
{
|
2021-01-15 20:07:25 +00:00
|
|
|
class Socket;
|
|
|
|
}
|
2020-12-04 11:00:32 +00:00
|
|
|
|
2021-01-15 20:07:25 +00:00
|
|
|
namespace DB
|
2020-12-04 11:00:32 +00:00
|
|
|
{
|
2021-01-15 20:07:25 +00:00
|
|
|
|
|
|
|
class MultiplexedConnections;
|
2020-12-04 11:00:32 +00:00
|
|
|
|
|
|
|
class RemoteQueryExecutorReadContext
|
|
|
|
{
|
|
|
|
public:
|
2021-01-04 07:59:01 +00:00
|
|
|
std::atomic_bool is_read_in_progress = false;
|
2020-12-04 11:00:32 +00:00
|
|
|
Packet packet;
|
|
|
|
|
|
|
|
std::exception_ptr exception;
|
2020-12-15 10:08:13 +00:00
|
|
|
FiberStack stack;
|
2020-12-04 11:00:32 +00:00
|
|
|
boost::context::fiber fiber;
|
2020-12-22 08:55:21 +00:00
|
|
|
/// This mutex for fiber is needed because fiber could be destroyed in cancel method from another thread.
|
2020-12-14 16:16:08 +00:00
|
|
|
std::mutex fiber_lock;
|
2020-12-04 11:00:32 +00:00
|
|
|
|
|
|
|
Poco::Timespan receive_timeout;
|
2021-01-19 19:21:06 +00:00
|
|
|
IConnections & connections;
|
2020-12-18 14:24:44 +00:00
|
|
|
Poco::Net::Socket * last_used_socket = nullptr;
|
2020-12-04 11:00:32 +00:00
|
|
|
|
2020-12-22 08:55:21 +00:00
|
|
|
/// Here we have three descriptors we are going to wait:
|
2021-01-19 19:21:06 +00:00
|
|
|
/// * connection_fd is a descriptor of connection. It may be changed in case of reading from several replicas.
|
2020-12-22 08:55:21 +00:00
|
|
|
/// * timer is a timerfd descriptor to manually check socket timeout
|
|
|
|
/// * pipe_fd is a pipe we use to cancel query and socket polling by executor.
|
2021-01-19 19:21:06 +00:00
|
|
|
/// We put those descriptors into our own epoll which is used by external executor.
|
2020-12-04 11:00:32 +00:00
|
|
|
TimerDescriptor timer{CLOCK_MONOTONIC, 0};
|
2021-03-26 18:01:21 +00:00
|
|
|
bool is_timer_alarmed = false;
|
2021-01-19 19:21:06 +00:00
|
|
|
int connection_fd = -1;
|
2021-01-15 20:14:49 +00:00
|
|
|
int pipe_fd[2] = { -1, -1 };
|
2020-12-04 11:00:32 +00:00
|
|
|
|
2021-01-19 19:21:06 +00:00
|
|
|
Epoll epoll;
|
|
|
|
|
|
|
|
std::string connection_fd_description;
|
|
|
|
|
|
|
|
explicit RemoteQueryExecutorReadContext(IConnections & connections_);
|
2021-01-15 20:07:25 +00:00
|
|
|
~RemoteQueryExecutorReadContext();
|
2020-12-04 11:00:32 +00:00
|
|
|
|
2021-03-26 18:01:21 +00:00
|
|
|
bool checkTimeout(bool blocking = false);
|
|
|
|
bool checkTimeoutImpl(bool blocking);
|
2020-12-04 11:00:32 +00:00
|
|
|
|
2021-01-19 19:21:06 +00:00
|
|
|
void setConnectionFD(int fd, const Poco::Timespan & timeout = 0, const std::string & fd_description = "");
|
2021-01-15 20:07:25 +00:00
|
|
|
void setTimer() const;
|
2020-12-10 12:20:18 +00:00
|
|
|
|
2021-01-15 20:07:25 +00:00
|
|
|
bool resumeRoutine();
|
|
|
|
void cancel();
|
2020-12-04 11:00:32 +00:00
|
|
|
};
|
2021-01-15 20:07:25 +00:00
|
|
|
|
2020-12-14 16:16:08 +00:00
|
|
|
}
|
2021-01-15 20:07:25 +00:00
|
|
|
|
2020-12-14 16:16:08 +00:00
|
|
|
#else
|
2021-01-15 20:07:25 +00:00
|
|
|
|
2020-12-14 16:16:08 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
class RemoteQueryExecutorReadContext
|
|
|
|
{
|
2020-12-15 10:08:13 +00:00
|
|
|
public:
|
|
|
|
void cancel() {}
|
2020-12-14 16:16:08 +00:00
|
|
|
};
|
2020-12-04 11:00:32 +00:00
|
|
|
|
|
|
|
}
|
2020-12-14 16:16:08 +00:00
|
|
|
#endif
|