2019-03-07 18:16:36 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-09-12 12:35:27 +00:00
|
|
|
# Tags: long
|
2019-03-07 18:16:36 +00:00
|
|
|
|
|
|
|
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-03-07 18:16:36 +00:00
|
|
|
|
2022-05-28 17:20:32 +00:00
|
|
|
echo "DROP TABLE IF EXISTS concurrent_alter_column" | ${CLICKHOUSE_CLIENT}
|
|
|
|
echo "CREATE TABLE concurrent_alter_column (ts DATETIME) ENGINE = MergeTree PARTITION BY toStartOfDay(ts) ORDER BY tuple()" | ${CLICKHOUSE_CLIENT}
|
|
|
|
|
2019-08-28 19:36:04 +00:00
|
|
|
function thread1()
|
|
|
|
{
|
2022-05-28 17:20:32 +00:00
|
|
|
while true; do
|
|
|
|
for i in {1..500}; do echo "ALTER TABLE concurrent_alter_column ADD COLUMN c$i DOUBLE;"; done | ${CLICKHOUSE_CLIENT} -n --query_id=alter_00816_1
|
|
|
|
done
|
2019-08-28 19:36:04 +00:00
|
|
|
}
|
2019-03-07 18:16:36 +00:00
|
|
|
|
2019-08-28 19:36:04 +00:00
|
|
|
function thread2()
|
|
|
|
{
|
2022-05-28 17:20:32 +00:00
|
|
|
while true; do
|
|
|
|
echo "ALTER TABLE concurrent_alter_column ADD COLUMN d DOUBLE" | ${CLICKHOUSE_CLIENT} --query_id=alter_00816_2;
|
|
|
|
sleep "$(echo 0.0$RANDOM)";
|
|
|
|
echo "ALTER TABLE concurrent_alter_column DROP COLUMN d" | ${CLICKHOUSE_CLIENT} --query_id=alter_00816_2;
|
|
|
|
done
|
2019-08-28 19:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function thread3()
|
|
|
|
{
|
2022-05-28 17:20:32 +00:00
|
|
|
while true; do
|
|
|
|
echo "ALTER TABLE concurrent_alter_column ADD COLUMN e DOUBLE" | ${CLICKHOUSE_CLIENT} --query_id=alter_00816_3;
|
|
|
|
sleep "$(echo 0.0$RANDOM)";
|
|
|
|
echo "ALTER TABLE concurrent_alter_column DROP COLUMN e" | ${CLICKHOUSE_CLIENT} --query_id=alter_00816_3;
|
|
|
|
done
|
2019-08-28 19:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function thread4()
|
|
|
|
{
|
2022-05-28 17:20:32 +00:00
|
|
|
while true; do
|
|
|
|
echo "ALTER TABLE concurrent_alter_column ADD COLUMN f DOUBLE" | ${CLICKHOUSE_CLIENT} --query_id=alter_00816_4;
|
|
|
|
sleep "$(echo 0.0$RANDOM)";
|
|
|
|
echo "ALTER TABLE concurrent_alter_column DROP COLUMN f" | ${CLICKHOUSE_CLIENT} --query_id=alter_00816_4;
|
|
|
|
done
|
2019-08-28 19:36:04 +00:00
|
|
|
}
|
|
|
|
|
2022-05-28 17:20:32 +00:00
|
|
|
# https://stackoverflow.com/questions/9954794/execute-a-shell-function-with-timeout
|
|
|
|
export -f thread1;
|
|
|
|
export -f thread2;
|
|
|
|
export -f thread3;
|
|
|
|
export -f thread4;
|
2019-08-28 19:36:04 +00:00
|
|
|
|
|
|
|
TIMEOUT=30
|
|
|
|
|
2022-05-28 17:20:32 +00:00
|
|
|
timeout $TIMEOUT bash -c thread1 2> /dev/null &
|
|
|
|
timeout $TIMEOUT bash -c thread2 2> /dev/null &
|
|
|
|
timeout $TIMEOUT bash -c thread3 2> /dev/null &
|
|
|
|
timeout $TIMEOUT bash -c thread4 2> /dev/null &
|
2019-03-07 18:16:36 +00:00
|
|
|
|
|
|
|
wait
|
|
|
|
|
2023-05-03 18:06:46 +00:00
|
|
|
echo "DROP TABLE concurrent_alter_column SYNC" | ${CLICKHOUSE_CLIENT} # SYNC has effect only for Atomic database
|
2022-05-28 17:20:32 +00:00
|
|
|
|
|
|
|
# Wait for alters and check for deadlocks (in case of deadlock this loop will not finish)
|
|
|
|
while true; do
|
|
|
|
echo "SELECT * FROM system.processes WHERE query_id LIKE 'alter\\_00816\\_%'" | ${CLICKHOUSE_CLIENT} | grep -q -F 'alter' || break
|
|
|
|
sleep 1;
|
|
|
|
done
|
|
|
|
|
2019-03-07 18:16:36 +00:00
|
|
|
echo 'did not crash'
|