From e531e0a0ab70cea10821abc7af6186b7c70a7f1a Mon Sep 17 00:00:00 2001 From: alesapin Date: Mon, 17 Feb 2020 16:20:09 +0300 Subject: [PATCH] Add test with bad alter --- .../MergeTree/ReplicatedMergeTreeQueue.cpp | 6 +++ .../01079_bad_alters_zookeeper.reference | 8 ++++ .../0_stateless/01079_bad_alters_zookeeper.sh | 41 +++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 dbms/tests/queries/0_stateless/01079_bad_alters_zookeeper.reference create mode 100755 dbms/tests/queries/0_stateless/01079_bad_alters_zookeeper.sh diff --git a/dbms/src/Storages/MergeTree/ReplicatedMergeTreeQueue.cpp b/dbms/src/Storages/MergeTree/ReplicatedMergeTreeQueue.cpp index ada136eaba2..664816ba51e 100644 --- a/dbms/src/Storages/MergeTree/ReplicatedMergeTreeQueue.cpp +++ b/dbms/src/Storages/MergeTree/ReplicatedMergeTreeQueue.cpp @@ -749,6 +749,12 @@ ReplicatedMergeTreeMutationEntryPtr ReplicatedMergeTreeQueue::removeMutation( mutations_by_partition.erase(partition_and_block_num.first); } + if (entry->alter_version != -1) + { + LOG_DEBUG(log, "Removed alter " << entry->alter_version << " because mutation " + entry->znode_name + " were killed."); + alter_chain.finishDataAlter(entry->alter_version, state_lock); + } + mutations_by_znode.erase(it); LOG_DEBUG(log, "Removed mutation " + entry->znode_name + " from local state."); } diff --git a/dbms/tests/queries/0_stateless/01079_bad_alters_zookeeper.reference b/dbms/tests/queries/0_stateless/01079_bad_alters_zookeeper.reference new file mode 100644 index 00000000000..198f79cf9a4 --- /dev/null +++ b/dbms/tests/queries/0_stateless/01079_bad_alters_zookeeper.reference @@ -0,0 +1,8 @@ +Wrong column name. +CREATE TABLE default.table_for_bad_alters (`key` UInt64, `value1` UInt8, `value2` String) ENGINE = ReplicatedMergeTree(\'/clickhouse/tables/table_for_bad_alters\', \'1\') ORDER BY key SETTINGS index_granularity = 8192 +CREATE TABLE default.table_for_bad_alters (`key` UInt64, `value1` UInt8, `value2` UInt32) ENGINE = ReplicatedMergeTree(\'/clickhouse/tables/table_for_bad_alters\', \'1\') ORDER BY key SETTINGS index_granularity = 8192 +syntax error at begin of string. +7 +Hello +World +Wrong index name. diff --git a/dbms/tests/queries/0_stateless/01079_bad_alters_zookeeper.sh b/dbms/tests/queries/0_stateless/01079_bad_alters_zookeeper.sh new file mode 100755 index 00000000000..b00215271fc --- /dev/null +++ b/dbms/tests/queries/0_stateless/01079_bad_alters_zookeeper.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +. $CURDIR/../shell_config.sh + +$CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS table_for_bad_alters"; + +$CLICKHOUSE_CLIENT -n --query "CREATE TABLE table_for_bad_alters ( + key UInt64, + value1 UInt8, + value2 String +) ENGINE = ReplicatedMergeTree('/clickhouse/tables/table_for_bad_alters', '1') +ORDER BY key;" + +$CLICKHOUSE_CLIENT --query "INSERT INTO table_for_bad_alters VALUES(1, 1, 'Hello');" +$CLICKHOUSE_CLIENT --query "ALTER TABLE table_for_bad_alters MODIFY COLUMN value1 UInt32, DROP COLUMN non_existing_column" 2>&1 | grep -o "Wrong column name." | uniq +$CLICKHOUSE_CLIENT --query "SHOW CREATE TABLE table_for_bad_alters;" # nothing changed + +$CLICKHOUSE_CLIENT --query "ALTER TABLE table_for_bad_alters MODIFY COLUMN value2 UInt32 SETTINGS replication_alter_partitions_sync=0;" + +sleep 2 + +while [[ $($CLICKHOUSE_CLIENT --query "KILL MUTATION WHERE mutation_id='0000000000'" 2>&1) ]]; do + sleep 1 +done + +$CLICKHOUSE_CLIENT --query "SHOW CREATE TABLE table_for_bad_alters;" # Type changed, but we can revert back + +$CLICKHOUSE_CLIENT --query "INSERT INTO table_for_bad_alters VALUES(2, 2, 7)" + +$CLICKHOUSE_CLIENT --query "SELECT distinct(value2) FROM table_for_bad_alters" 2>&1 | grep -o 'syntax error at begin of string.' | uniq + +$CLICKHOUSE_CLIENT --query "ALTER TABLE table_for_bad_alters MODIFY COLUMN value2 String SETTINGS replication_alter_partitions_sync=2" + +$CLICKHOUSE_CLIENT --query "INSERT INTO table_for_bad_alters VALUES(3, 3, 'World')" + +$CLICKHOUSE_CLIENT --query "SELECT value2 FROM table_for_bad_alters ORDER BY value2" + +$CLICKHOUSE_CLIENT --query "ALTER TABLE table_for_bad_alters DROP INDEX idx2" 2>&1 | grep -o 'Wrong index name.' | uniq + +$CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS table_for_bad_alters"