mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-05 22:12:21 +00:00
1b4adc963f
02015_shard_crash_clang_12_build OK 30.39 01014_lazy_database_concurrent_recreate_reattach_and_show_tables OK 31.27 01034_move_partition_from_table_zookeeper OK 32.34 01035_concurrent_move_partition_from_table_zookeeper OK 35.35 00183_skip_unavailable_shards OK 36.69 01593_concurrent_alter_mutations_kill OK 38.36 02122_parallel_formatting OK 39.27 02100_multiple_hosts_command_line_set OK 44.04 01114_database_atomic OK 45.67 01287_max_execution_speed OK 90.98 01599_multiline_input_and_singleline_comments OK 180.09
67 lines
2.7 KiB
Bash
Executable File
67 lines
2.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Tags: no-parallel, no-fasttest
|
|
|
|
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
# shellcheck source=../shell_config.sh
|
|
. "$CURDIR"/../shell_config.sh
|
|
|
|
$CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS concurrent_mutate_kill"
|
|
|
|
$CLICKHOUSE_CLIENT --query "CREATE TABLE concurrent_mutate_kill (key UInt64, value String) ENGINE = ReplicatedMergeTree('/clickhouse/tables/$CLICKHOUSE_TEST_ZOOKEEPER_PREFIX/concurrent_mutate_kill', '1') ORDER BY key PARTITION BY key % 100 SETTINGS max_replicated_mutations_in_queue=1000, number_of_free_entries_in_pool_to_execute_mutation=0,max_replicated_merges_in_queue=1000"
|
|
|
|
$CLICKHOUSE_CLIENT --query "INSERT INTO concurrent_mutate_kill SELECT number, toString(number) FROM numbers(1000000)"
|
|
|
|
function alter_thread
|
|
{
|
|
TYPE=$($CLICKHOUSE_CLIENT --query "SELECT type FROM system.columns WHERE table='concurrent_mutate_kill' and database='${CLICKHOUSE_DATABASE}' and name='value'")
|
|
if [ "$TYPE" == "String" ]; then
|
|
$CLICKHOUSE_CLIENT --query "ALTER TABLE concurrent_mutate_kill MODIFY COLUMN value UInt64 SETTINGS replication_alter_partitions_sync=2"
|
|
else
|
|
$CLICKHOUSE_CLIENT --query "ALTER TABLE concurrent_mutate_kill MODIFY COLUMN value String SETTINGS replication_alter_partitions_sync=2"
|
|
fi
|
|
}
|
|
|
|
function kill_mutation_thread
|
|
{
|
|
# find any mutation and kill it
|
|
mutation_id=$($CLICKHOUSE_CLIENT --query "SELECT mutation_id FROM system.mutations WHERE is_done=0 and database='${CLICKHOUSE_DATABASE}' and table='concurrent_mutate_kill' LIMIT 1")
|
|
if [ ! -z "$mutation_id" ]; then
|
|
$CLICKHOUSE_CLIENT --query "KILL MUTATION WHERE mutation_id='$mutation_id' and table='concurrent_mutate_kill' and database='${CLICKHOUSE_DATABASE}'" 1> /dev/null
|
|
sleep 1
|
|
fi
|
|
}
|
|
|
|
|
|
export -f alter_thread
|
|
export -f kill_mutation_thread
|
|
|
|
TIMEOUT=30
|
|
|
|
clickhouse_client_loop_timeout $TIMEOUT alter_thread 2> /dev/null &
|
|
clickhouse_client_loop_timeout $TIMEOUT kill_mutation_thread 2> /dev/null &
|
|
|
|
wait
|
|
|
|
$CLICKHOUSE_CLIENT --query "SYSTEM SYNC REPLICA concurrent_mutate_kill"
|
|
|
|
# with timeout alter query can be not finished yet, so to execute new alter
|
|
# we use retries
|
|
counter=0
|
|
while true; do
|
|
if $CLICKHOUSE_CLIENT --query "ALTER TABLE concurrent_mutate_kill MODIFY COLUMN value Int64 SETTINGS replication_alter_partitions_sync=2" 2> /dev/null ; then
|
|
break
|
|
fi
|
|
|
|
if [ "$counter" -gt 120 ]
|
|
then
|
|
break
|
|
fi
|
|
sleep 0.5
|
|
counter=$(($counter + 1))
|
|
done
|
|
|
|
$CLICKHOUSE_CLIENT --query "SHOW CREATE TABLE concurrent_mutate_kill"
|
|
$CLICKHOUSE_CLIENT --query "OPTIMIZE TABLE concurrent_mutate_kill FINAL"
|
|
$CLICKHOUSE_CLIENT --query "SELECT sum(value) FROM concurrent_mutate_kill"
|
|
$CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS concurrent_mutate_kill"
|