From 779a8f1305c5041cc0523607b21ff688c4a36db2 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Wed, 21 Sep 2022 03:10:18 +0300 Subject: [PATCH] tests: fix 02340_parts_refcnt_mergetree flakiness (#40998) --- .../02340_parts_refcnt_mergetree.sh | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/queries/0_stateless/02340_parts_refcnt_mergetree.sh b/tests/queries/0_stateless/02340_parts_refcnt_mergetree.sh index 5079977fea0..e8111bf7a03 100755 --- a/tests/queries/0_stateless/02340_parts_refcnt_mergetree.sh +++ b/tests/queries/0_stateless/02340_parts_refcnt_mergetree.sh @@ -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