2021-11-24 19:45:10 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Tags: race
|
|
|
|
|
|
|
|
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
|
|
# shellcheck source=../shell_config.sh
|
|
|
|
. "$CURDIR"/../shell_config.sh
|
|
|
|
|
2023-07-07 02:41:47 +00:00
|
|
|
$CLICKHOUSE_CLIENT -q "drop table if exists mt"
|
|
|
|
|
2023-07-26 20:38:14 +00:00
|
|
|
$CLICKHOUSE_CLIENT -q "create table mt (n int) engine=MergeTree order by n settings parts_to_throw_insert=5000"
|
2021-11-24 19:45:10 +00:00
|
|
|
$CLICKHOUSE_CLIENT -q "insert into mt values (1)"
|
|
|
|
$CLICKHOUSE_CLIENT -q "insert into mt values (2)"
|
|
|
|
$CLICKHOUSE_CLIENT -q "insert into mt values (3)"
|
|
|
|
|
|
|
|
function thread_insert()
|
|
|
|
{
|
2023-07-07 11:57:12 +00:00
|
|
|
local TIMELIMIT=$((SECONDS+$1))
|
|
|
|
while [ $SECONDS -lt "$TIMELIMIT" ]; do
|
|
|
|
$CLICKHOUSE_CLIENT -q "insert into mt values (rand())";
|
2022-05-28 17:20:32 +00:00
|
|
|
done
|
2021-11-24 19:45:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function thread_detach_attach()
|
|
|
|
{
|
2023-07-07 11:57:12 +00:00
|
|
|
local TIMELIMIT=$((SECONDS+$1))
|
|
|
|
while [ $SECONDS -lt "$TIMELIMIT" ]; do
|
2022-05-28 17:20:32 +00:00
|
|
|
$CLICKHOUSE_CLIENT -q "alter table mt detach partition id 'all'";
|
|
|
|
$CLICKHOUSE_CLIENT -q "alter table mt attach partition id 'all'";
|
|
|
|
done
|
2021-11-24 19:45:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function thread_drop_detached()
|
|
|
|
{
|
2023-07-07 11:57:12 +00:00
|
|
|
local TIMELIMIT=$((SECONDS+$1))
|
|
|
|
while [ $SECONDS -lt "$TIMELIMIT" ]; do
|
2023-02-07 12:46:00 +00:00
|
|
|
$CLICKHOUSE_CLIENT --allow_drop_detached 1 -q "alter table mt drop detached partition id 'all'";
|
2022-05-28 17:20:32 +00:00
|
|
|
done
|
2021-11-24 19:45:10 +00:00
|
|
|
}
|
|
|
|
|
2022-05-28 17:20:32 +00:00
|
|
|
export -f thread_insert;
|
|
|
|
export -f thread_detach_attach;
|
|
|
|
export -f thread_drop_detached;
|
2021-11-24 19:45:10 +00:00
|
|
|
|
|
|
|
TIMEOUT=10
|
|
|
|
|
2023-07-07 11:57:12 +00:00
|
|
|
thread_insert $TIMEOUT &
|
|
|
|
thread_detach_attach $TIMEOUT 2> /dev/null &
|
|
|
|
thread_detach_attach $TIMEOUT 2> /dev/null &
|
|
|
|
thread_drop_detached $TIMEOUT 2> /dev/null &
|
2021-11-24 19:45:10 +00:00
|
|
|
|
|
|
|
wait
|
|
|
|
|
|
|
|
$CLICKHOUSE_CLIENT -q "drop table mt"
|