aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Client/IConnections.h
blob: ee17d198fc34688e9bce889b0244bc3e95eb6ebb (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
73
74
75
76
77
78
79
#pragma once

#include <compare>

#include <Client/Connection.h>
#include <Storages/MergeTree/RequestResponse.h>

namespace DB
{

/// Base class for working with multiple replicas (connections)
/// from one shard within a single thread
class IConnections : boost::noncopyable
{
public:
    /// Send all scalars to replicas.
    virtual void sendScalarsData(Scalars & data) = 0;
    /// Send all content of external tables to replicas.
    virtual void sendExternalTablesData(std::vector<ExternalTablesData> & data) = 0;

    /// Send request to replicas.
    virtual void sendQuery(
        const ConnectionTimeouts & timeouts,
        const String & query,
        const String & query_id,
        UInt64 stage,
        ClientInfo & client_info,
        bool with_pending_data) = 0;

    virtual void sendReadTaskResponse(const String &) = 0;
    virtual void sendMergeTreeReadTaskResponse(const ParallelReadResponse & response) = 0;

    /// Get packet from any replica.
    virtual Packet receivePacket() = 0;

    /// Version of `receivePacket` function without locking.
    virtual Packet receivePacketUnlocked(AsyncCallback async_callback) = 0;

    /// Break all active connections.
    virtual void disconnect() = 0;

    /// Send a request to replicas to cancel the request
    virtual void sendCancel() = 0;

    /// Send parts' uuids to replicas to exclude them from query processing
    virtual void sendIgnoredPartUUIDs(const std::vector<UUID> & uuids) = 0;

    /** On each replica, read and skip all packets to EndOfStream or Exception.
      * Returns EndOfStream if no exception has been received. Otherwise
      * returns the last received packet of type Exception.
      */
    virtual Packet drain() = 0;

    /// Get the replica addresses as a string.
    virtual std::string dumpAddresses() const = 0;

    struct ReplicaInfo
    {
        bool collaborate_with_initiator{false};
        size_t all_replicas_count{0};
        size_t number_of_current_replica{0};
    };

    /// This is needed in max_parallel_replicas case.
    /// We create a RemoteQueryExecutor for each replica
    virtual void setReplicaInfo(ReplicaInfo value) = 0;

    /// Returns the number of replicas.
    virtual size_t size() const = 0;

    /// Check if there are any valid replicas.
    virtual bool hasActiveConnections() const = 0;

    virtual ~IConnections() = default;

    virtual void setAsyncCallback(AsyncCallback) {}
};

}