2020-01-31 17:12:18 +00:00
|
|
|
#!/usr/bin/env bash
|
2022-02-26 19:09:34 +00:00
|
|
|
# Tags: long
|
2020-01-31 17:12:18 +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
|
2020-01-31 17:12:18 +00:00
|
|
|
|
|
|
|
$CLICKHOUSE_CLIENT --multiquery <<EOF
|
|
|
|
DROP TABLE IF EXISTS src;
|
|
|
|
DROP TABLE IF EXISTS mv;
|
|
|
|
|
2020-05-12 23:55:16 +00:00
|
|
|
CREATE TABLE src (v UInt64) ENGINE = Null;
|
|
|
|
CREATE MATERIALIZED VIEW mv (v UInt8) Engine = MergeTree() ORDER BY v AS SELECT v FROM src;
|
2020-01-31 17:12:18 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
# Test that ALTER doesn't cause data loss or duplication.
|
|
|
|
#
|
|
|
|
# Idea for future:
|
|
|
|
#
|
|
|
|
# null
|
|
|
|
# / \
|
|
|
|
# mv1 mv2
|
|
|
|
# \ /
|
|
|
|
# \ /
|
|
|
|
# mv sink
|
|
|
|
#
|
|
|
|
# Insert N times into null while altering sink query and switching it from mv1 to mv2.
|
|
|
|
|
|
|
|
function alter_thread()
|
|
|
|
{
|
2020-05-12 23:55:16 +00:00
|
|
|
ALTERS[0]="ALTER TABLE mv MODIFY QUERY SELECT v FROM src;"
|
|
|
|
ALTERS[1]="ALTER TABLE mv MODIFY QUERY SELECT v * 2 as v FROM src;"
|
2020-01-31 17:12:18 +00:00
|
|
|
|
2022-02-26 19:09:34 +00:00
|
|
|
$CLICKHOUSE_CLIENT --allow_experimental_alter_materialized_view_structure=1 -q "${ALTERS[$RANDOM % 2]}"
|
|
|
|
sleep 0.$RANDOM
|
2020-01-31 17:12:18 +00:00
|
|
|
}
|
|
|
|
|
2022-02-26 19:09:34 +00:00
|
|
|
export -f alter_thread
|
|
|
|
clickhouse_client_loop_timeout 10 alter_thread &
|
2020-01-31 17:12:18 +00:00
|
|
|
|
2020-08-01 00:40:56 +00:00
|
|
|
for _ in {1..100}; do
|
2020-01-31 17:12:18 +00:00
|
|
|
# Retry (hopefully retriable (deadlock avoided)) errors.
|
2020-05-12 23:55:16 +00:00
|
|
|
while true; do
|
2020-08-01 00:40:56 +00:00
|
|
|
$CLICKHOUSE_CLIENT -q "INSERT INTO src VALUES (1);" 2>/dev/null && break
|
2020-01-31 17:12:18 +00:00
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
$CLICKHOUSE_CLIENT -q "SELECT count() FROM mv;"
|
2020-05-12 23:55:16 +00:00
|
|
|
wait
|
2020-12-04 02:15:44 +00:00
|
|
|
|
|
|
|
$CLICKHOUSE_CLIENT -q "DROP VIEW mv"
|
|
|
|
$CLICKHOUSE_CLIENT -q "DROP TABLE src"
|