aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/IO/ConnectionTimeouts.h
blob: 684af42827f51a803262f3a15a3f7ecda9e1892f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once

#include <Core/Defines.h>
#include <Interpreters/Context_fwd.h>

#include <Poco/Timespan.h>

namespace DB
{

struct Settings;

struct 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;

    /// Timeouts for HedgedConnections
    Poco::Timespan hedged_connection_timeout;
    Poco::Timespan receive_data_timeout;

    /// Timeout for receiving HELLO packet
    Poco::Timespan handshake_timeout;

    /// Timeout for synchronous request-result protocol call (like Ping or TablesStatus)
    Poco::Timespan sync_request_timeout = Poco::Timespan(DBMS_DEFAULT_SYNC_REQUEST_TIMEOUT_SEC, 0);

    ConnectionTimeouts() = default;

    ConnectionTimeouts(Poco::Timespan connection_timeout_,
                       Poco::Timespan send_timeout_,
                       Poco::Timespan receive_timeout_);

    ConnectionTimeouts(Poco::Timespan connection_timeout_,
                       Poco::Timespan send_timeout_,
                       Poco::Timespan receive_timeout_,
                       Poco::Timespan tcp_keep_alive_timeout_,
                       Poco::Timespan handshake_timeout_);

    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 handshake_timeout_);

    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 hedged_connection_timeout_,
                       Poco::Timespan receive_data_timeout_,
                       Poco::Timespan handshake_timeout_);

    static Poco::Timespan saturate(Poco::Timespan timespan, Poco::Timespan limit);
    ConnectionTimeouts getSaturated(Poco::Timespan limit) const;

    /// 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);
    static ConnectionTimeouts getHTTPTimeouts(const Settings & settings, Poco::Timespan http_keep_alive_timeout);
};

}