ClickHouse/tests/queries/0_stateless/00909_kill_not_initialized_query.sh

53 lines
2.3 KiB
Bash
Raw Normal View History

2019-02-25 15:03:37 +00:00
#!/usr/bin/env bash
set -e
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
2019-02-25 15:03:37 +00:00
$CLICKHOUSE_CLIENT -q "DROP TABLE IF EXISTS cannot_kill_query"
$CLICKHOUSE_CLIENT -q "CREATE TABLE cannot_kill_query (x UInt64) ENGINE = MergeTree ORDER BY x" &> /dev/null
$CLICKHOUSE_CLIENT -q "INSERT INTO cannot_kill_query SELECT * FROM numbers(10000000)" &> /dev/null
2019-02-25 15:03:37 +00:00
2019-03-06 17:10:26 +00:00
# This SELECT query will run for a long time. It's used as bloker for ALTER query. It will be killed with SYNC kill.
2019-06-29 15:26:19 +00:00
query_for_pending="SELECT count() FROM cannot_kill_query WHERE NOT ignore(sleep(1)) SETTINGS max_threads = 1, max_block_size = 1"
2019-02-25 15:03:37 +00:00
$CLICKHOUSE_CLIENT -q "$query_for_pending" &>/dev/null &
2019-03-06 17:10:26 +00:00
sleep 1 # queries should be in strict order
# This ALTER query will wait until $query_for_pending finished. Also it will block $query_to_kill.
$CLICKHOUSE_CLIENT -q "ALTER TABLE cannot_kill_query MODIFY COLUMN x UInt64" &>/dev/null &
2019-02-25 15:03:37 +00:00
2019-03-06 17:10:26 +00:00
sleep 1
# This SELECT query will also run for a long time. Also it's blocked by ALTER query. It will be killed with ASYNC kill.
# This is main idea which we check -- blocked queries can be killed with ASYNC kill.
2019-06-29 15:26:19 +00:00
query_to_kill="SELECT sum(1) FROM cannot_kill_query WHERE NOT ignore(sleep(1)) SETTINGS max_threads = 1"
2019-02-25 15:03:37 +00:00
$CLICKHOUSE_CLIENT -q "$query_to_kill" &>/dev/null &
2019-03-06 17:10:26 +00:00
sleep 1 # just to be sure that kill of $query_to_kill will be executed after $query_to_kill.
2019-02-25 15:03:37 +00:00
2019-03-06 17:10:26 +00:00
# Kill $query_to_kill with ASYNC kill. We will check that information about KILL is not lost.
$CLICKHOUSE_CLIENT -q "KILL QUERY WHERE query='$query_to_kill' ASYNC" &>/dev/null
2019-02-25 15:03:37 +00:00
2019-03-06 17:10:26 +00:00
sleep 1
2019-02-25 15:03:37 +00:00
2019-03-06 17:10:26 +00:00
# Kill $query_for_pending SYNC. This query is not blocker, so it should be killed fast.
2020-08-01 13:25:59 +00:00
timeout 20 ${CLICKHOUSE_CLIENT} -q "KILL QUERY WHERE query='$query_for_pending' SYNC" &>/dev/null
2019-03-06 17:10:26 +00:00
# Both queries have to be killed, doesn't matter with SYNC or ASYNC kill
2020-08-01 00:40:56 +00:00
for _ in {1..15}
2019-03-07 13:42:58 +00:00
do
sleep 1
no_first_query=$($CLICKHOUSE_CLIENT -q "SELECT count() FROM system.processes where query='$query_for_pending'")
no_second_query=$($CLICKHOUSE_CLIENT -q "SELECT count() FROM system.processes where query='$query_to_kill'")
if [ "$no_first_query" == "0" ] && [ "$no_second_query" == "0" ]; then
2019-03-07 13:42:58 +00:00
echo "killed"
break
fi
done
2019-02-25 15:03:37 +00:00
$CLICKHOUSE_CLIENT -q "DROP TABLE IF EXISTS cannot_kill_query" &>/dev/null