From 49db4dbe6a250ad011b4ef8a5d09fcf676cbb7ef Mon Sep 17 00:00:00 2001 From: Amos Bird Date: Fri, 11 Jun 2021 23:06:25 +0800 Subject: [PATCH] Update comment --- src/Interpreters/ClientInfo.cpp | 5 +---- src/Interpreters/executeQuery.cpp | 6 +++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Interpreters/ClientInfo.cpp b/src/Interpreters/ClientInfo.cpp index ec694952b07..c8b945ef9b5 100644 --- a/src/Interpreters/ClientInfo.cpp +++ b/src/Interpreters/ClientInfo.cpp @@ -35,10 +35,7 @@ void ClientInfo::write(WriteBuffer & out, const UInt64 server_protocol_revision) writeBinary(initial_address.toString(), out); if (server_protocol_revision >= DBMS_MIN_PROTOCOL_VERSION_WITH_INITIAL_QUERY_START_TIME) - { - writeBinary(initial_query_start_time, out); writeBinary(initial_query_start_time_microseconds, out); - } writeBinary(UInt8(interface), out); @@ -117,8 +114,8 @@ void ClientInfo::read(ReadBuffer & in, const UInt64 client_protocol_revision) if (client_protocol_revision >= DBMS_MIN_PROTOCOL_VERSION_WITH_INITIAL_QUERY_START_TIME) { - readBinary(initial_query_start_time, in); readBinary(initial_query_start_time_microseconds, in); + initial_query_start_time = initial_query_start_time_microseconds / 1000000; } UInt8 read_interface = 0; diff --git a/src/Interpreters/executeQuery.cpp b/src/Interpreters/executeQuery.cpp index 8d3d4a28aa8..c69a5bcd3e1 100644 --- a/src/Interpreters/executeQuery.cpp +++ b/src/Interpreters/executeQuery.cpp @@ -357,7 +357,11 @@ static std::tuple executeQueryImpl( auto & client_info = context->getClientInfo(); - // If it's an initial query, set to current_time + // If it's not an internal query and we don't see an initial_query_start_time yet, initialize it + // to current time. Internal queries are those executed without an independent client context, + // thus should not set initial_query_start_time, because it might introduce data race. It's also + // possible to have unset initial_query_start_time for non-internal and non-initial queries. For + // example, the query is from an initiator that is running an old version of clickhouse. if (!internal && client_info.initial_query_start_time == 0) { client_info.initial_query_start_time = time_in_seconds(current_time);