From 8fcdcd25fac3de6ea9cd4b081917036d19545d54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mar=C3=ADn?= Date: Thu, 10 Oct 2024 10:12:04 +0800 Subject: [PATCH] Revert "Support CREATE OR REPLACE VIEW atomically" --- src/Analyzer/Resolve/IdentifierResolver.cpp | 8 --- src/Common/ErrorCodes.cpp | 11 ++-- src/Interpreters/InterpreterCreateQuery.cpp | 9 ++-- src/Storages/IStorage.cpp | 20 +++---- .../02437_drop_mv_restart_replicas.sh | 2 +- ...ew_atomically_with_atomic_engine.reference | 0 ...lace_view_atomically_with_atomic_engine.sh | 52 ------------------- ...tomically_with_replicated_engine.reference | 0 ..._view_atomically_with_replicated_engine.sh | 52 ------------------- 9 files changed, 20 insertions(+), 134 deletions(-) delete mode 100644 tests/queries/0_stateless/03237_create_or_replace_view_atomically_with_atomic_engine.reference delete mode 100755 tests/queries/0_stateless/03237_create_or_replace_view_atomically_with_atomic_engine.sh delete mode 100644 tests/queries/0_stateless/03238_create_or_replace_view_atomically_with_replicated_engine.reference delete mode 100755 tests/queries/0_stateless/03238_create_or_replace_view_atomically_with_replicated_engine.sh diff --git a/src/Analyzer/Resolve/IdentifierResolver.cpp b/src/Analyzer/Resolve/IdentifierResolver.cpp index 15a90c52a2a..7efc0d2a367 100644 --- a/src/Analyzer/Resolve/IdentifierResolver.cpp +++ b/src/Analyzer/Resolve/IdentifierResolver.cpp @@ -432,14 +432,6 @@ QueryTreeNodePtr IdentifierResolver::tryResolveTableIdentifierFromDatabaseCatalo else storage = DatabaseCatalog::instance().tryGetTable(storage_id, context); - if (!storage && storage_id.hasUUID()) - { - // If `storage_id` has UUID, it is possible that the UUID is removed from `DatabaseCatalog` after `context->resolveStorageID(storage_id)` - // We try to get the table with the database name and the table name. - auto database = DatabaseCatalog::instance().tryGetDatabase(storage_id.getDatabaseName()); - if (database) - storage = database->tryGetTable(table_name, context); - } if (!storage) return {}; diff --git a/src/Common/ErrorCodes.cpp b/src/Common/ErrorCodes.cpp index 9f07c3ed5d5..09a5375191b 100644 --- a/src/Common/ErrorCodes.cpp +++ b/src/Common/ErrorCodes.cpp @@ -452,7 +452,7 @@ M(553, LZMA_STREAM_ENCODER_FAILED) \ M(554, LZMA_STREAM_DECODER_FAILED) \ M(555, ROCKSDB_ERROR) \ - M(556, SYNC_MYSQL_USER_ACCESS_ERROR) \ + M(556, SYNC_MYSQL_USER_ACCESS_ERROR)\ M(557, UNKNOWN_UNION) \ M(558, EXPECTED_ALL_OR_DISTINCT) \ M(559, INVALID_GRPC_QUERY_INFO) \ @@ -578,7 +578,7 @@ M(697, CANNOT_RESTORE_TO_NONENCRYPTED_DISK) \ M(698, INVALID_REDIS_STORAGE_TYPE) \ M(699, INVALID_REDIS_TABLE_STRUCTURE) \ - M(700, USER_SESSION_LIMIT_EXCEEDED) \ + M(700, USER_SESSION_LIMIT_EXCEEDED) \ M(701, CLUSTER_DOESNT_EXIST) \ M(702, CLIENT_INFO_DOES_NOT_MATCH) \ M(703, INVALID_IDENTIFIER) \ @@ -610,16 +610,15 @@ M(729, ILLEGAL_TIME_SERIES_TAGS) \ M(730, REFRESH_FAILED) \ M(731, QUERY_CACHE_USED_WITH_NON_THROW_OVERFLOW_MODE) \ - M(733, TABLE_IS_BEING_RESTARTED) \ -\ + \ M(900, DISTRIBUTED_CACHE_ERROR) \ M(901, CANNOT_USE_DISTRIBUTED_CACHE) \ -\ + \ M(999, KEEPER_EXCEPTION) \ M(1000, POCO_EXCEPTION) \ M(1001, STD_EXCEPTION) \ M(1002, UNKNOWN_EXCEPTION) \ - /* See END */ +/* See END */ #ifdef APPLY_FOR_EXTERNAL_ERROR_CODES #define APPLY_FOR_ERROR_CODES(M) APPLY_FOR_BUILTIN_ERROR_CODES(M) APPLY_FOR_EXTERNAL_ERROR_CODES(M) diff --git a/src/Interpreters/InterpreterCreateQuery.cpp b/src/Interpreters/InterpreterCreateQuery.cpp index 647a1ba098e..83904e7ad21 100644 --- a/src/Interpreters/InterpreterCreateQuery.cpp +++ b/src/Interpreters/InterpreterCreateQuery.cpp @@ -1668,8 +1668,7 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create) if (need_add_to_database && !database) throw Exception(ErrorCodes::UNKNOWN_DATABASE, "Database {} does not exist", backQuoteIfNeed(database_name)); - if (create.replace_table - || (create.replace_view && (database->getEngineName() == "Atomic" || database->getEngineName() == "Replicated"))) + if (create.replace_table) { chassert(!ddl_guard); return doCreateOrReplaceTable(create, properties, mode); @@ -2030,16 +2029,16 @@ BlockIO InterpreterCreateQuery::doCreateOrReplaceTable(ASTCreateQuery & create, auto ast_rename = std::make_shared(ASTRenameQuery::Elements{std::move(elem)}); ast_rename->dictionary = create.is_dictionary; - if (create.create_or_replace || create.replace_view) + if (create.create_or_replace) { - /// CREATE OR REPLACE TABLE/VIEW + /// CREATE OR REPLACE TABLE /// Will execute ordinary RENAME instead of EXCHANGE if the target table does not exist ast_rename->rename_if_cannot_exchange = true; ast_rename->exchange = false; } else { - /// REPLACE TABLE/VIEW + /// REPLACE TABLE /// Will execute EXCHANGE query and fail if the target table does not exist ast_rename->exchange = true; } diff --git a/src/Storages/IStorage.cpp b/src/Storages/IStorage.cpp index 23f1811d330..a2efa4201a7 100644 --- a/src/Storages/IStorage.cpp +++ b/src/Storages/IStorage.cpp @@ -31,7 +31,6 @@ namespace ErrorCodes extern const int NOT_IMPLEMENTED; extern const int DEADLOCK_AVOIDED; extern const int CANNOT_RESTORE_TABLE; - extern const int TABLE_IS_BEING_RESTARTED; } IStorage::IStorage(StorageID storage_id_, std::unique_ptr metadata_) @@ -67,13 +66,12 @@ RWLockImpl::LockHolder IStorage::tryLockTimed( TableLockHolder IStorage::lockForShare(const String & query_id, const std::chrono::milliseconds & acquire_timeout) { TableLockHolder result = tryLockTimed(drop_lock, RWLockImpl::Read, query_id, acquire_timeout); - auto table_id = getStorageID(); - if (!table_id.hasUUID() && (is_dropped || is_detached)) - throw Exception(ErrorCodes::TABLE_IS_DROPPED, "Table {}.{} is dropped or detached", table_id.database_name, table_id.table_name); - if (is_being_restarted) - throw Exception( - ErrorCodes::TABLE_IS_BEING_RESTARTED, "Table {}.{} is being restarted", table_id.database_name, table_id.table_name); + if (is_dropped || is_detached) + { + auto table_id = getStorageID(); + throw Exception(ErrorCodes::TABLE_IS_DROPPED, "Table {}.{} is dropped or detached", table_id.database_name, table_id.table_name); + } return result; } @@ -81,10 +79,12 @@ TableLockHolder IStorage::tryLockForShare(const String & query_id, const std::ch { TableLockHolder result = tryLockTimed(drop_lock, RWLockImpl::Read, query_id, acquire_timeout); - auto table_id = getStorageID(); - if (is_being_restarted || (!table_id.hasUUID() && (is_dropped || is_detached))) - // Table was dropped or is being restarted while acquiring the lock + if (is_dropped || is_detached) + { + // Table was dropped while acquiring the lock result = nullptr; + } + return result; } diff --git a/tests/queries/0_stateless/02437_drop_mv_restart_replicas.sh b/tests/queries/0_stateless/02437_drop_mv_restart_replicas.sh index af6d15b60e6..44076aeba18 100755 --- a/tests/queries/0_stateless/02437_drop_mv_restart_replicas.sh +++ b/tests/queries/0_stateless/02437_drop_mv_restart_replicas.sh @@ -53,7 +53,7 @@ export -f thread_restart; TIMEOUT=15 -timeout $TIMEOUT bash -c thread_ddl 2>&1| grep -Fa "Exception: " | grep -Fv -e "TABLE_IS_DROPPED" -e "UNKNOWN_TABLE" -e "DATABASE_NOT_EMPTY" -e "TABLE_IS_BEING_RESTARTED" & +timeout $TIMEOUT bash -c thread_ddl 2>&1| grep -Fa "Exception: " | grep -Fv -e "TABLE_IS_DROPPED" -e "UNKNOWN_TABLE" -e "DATABASE_NOT_EMPTY" & timeout $TIMEOUT bash -c thread_insert 2> /dev/null & timeout $TIMEOUT bash -c thread_restart 2>&1| grep -Fa "Exception: " | grep -Fv -e "is currently dropped or renamed" -e "is being dropped or detached" & diff --git a/tests/queries/0_stateless/03237_create_or_replace_view_atomically_with_atomic_engine.reference b/tests/queries/0_stateless/03237_create_or_replace_view_atomically_with_atomic_engine.reference deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/tests/queries/0_stateless/03237_create_or_replace_view_atomically_with_atomic_engine.sh b/tests/queries/0_stateless/03237_create_or_replace_view_atomically_with_atomic_engine.sh deleted file mode 100755 index cc0e6c0d113..00000000000 --- a/tests/queries/0_stateless/03237_create_or_replace_view_atomically_with_atomic_engine.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash - -CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -# shellcheck source=../shell_config.sh -. "$CUR_DIR"/../shell_config.sh - -# with Atomic engine -$CLICKHOUSE_CLIENT --query "CREATE DATABASE IF NOT EXISTS ${CLICKHOUSE_DATABASE}_db ENGINE=Atomic" - -function create_or_replace_view_thread -{ - for _ in {1..20}; do - $CLICKHOUSE_CLIENT --query "CREATE OR REPLACE VIEW ${CLICKHOUSE_DATABASE}_db.test_view AS SELECT 'abcdef'" > /dev/null - done -} -export -f create_or_replace_view_thread; - -function select_view_thread -{ - for _ in {1..20}; do - $CLICKHOUSE_CLIENT --query "SELECT * FROM ${CLICKHOUSE_DATABASE}_db.test_view" > /dev/null - done -} -export -f select_view_thread; - -$CLICKHOUSE_CLIENT --query "CREATE OR REPLACE VIEW ${CLICKHOUSE_DATABASE}_db.test_view AS SELECT 'abcdef'" > /dev/null - -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & - -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & - -wait \ No newline at end of file diff --git a/tests/queries/0_stateless/03238_create_or_replace_view_atomically_with_replicated_engine.reference b/tests/queries/0_stateless/03238_create_or_replace_view_atomically_with_replicated_engine.reference deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/tests/queries/0_stateless/03238_create_or_replace_view_atomically_with_replicated_engine.sh b/tests/queries/0_stateless/03238_create_or_replace_view_atomically_with_replicated_engine.sh deleted file mode 100755 index 04adc38e34b..00000000000 --- a/tests/queries/0_stateless/03238_create_or_replace_view_atomically_with_replicated_engine.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash - -CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -# shellcheck source=../shell_config.sh -. "$CUR_DIR"/../shell_config.sh - -# with Replicated engine -$CLICKHOUSE_CLIENT --query "CREATE DATABASE IF NOT EXISTS ${CLICKHOUSE_DATABASE}_db ENGINE=Replicated('/test/clickhouse/db/${CLICKHOUSE_DATABASE}_db', 's1', 'r1')" - -function create_or_replace_view_thread -{ - for _ in {1..15}; do - $CLICKHOUSE_CLIENT --query "CREATE OR REPLACE VIEW ${CLICKHOUSE_DATABASE}_db.test_view AS SELECT 'abcdef'" > /dev/null - done -} -export -f create_or_replace_view_thread; - -function select_view_thread -{ - for _ in {1..15}; do - $CLICKHOUSE_CLIENT --query "SELECT * FROM ${CLICKHOUSE_DATABASE}_db.test_view" > /dev/null - done -} -export -f select_view_thread; - -$CLICKHOUSE_CLIENT --query "CREATE OR REPLACE VIEW ${CLICKHOUSE_DATABASE}_db.test_view AS SELECT 'abcdef'" > /dev/null - -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & -bash -c select_view_thread & - -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & -bash -c create_or_replace_view_thread & - -wait \ No newline at end of file