2019-02-05 18:07:00 +00:00
#!/usr/bin/env bash
CURDIR = $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd )
. $CURDIR /../shell_config.sh
. $CURDIR /mergetree_mutations.lib
2019-04-18 18:48:04 +00:00
${ CLICKHOUSE_CLIENT } --query= "DROP TABLE IF EXISTS test.kill_mutation_r1"
${ CLICKHOUSE_CLIENT } --query= "DROP TABLE IF EXISTS test.kill_mutation_r2"
2019-02-05 18:07:00 +00:00
2019-04-18 18:48:04 +00:00
${ CLICKHOUSE_CLIENT } --query= "CREATE TABLE test.kill_mutation_r1(d Date, x UInt32, s String) ENGINE ReplicatedMergeTree('/clickhouse/tables/test/kill_mutation', '1') ORDER BY x PARTITION BY d"
${ CLICKHOUSE_CLIENT } --query= "CREATE TABLE test.kill_mutation_r2(d Date, x UInt32, s String) ENGINE ReplicatedMergeTree('/clickhouse/tables/test/kill_mutation', '2') ORDER BY x PARTITION BY d"
2019-02-05 18:07:00 +00:00
2019-04-18 18:48:04 +00:00
${ CLICKHOUSE_CLIENT } --query= "INSERT INTO test.kill_mutation_r1 VALUES ('2000-01-01', 1, 'a')"
${ CLICKHOUSE_CLIENT } --query= "INSERT INTO test.kill_mutation_r1 VALUES ('2001-01-01', 2, 'b')"
2019-02-05 18:07:00 +00:00
${ CLICKHOUSE_CLIENT } --query= "SELECT '*** Create and kill a single invalid mutation ***'"
2019-12-18 13:00:20 +00:00
# wrong mutation
2019-12-19 15:27:56 +00:00
${ CLICKHOUSE_CLIENT } --query= "ALTER TABLE test.kill_mutation_r1 DELETE WHERE toUInt32(s) = 1 SETTINGS mutations_sync=2" 2>& 1 | grep -o "Mutation 0000000000 was killed" &
2019-02-05 18:07:00 +00:00
2020-03-16 14:05:11 +00:00
check_query1 = "SELECT count() FROM system.mutations WHERE database = 'test' AND table = 'kill_mutation_r1' AND is_done = 0"
2019-12-19 15:27:56 +00:00
query_result = ` $CLICKHOUSE_CLIENT --query= " $check_query1 " 2>& 1`
2020-03-16 14:05:11 +00:00
while [ " $query_result " = = "0" ]
2019-12-19 15:27:56 +00:00
do
query_result = ` $CLICKHOUSE_CLIENT --query= " $check_query1 " 2>& 1`
2020-03-16 14:05:11 +00:00
sleep 0.5
2019-12-19 15:27:56 +00:00
done
2020-03-16 14:05:11 +00:00
$CLICKHOUSE_CLIENT --query= "SELECT count() FROM system.mutations WHERE database = 'test' AND table = 'kill_mutation_r1' AND is_done = 0"
2019-02-05 18:07:00 +00:00
2020-03-16 14:05:11 +00:00
kill_message = $( ${ CLICKHOUSE_CLIENT } --query= "KILL MUTATION WHERE database = 'test' AND table = 'kill_mutation_r1'" )
2019-02-05 18:07:00 +00:00
2019-12-19 15:27:56 +00:00
wait
2020-03-16 14:05:11 +00:00
echo " $kill_message "
2020-03-11 10:28:24 +00:00
# No active mutations exists
${ CLICKHOUSE_CLIENT } --query= "SELECT count() FROM system.mutations WHERE database = 'test' AND table = 'kill_mutation_r1'"
2019-02-05 18:07:00 +00:00
${ CLICKHOUSE_CLIENT } --query= "SELECT '*** Create and kill invalid mutation that blocks another mutation ***'"
2019-04-18 18:48:04 +00:00
${ CLICKHOUSE_CLIENT } --query= "SYSTEM SYNC REPLICA test.kill_mutation_r1"
2020-03-11 10:28:24 +00:00
${ CLICKHOUSE_CLIENT } --query= "SYSTEM SYNC REPLICA test.kill_mutation_r2"
# Should be empty, but in case of problems we will see some diagnostics
${ CLICKHOUSE_CLIENT } --query= "SELECT * FROM system.replication_queue WHERE table like 'kill_mutation_r%'"
2019-04-18 18:48:04 +00:00
${ CLICKHOUSE_CLIENT } --query= "ALTER TABLE test.kill_mutation_r1 DELETE WHERE toUInt32(s) = 1"
2019-02-05 18:07:00 +00:00
2019-12-19 15:27:56 +00:00
# good mutation, but blocked with wrong mutation
${ CLICKHOUSE_CLIENT } --query= "ALTER TABLE test.kill_mutation_r1 DELETE WHERE x = 1 SETTINGS mutations_sync=2" &
2020-03-16 14:05:11 +00:00
check_query2 = "SELECT count() FROM system.mutations WHERE database = 'test' AND table = 'kill_mutation_r1' AND mutation_id = '0000000001' AND is_done = 0"
2019-12-19 15:27:56 +00:00
query_result = ` $CLICKHOUSE_CLIENT --query= " $check_query2 " 2>& 1`
2020-03-16 14:05:11 +00:00
while [ " $query_result " = = "0" ]
2019-12-19 15:27:56 +00:00
do
query_result = ` $CLICKHOUSE_CLIENT --query= " $check_query2 " 2>& 1`
2020-03-16 14:05:11 +00:00
sleep 0.5
2019-12-19 15:27:56 +00:00
done
2019-12-18 13:00:20 +00:00
2020-03-16 14:05:11 +00:00
$CLICKHOUSE_CLIENT --query= "SELECT count() FROM system.mutations WHERE database = 'test' AND table = 'kill_mutation_r1' AND mutation_id = '0000000001' AND is_done = 0"
2019-02-05 18:07:00 +00:00
2020-03-16 14:05:11 +00:00
kill_message = $( ${ CLICKHOUSE_CLIENT } --query= "KILL MUTATION WHERE database = 'test' AND table = 'kill_mutation_r1' AND mutation_id = '0000000001'" )
2019-02-05 18:07:00 +00:00
2019-12-19 15:27:56 +00:00
wait
2019-02-05 18:07:00 +00:00
2020-03-16 14:05:11 +00:00
echo " $kill_message "
2020-03-11 10:28:24 +00:00
${ CLICKHOUSE_CLIENT } --query= "SYSTEM SYNC REPLICA test.kill_mutation_r1"
${ CLICKHOUSE_CLIENT } --query= "SYSTEM SYNC REPLICA test.kill_mutation_r2"
2019-04-18 18:48:04 +00:00
${ CLICKHOUSE_CLIENT } --query= "SELECT * FROM test.kill_mutation_r2"
2020-03-11 10:28:24 +00:00
# must be empty
${ CLICKHOUSE_CLIENT } --query= "SELECT * FROM system.mutations WHERE table = 'kill_mutation' AND database = 'test' AND is_done = 0"
2019-02-05 18:07:00 +00:00
2019-04-18 18:48:04 +00:00
${ CLICKHOUSE_CLIENT } --query= "DROP TABLE test.kill_mutation_r1"
${ CLICKHOUSE_CLIENT } --query= "DROP TABLE test.kill_mutation_r2"