fix initial query id

This commit is contained in:
Alexander Kuzmenkov 2020-10-20 00:26:10 +03:00
parent 6dcfd26b29
commit 41ac15a71c
5 changed files with 66 additions and 11 deletions

View File

@ -310,9 +310,11 @@ void HTTPHandler::processQuery(
session->release();
});
std::string query_id = params.get("query_id", "");
context.setCurrentQueryId(query_id);
// Set the query id supplied by the user, if any.
context.setCurrentQueryId(params.get("query_id",
request.get("X-ClickHouse-Query-Id", "")));
// Parse the OpenTelemetry traceparent header.
if (request.has("traceparent"))
{
std::string opentelemetry_traceparent = request.get("traceparent");

View File

@ -903,14 +903,6 @@ void TCPHandler::receiveQuery()
/// Set fields, that are known apriori.
client_info.interface = ClientInfo::Interface::TCP;
if (client_info.query_kind == ClientInfo::QueryKind::INITIAL_QUERY)
{
/// 'Current' fields was set at receiveHello.
client_info.initial_user = client_info.current_user;
client_info.initial_query_id = client_info.current_query_id;
client_info.initial_address = client_info.current_address;
}
/// Per query settings are also passed via TCP.
/// We need to check them before applying due to they can violate the settings constraints.
auto settings_format = (client_tcp_protocol_version >= DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS) ? SettingsWriteFormat::STRINGS_WITH_FLAGS
@ -999,6 +991,15 @@ void TCPHandler::receiveQuery()
// so we have to apply the changes first.
query_context->setCurrentQueryId(state.query_id);
// Set parameters of initial query.
if (client_info.query_kind == ClientInfo::QueryKind::INITIAL_QUERY)
{
/// 'Current' fields was set at receiveHello.
client_info.initial_user = client_info.current_user;
client_info.initial_query_id = client_info.current_query_id;
client_info.initial_address = client_info.current_address;
}
/// Sync timeouts on client and server during current query to avoid dangling queries on server
/// NOTE: We use settings.send_timeout for the receive timeout and vice versa (change arguments ordering in TimeoutSetter),
/// because settings.send_timeout is client-side setting which has opposite meaning on the server side.

View File

@ -14,7 +14,32 @@ Don't use Docker from your system repository.
* [pip](https://pypi.python.org/pypi/pip) and `libpq-dev`. To install: `sudo apt-get install python3-pip libpq-dev zlib1g-dev libcrypto++-dev libssl-dev`
* [py.test](https://docs.pytest.org/) testing framework. To install: `sudo -H pip install pytest`
* [docker-compose](https://docs.docker.com/compose/) and additional python libraries. To install: `sudo -H pip install urllib3==1.23 pytest docker-compose==1.22.0 docker dicttoxml kazoo PyMySQL psycopg2==2.7.5 pymongo tzlocal kafka-python protobuf redis aerospike pytest-timeout minio confluent-kafka avro
* [docker-compose](https://docs.docker.com/compose/) and additional python libraries. To install:
```
sudo -H pip install \
PyMySQL \
aerospike \
avro \
cassandra-driver \
confluent-kafka \
dicttoxml \
docker \
docker-compose==1.22.0 \
grpcio \
grpcio-tools \
kafka-python \
kazoo \
minio \
protobuf \
psycopg2-binary==2.7.5 \
pymongo \
pytest \
pytest-timeout \
redis \
tzlocal \
urllib3
```
(highly not recommended) If you really want to use OS packages on modern debian/ubuntu instead of "pip": `sudo apt install -y docker docker-compose python3-pytest python3-dicttoxml python3-docker python3-pymysql python3-pymongo python3-tzlocal python3-kazoo python3-psycopg2 kafka-python python3-pytest-timeout python3-minio`

View File

@ -0,0 +1,2 @@
1 1
2 1

View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -ue
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. "$CURDIR"/../shell_config.sh
query_id=$(${CLICKHOUSE_CLIENT} -q "select lower(hex(reverse(reinterpretAsString(generateUUIDv4()))))")
${CLICKHOUSE_CLIENT} -q "select 1 format Null" "--query_id=$query_id"
${CLICKHOUSE_CURL} \
--header "X-ClickHouse-Query-Id: $query_id" \
"http://localhost:8123/" \
--get \
--data-urlencode "query=select 1 format Null"
${CLICKHOUSE_CLIENT} -n -q "
system flush logs;
select interface, initial_query_id = query_id
from system.query_log
where query_id = '$query_id' and type = 'QueryFinish'
order by interface
;
"