ClickHouse/tests/queries/0_stateless/01019_alter_materialized_view_atomic.sh

57 lines
1.3 KiB
Bash
Raw Normal View History

2020-01-31 17:12:18 +00:00
#!/usr/bin/env bash
set -e
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
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
trap 'exit' INT
2020-01-31 17:12:18 +00:00
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
2020-05-12 23:55:16 +00:00
while true; do
$CLICKHOUSE_CLIENT --allow_experimental_alter_materialized_view_structure=1 -q "${ALTERS[$RANDOM % 2]}"
sleep "$(echo 0.$RANDOM)";
2020-05-12 23:55:16 +00:00
done
2020-01-31 17:12:18 +00:00
}
2020-05-12 23:55:16 +00:00
export -f alter_thread;
timeout 10 bash -c 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
$CLICKHOUSE_CLIENT -q "DROP VIEW mv"
$CLICKHOUSE_CLIENT -q "DROP TABLE src"