2018-03-09 23:07:08 +00:00
#!/usr/bin/env bash
2019-08-22 21:35:16 +00:00
CLICKHOUSE_CLIENT_SERVER_LOGS_LEVEL = none
2018-03-09 23:07:08 +00:00
CURDIR = $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd )
2020-12-28 11:46:53 +00:00
# shellcheck source=../shell_config.sh
2020-08-01 00:51:12 +00:00
. " $CURDIR " /../shell_config.sh
2018-03-09 23:07:08 +00:00
2024-08-13 00:07:51 +00:00
TEST_PREFIX = " ${ CLICKHOUSE_DATABASE } "
2024-07-09 22:24:53 +00:00
${ CLICKHOUSE_CLIENT } -q " drop user if exists u_00600 ${ TEST_PREFIX } "
2024-07-24 07:57:56 +00:00
${ CLICKHOUSE_CLIENT } -q " create user u_00600 ${ TEST_PREFIX } settings max_execution_time=60, readonly=1, max_rows_to_read=0 "
2024-07-09 22:24:53 +00:00
${ CLICKHOUSE_CLIENT } -q " grant select on system.numbers to u_00600 ${ TEST_PREFIX } "
2018-03-09 23:07:08 +00:00
2019-07-20 00:47:06 +00:00
function wait_for_query_to_start( )
{
2024-08-12 05:39:25 +00:00
while [ [ 0 -eq $( $CLICKHOUSE_CURL -sS " $CLICKHOUSE_URL " -d " SELECT count() FROM system.processes WHERE query_id = ' $1 ' " ) ] ]
do
sleep 0.1
done
}
function wait_for_queries_to_finish( )
{
while [ [ 0 -ne $( $CLICKHOUSE_CURL -sS " $CLICKHOUSE_URL " -d " SELECT count() FROM system.processes WHERE current_database = ' ${ CLICKHOUSE_DATABASE } ' AND query NOT LIKE '%this query%' " ) ] ]
do
sleep 0.1
done
2019-07-20 00:47:06 +00:00
}
2024-08-13 14:20:50 +00:00
$CLICKHOUSE_CURL -sS " $CLICKHOUSE_URL &query_id= ${ CLICKHOUSE_DATABASE } hello&replace_running_query=1&max_rows_to_read=0 " -d 'SELECT 1, count() FROM system.numbers' > /dev/null 2>& 1 &
2024-08-13 00:07:51 +00:00
wait_for_query_to_start " ${ CLICKHOUSE_DATABASE } hello "
2019-07-20 00:47:06 +00:00
# Replace it
2024-08-13 00:07:51 +00:00
$CLICKHOUSE_CURL -sS " $CLICKHOUSE_URL &query_id= ${ CLICKHOUSE_DATABASE } hello&replace_running_query=1 " -d 'SELECT 0'
2019-07-20 00:47:06 +00:00
# Wait for it to be replaced
2018-03-09 23:07:08 +00:00
wait
2024-08-12 05:39:25 +00:00
wait_for_queries_to_finish
2019-06-30 13:17:27 +00:00
2024-08-13 00:07:51 +00:00
${ CLICKHOUSE_CLIENT_BINARY } --user= u_00600${ TEST_PREFIX } --query_id= " ${ CLICKHOUSE_DATABASE } 42 " --query= 'SELECT 2, count() FROM system.numbers' 2>& 1 | grep -cF 'QUERY_WAS_CANCELLED' &
wait_for_query_to_start " ${ CLICKHOUSE_DATABASE } 42 "
2019-08-22 21:35:16 +00:00
# Trying to run another query with the same query_id
2024-08-13 00:07:51 +00:00
${ CLICKHOUSE_CLIENT } --query_id= " ${ CLICKHOUSE_DATABASE } 42 " --query= 'SELECT 43' 2>& 1 | grep -cF 'is already running by user'
2019-08-22 21:35:16 +00:00
# Trying to replace query of a different user
2024-08-13 00:07:51 +00:00
$CLICKHOUSE_CURL -sS " $CLICKHOUSE_URL &query_id= ${ CLICKHOUSE_DATABASE } 42&replace_running_query=1 " -d 'SELECT 1' | grep -cF 'is already running by user'
2019-08-22 21:35:16 +00:00
2024-08-13 00:07:51 +00:00
$CLICKHOUSE_CURL -sS " $CLICKHOUSE_URL " -d " KILL QUERY WHERE query_id = ' ${ CLICKHOUSE_DATABASE } 42' SYNC " > /dev/null
2019-06-30 13:17:27 +00:00
wait
2024-08-12 05:39:25 +00:00
wait_for_queries_to_finish
2019-06-30 13:17:27 +00:00
2024-08-13 14:20:50 +00:00
${ CLICKHOUSE_CLIENT } --query_id= " ${ CLICKHOUSE_DATABASE } 42 " --max_rows_to_read= 0 --query= 'SELECT 3, count() FROM system.numbers' 2>& 1 | grep -cF 'QUERY_WAS_CANCELLED' &
2024-08-13 00:07:51 +00:00
wait_for_query_to_start " ${ CLICKHOUSE_DATABASE } 42 "
${ CLICKHOUSE_CLIENT } --query_id= " ${ CLICKHOUSE_DATABASE } 42 " --replace_running_query= 1 --replace_running_query_max_wait_ms= 500 --query= 'SELECT 43' 2>& 1 | grep -F "can't be stopped" > /dev/null
2019-06-30 13:17:27 +00:00
wait
2024-08-12 05:39:25 +00:00
wait_for_queries_to_finish
2024-08-13 00:07:51 +00:00
${ CLICKHOUSE_CLIENT } --query_id= " ${ CLICKHOUSE_DATABASE } 42 " --replace_running_query= 1 --query= 'SELECT 44'
2024-07-09 22:24:53 +00:00
${ CLICKHOUSE_CLIENT } -q " drop user u_00600 ${ TEST_PREFIX } "