2020-07-25 14:42:20 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-09-12 12:35:27 +00:00
|
|
|
# Tags: no-replicated-database, no-parallel
|
2020-07-25 14:42:20 +00:00
|
|
|
|
2020-07-26 14:21:57 +00:00
|
|
|
set -e
|
|
|
|
|
2020-07-25 14:42:20 +00:00
|
|
|
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-07-25 14:42:20 +00:00
|
|
|
|
|
|
|
$CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS sticking_mutations"
|
|
|
|
|
2020-07-26 14:21:57 +00:00
|
|
|
function check_sticky_mutations()
|
|
|
|
{
|
|
|
|
$CLICKHOUSE_CLIENT -n --query "CREATE TABLE sticking_mutations (
|
|
|
|
date Date,
|
|
|
|
key UInt64,
|
|
|
|
value1 String,
|
|
|
|
value2 UInt8
|
|
|
|
)
|
|
|
|
ENGINE = MergeTree()
|
|
|
|
ORDER BY key;"
|
2020-07-25 14:42:20 +00:00
|
|
|
|
2020-07-26 14:21:57 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query "INSERT INTO sticking_mutations SELECT toDate('2020-07-10'), number, toString(number), number % 128 FROM numbers(1000)"
|
2020-07-25 14:42:20 +00:00
|
|
|
|
2020-07-26 14:21:57 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query "INSERT INTO sticking_mutations SELECT toDate('2100-01-10'), number, toString(number), number % 128 FROM numbers(1000)"
|
2020-07-25 14:42:20 +00:00
|
|
|
|
2020-07-26 14:21:57 +00:00
|
|
|
# if merges stopped for normal merge tree mutations will stick
|
|
|
|
$CLICKHOUSE_CLIENT --query "SYSTEM STOP MERGES sticking_mutations"
|
2020-07-25 14:42:20 +00:00
|
|
|
|
2020-07-26 14:21:57 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query "$1" &
|
2020-07-25 14:42:20 +00:00
|
|
|
|
2020-07-26 14:21:57 +00:00
|
|
|
##### wait mutation to start #####
|
|
|
|
check_query="SELECT count() FROM system.mutations WHERE table='sticking_mutations' and database='$CLICKHOUSE_DATABASE' and is_done = 0"
|
2020-07-25 14:42:20 +00:00
|
|
|
|
2020-08-01 01:20:22 +00:00
|
|
|
query_result=$($CLICKHOUSE_CLIENT --query="$check_query" 2>&1)
|
2020-07-25 14:42:20 +00:00
|
|
|
|
2021-07-30 16:34:18 +00:00
|
|
|
for _ in {1..50}
|
2020-07-26 14:21:57 +00:00
|
|
|
do
|
2020-08-01 01:20:22 +00:00
|
|
|
query_result=$($CLICKHOUSE_CLIENT --query="$check_query" 2>&1)
|
2021-07-30 16:34:18 +00:00
|
|
|
if ! [ "$query_result" == "0" ]; then break; fi
|
2020-07-26 14:21:57 +00:00
|
|
|
sleep 0.5
|
|
|
|
done
|
|
|
|
##### wait mutation to start #####
|
2020-07-25 14:42:20 +00:00
|
|
|
|
2020-07-26 14:21:57 +00:00
|
|
|
# Starting merges to execute sticked mutations
|
2020-07-25 14:42:20 +00:00
|
|
|
|
2020-07-26 14:21:57 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query "SYSTEM START MERGES sticking_mutations"
|
2020-07-25 14:42:20 +00:00
|
|
|
|
2020-12-21 10:09:07 +00:00
|
|
|
# Just to be sure, that previous mutations finished
|
2020-07-26 14:21:57 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query "ALTER TABLE sticking_mutations DELETE WHERE value2 % 31 == 0 SETTINGS mutations_sync = 1"
|
2020-07-25 14:42:20 +00:00
|
|
|
|
2020-07-26 14:21:57 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query "OPTIMIZE TABLE sticking_mutations FINAL"
|
2020-07-25 14:42:20 +00:00
|
|
|
|
2020-07-26 14:21:57 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query "SELECT sum(cityHash64(*)) > 1 FROM sticking_mutations WHERE key > 10"
|
|
|
|
|
|
|
|
$CLICKHOUSE_CLIENT --query "SHOW CREATE TABLE sticking_mutations"
|
|
|
|
|
|
|
|
$CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS sticking_mutations"
|
|
|
|
}
|
|
|
|
|
|
|
|
check_sticky_mutations "ALTER TABLE sticking_mutations DELETE WHERE value2 % 32 == 0, MODIFY COLUMN value1 UInt64"
|
|
|
|
|
|
|
|
check_sticky_mutations "ALTER TABLE sticking_mutations MODIFY COLUMN value1 UInt64, DELETE WHERE value2 % 32 == 0"
|
|
|
|
|
|
|
|
check_sticky_mutations "ALTER TABLE sticking_mutations UPDATE value1 = 15 WHERE key < 2000, DELETE WHERE value2 % 32 == 0"
|
|
|
|
|
|
|
|
check_sticky_mutations "ALTER TABLE sticking_mutations DELETE WHERE value2 % 32 == 0, UPDATE value1 = 15 WHERE key < 2000"
|
|
|
|
|
|
|
|
check_sticky_mutations "ALTER TABLE sticking_mutations DELETE WHERE value2 % 32 == 0, DROP COLUMN value1"
|
|
|
|
|
|
|
|
check_sticky_mutations "ALTER TABLE sticking_mutations DELETE WHERE value2 % 32 == 0, RENAME COLUMN value1 TO renamed_value1"
|
|
|
|
|
|
|
|
check_sticky_mutations "ALTER TABLE sticking_mutations MODIFY COLUMN value1 UInt64, MODIFY TTL date + INTERVAL 1 DAY"
|