// Copyright 2023 PingCAP, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #pragma once #include #include namespace DB { class WriteBuffer; class ReadBuffer; /** Information about client for query. * Some fields are passed explicitly from client and some are calculated automatically. * * Contains info about initial query source, for tracing distributed queries * (where one query initiates many other queries). */ class ClientInfo { public: enum class Interface : UInt8 { TCP = 1, GRPC = 2, }; enum class QueryKind : UInt8 { NO_QUERY = 0, /// Uninitialized object. INITIAL_QUERY = 1, SECONDARY_QUERY = 2, /// Query that was initiated by another query for distributed query execution. }; QueryKind query_kind = QueryKind::NO_QUERY; /// Current values are not serialized, because it is passed separately. String current_user; String current_query_id; Poco::Net::SocketAddress current_address; /// Use current user and password when sending query to replica leader String current_password; /// When query_kind == INITIAL_QUERY, these values are equal to current. String initial_user; String initial_query_id; Poco::Net::SocketAddress initial_address; /// All below are parameters related to initial query. Interface interface = Interface::TCP; /// For tcp String os_user; String client_hostname; String client_name; UInt64 client_version_major = 0; UInt64 client_version_minor = 0; UInt64 client_version_patch = 0; /// Common String quota_key; bool empty() const { return query_kind == QueryKind::NO_QUERY; } /** Serialization and deserialization. * Only values that are not calculated automatically or passed separately are serialized. */ void write(WriteBuffer & out) const; void read(ReadBuffer & in); void fillOSUserHostNameAndVersionInfo(); }; } // namespace DB