tests: fix 02340_parts_refcnt_mergetree flakiness (#40998)

This commit is contained in:
Azat Khuzhin 2022-09-21 03:10:18 +03:00 committed by GitHub
parent 9e1bb19559
commit 779a8f1305
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Tags: no-fasttest
# Tags: no-fasttest, long
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
@ -16,9 +16,10 @@ function check_refcnt_for_table()
query_id="$table-$(random_str 10)"
# Notes:
# - query may sleep 0.1*(200/4)=5 seconds, it is enough to check system.parts
# - query may sleep 1*(200/4)=50 seconds maximum, it is enough to check system.parts
# - "part = 1" condition should prune all parts except first
$CLICKHOUSE_CLIENT --format Null --max_block_size 1 --query_id "$query_id" -q "select sleepEachRow(0.1) from $table where part = 1" &
# - max_block_size=1 with index_granularity=1 will allow to cancel the query earlier
$CLICKHOUSE_CLIENT --format Null --max_threads 1 --max_block_size 1 --query_id "$query_id" -q "select sleepEachRow(1) from $table where part = 1" &
PID=$!
# wait for query to be started
@ -30,26 +31,30 @@ function check_refcnt_for_table()
# however when it starts reading, partition pruning takes place,
# and it should hold only parts that are required for SELECT
#
# So 2 seconds delay to ensure that it goes the reading stage.
sleep 2
# But to reach partition prune the function sleepEachRow() will be executed twice,
# so 2 seconds for sleepEachRow() and 3 seconds just to ensure that it enters the reading stage.
sleep $((2+3))
# NOTE: parts that are used in query will have refcount increased for each range
$CLICKHOUSE_CLIENT -q "select table, name, refcount from system.parts where database = '$CLICKHOUSE_DATABASE' and table = '$table' and refcount > 1"
# Kill the query gracefully.
kill -INT $PID
wait $PID
}
# NOTE: index_granularity=1 to cancel ASAP
$CLICKHOUSE_CLIENT -nmq "
drop table if exists data_02340;
create table data_02340 (key Int, part Int) engine=MergeTree() partition by part order by key;
"
create table data_02340 (key Int, part Int) engine=MergeTree() partition by part order by key settings index_granularity=1;
" || exit 1
check_refcnt_for_table data_02340
$CLICKHOUSE_CLIENT -nmq "
drop table if exists data_02340_rep;
create table data_02340_rep (key Int, part Int) engine=ReplicatedMergeTree('/clickhouse/$CLICKHOUSE_TEST_ZOOKEEPER_PREFIX', '1') partition by part order by key;
"
create table data_02340_rep (key Int, part Int) engine=ReplicatedMergeTree('/clickhouse/$CLICKHOUSE_TEST_ZOOKEEPER_PREFIX', '1') partition by part order by key settings index_granularity=1;
" || exit 1
check_refcnt_for_table data_02340_rep
exit 0