ClickHouse/src/IO/ConnectionTimeouts.h

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

122 lines
4.7 KiB
C++
Raw Normal View History

#pragma once
#include <Core/Defines.h>
#include <Interpreters/Context_fwd.h>
#include <Poco/Timespan.h>
2019-03-29 18:10:03 +00:00
namespace DB
{
struct Settings;
struct ConnectionTimeouts
{
Poco::Timespan connection_timeout;
Poco::Timespan send_timeout;
Poco::Timespan receive_timeout;
2018-10-22 23:02:57 +00:00
Poco::Timespan tcp_keep_alive_timeout;
2019-03-29 18:10:03 +00:00
Poco::Timespan http_keep_alive_timeout;
2020-02-06 17:23:05 +00:00
Poco::Timespan secure_connection_timeout;
2021-01-19 19:21:06 +00:00
/// Timeouts for HedgedConnections
2021-02-17 17:34:52 +00:00
Poco::Timespan hedged_connection_timeout;
2021-01-19 19:21:06 +00:00
Poco::Timespan receive_data_timeout;
/// Timeout for synchronous request-result protocol call (like Ping or TablesStatus)
2022-08-12 14:28:21 +00:00
Poco::Timespan sync_request_timeout = Poco::Timespan(DBMS_DEFAULT_SYNC_REQUEST_TIMEOUT_SEC, 0);
ConnectionTimeouts() = default;
2021-04-29 16:11:20 +00:00
ConnectionTimeouts(Poco::Timespan connection_timeout_,
Poco::Timespan send_timeout_,
Poco::Timespan receive_timeout_)
2018-10-22 23:02:57 +00:00
: connection_timeout(connection_timeout_),
send_timeout(send_timeout_),
receive_timeout(receive_timeout_),
2019-03-29 18:10:03 +00:00
tcp_keep_alive_timeout(0),
2020-02-06 17:23:05 +00:00
http_keep_alive_timeout(0),
2021-01-19 19:21:06 +00:00
secure_connection_timeout(connection_timeout),
2021-02-17 17:34:52 +00:00
hedged_connection_timeout(receive_timeout_),
2021-02-06 00:54:27 +00:00
receive_data_timeout(receive_timeout_)
2018-10-22 23:02:57 +00:00
{
}
2021-04-29 16:11:20 +00:00
ConnectionTimeouts(Poco::Timespan connection_timeout_,
Poco::Timespan send_timeout_,
Poco::Timespan receive_timeout_,
Poco::Timespan tcp_keep_alive_timeout_)
: connection_timeout(connection_timeout_),
send_timeout(send_timeout_),
2018-10-22 18:09:55 +00:00
receive_timeout(receive_timeout_),
2019-03-29 18:10:03 +00:00
tcp_keep_alive_timeout(tcp_keep_alive_timeout_),
2020-02-06 17:23:05 +00:00
http_keep_alive_timeout(0),
2021-01-19 19:21:06 +00:00
secure_connection_timeout(connection_timeout),
2021-02-17 17:34:52 +00:00
hedged_connection_timeout(receive_timeout_),
2021-02-06 00:54:27 +00:00
receive_data_timeout(receive_timeout_)
{
}
2021-04-29 16:11:20 +00:00
ConnectionTimeouts(Poco::Timespan connection_timeout_,
Poco::Timespan send_timeout_,
Poco::Timespan receive_timeout_,
Poco::Timespan tcp_keep_alive_timeout_,
Poco::Timespan http_keep_alive_timeout_)
2019-03-29 18:10:03 +00:00
: connection_timeout(connection_timeout_),
send_timeout(send_timeout_),
receive_timeout(receive_timeout_),
tcp_keep_alive_timeout(tcp_keep_alive_timeout_),
2020-02-06 17:23:05 +00:00
http_keep_alive_timeout(http_keep_alive_timeout_),
2021-01-19 19:21:06 +00:00
secure_connection_timeout(connection_timeout),
2021-02-17 17:34:52 +00:00
hedged_connection_timeout(receive_timeout_),
2021-02-06 00:54:27 +00:00
receive_data_timeout(receive_timeout_)
2019-03-29 18:10:03 +00:00
{
}
2021-04-29 16:11:20 +00:00
ConnectionTimeouts(Poco::Timespan connection_timeout_,
Poco::Timespan send_timeout_,
Poco::Timespan receive_timeout_,
Poco::Timespan tcp_keep_alive_timeout_,
Poco::Timespan http_keep_alive_timeout_,
Poco::Timespan secure_connection_timeout_,
Poco::Timespan receive_hello_timeout_,
Poco::Timespan receive_data_timeout_)
2021-01-19 19:21:06 +00:00
: connection_timeout(connection_timeout_),
send_timeout(send_timeout_),
receive_timeout(receive_timeout_),
tcp_keep_alive_timeout(tcp_keep_alive_timeout_),
http_keep_alive_timeout(http_keep_alive_timeout_),
secure_connection_timeout(secure_connection_timeout_),
2021-02-17 17:34:52 +00:00
hedged_connection_timeout(receive_hello_timeout_),
2021-01-19 19:21:06 +00:00
receive_data_timeout(receive_data_timeout_)
2020-02-06 17:23:05 +00:00
{
}
2021-04-29 16:11:20 +00:00
static Poco::Timespan saturate(Poco::Timespan timespan, Poco::Timespan limit)
{
if (limit.totalMicroseconds() == 0)
return timespan;
else
return (timespan > limit) ? limit : timespan;
}
2021-04-29 16:11:20 +00:00
ConnectionTimeouts getSaturated(Poco::Timespan limit) const
{
return ConnectionTimeouts(saturate(connection_timeout, limit),
saturate(send_timeout, limit),
2018-10-22 18:09:55 +00:00
saturate(receive_timeout, limit),
2019-03-29 18:10:03 +00:00
saturate(tcp_keep_alive_timeout, limit),
2020-02-06 17:23:05 +00:00
saturate(http_keep_alive_timeout, limit),
2021-01-19 19:21:06 +00:00
saturate(secure_connection_timeout, limit),
2021-02-17 17:34:52 +00:00
saturate(hedged_connection_timeout, limit),
2021-01-19 19:21:06 +00:00
saturate(receive_data_timeout, limit));
}
/// Timeouts for the case when we have just single attempt to connect.
static ConnectionTimeouts getTCPTimeoutsWithoutFailover(const Settings & settings);
/// Timeouts for the case when we will try many addresses in a loop.
static ConnectionTimeouts getTCPTimeoutsWithFailover(const Settings & settings);
2021-06-01 12:20:52 +00:00
static ConnectionTimeouts getHTTPTimeouts(ContextPtr context);
};
}