| 1 | #pragma once |
| 2 | |
| 3 | #include <Poco/Net/SocketAddress.h> |
| 4 | #include <Core/Types.h> |
| 5 | |
| 6 | |
| 7 | namespace DB |
| 8 | { |
| 9 | |
| 10 | class WriteBuffer; |
| 11 | class ReadBuffer; |
| 12 | |
| 13 | |
| 14 | /** Information about client for query. |
| 15 | * Some fields are passed explicitly from client and some are calculated automatically. |
| 16 | * |
| 17 | * Contains info about initial query source, for tracing distributed queries |
| 18 | * (where one query initiates many other queries). |
| 19 | */ |
| 20 | class ClientInfo |
| 21 | { |
| 22 | public: |
| 23 | enum class Interface : UInt8 |
| 24 | { |
| 25 | TCP = 1, |
| 26 | HTTP = 2, |
| 27 | }; |
| 28 | |
| 29 | enum class HTTPMethod : UInt8 |
| 30 | { |
| 31 | UNKNOWN = 0, |
| 32 | GET = 1, |
| 33 | POST = 2, |
| 34 | }; |
| 35 | |
| 36 | enum class QueryKind : UInt8 |
| 37 | { |
| 38 | NO_QUERY = 0, /// Uninitialized object. |
| 39 | INITIAL_QUERY = 1, |
| 40 | SECONDARY_QUERY = 2, /// Query that was initiated by another query for distributed or ON CLUSTER query execution. |
| 41 | }; |
| 42 | |
| 43 | |
| 44 | QueryKind query_kind = QueryKind::NO_QUERY; |
| 45 | |
| 46 | /// Current values are not serialized, because it is passed separately. |
| 47 | String current_user; |
| 48 | String current_query_id; |
| 49 | Poco::Net::SocketAddress current_address; |
| 50 | /// Use current user and password when sending query to replica leader |
| 51 | String current_password; |
| 52 | |
| 53 | /// When query_kind == INITIAL_QUERY, these values are equal to current. |
| 54 | String initial_user; |
| 55 | String initial_query_id; |
| 56 | Poco::Net::SocketAddress initial_address; |
| 57 | |
| 58 | /// All below are parameters related to initial query. |
| 59 | |
| 60 | Interface interface = Interface::TCP; |
| 61 | |
| 62 | /// For tcp |
| 63 | String os_user; |
| 64 | String client_hostname; |
| 65 | String client_name; |
| 66 | UInt64 client_version_major = 0; |
| 67 | UInt64 client_version_minor = 0; |
| 68 | UInt64 client_version_patch = 0; |
| 69 | unsigned client_revision = 0; |
| 70 | |
| 71 | /// For http |
| 72 | HTTPMethod http_method = HTTPMethod::UNKNOWN; |
| 73 | String http_user_agent; |
| 74 | |
| 75 | /// Common |
| 76 | String quota_key; |
| 77 | |
| 78 | bool empty() const { return query_kind == QueryKind::NO_QUERY; } |
| 79 | |
| 80 | /** Serialization and deserialization. |
| 81 | * Only values that are not calculated automatically or passed separately are serialized. |
| 82 | * Revisions are passed to use format that server will understand or client was used. |
| 83 | */ |
| 84 | void write(WriteBuffer & out, const UInt64 server_protocol_revision) const; |
| 85 | void read(ReadBuffer & in, const UInt64 client_protocol_revision); |
| 86 | |
| 87 | void fillOSUserHostNameAndVersionInfo(); |
| 88 | }; |
| 89 | |
| 90 | } |
| 91 | |