From 6f79f987191c8196f6b8f26fc395b15448fd0202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=93=D0=B0=D1=80?= =?UTF-8?q?=D0=B1=D0=B0=D1=80?= Date: Thu, 28 Dec 2023 00:54:10 +0300 Subject: [PATCH] Throw on ordinary db engine --- src/Databases/DatabaseOrdinary.cpp | 4 + .../test_ordinary.py | 106 ++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 tests/integration/test_modify_engine_on_restart/test_ordinary.py diff --git a/src/Databases/DatabaseOrdinary.cpp b/src/Databases/DatabaseOrdinary.cpp index 8caefdca2a3..e5ab7589b1c 100644 --- a/src/Databases/DatabaseOrdinary.cpp +++ b/src/Databases/DatabaseOrdinary.cpp @@ -80,6 +80,10 @@ void DatabaseOrdinary::convertMergeTreeToReplicatedIfNeeded(ASTPtr ast, const Qu if (!fs::exists(convert_to_replicated_flag_path)) return; + if (getUUID() == UUIDHelpers::Nil) + throw Exception(ErrorCodes::NOT_IMPLEMENTED, + "Table engine conversion to replicated is supported only for Atomic databases. Convert your database engine to Atomic first."); + LOG_INFO(log, "Found convert_to_replicated flag for table {}. Will try to change it's engine in metadata to replicated table.", backQuote(qualified_name.getFullName())); /// Get storage definition diff --git a/tests/integration/test_modify_engine_on_restart/test_ordinary.py b/tests/integration/test_modify_engine_on_restart/test_ordinary.py new file mode 100644 index 00000000000..7e9830c5166 --- /dev/null +++ b/tests/integration/test_modify_engine_on_restart/test_ordinary.py @@ -0,0 +1,106 @@ +import pytest +from helpers.cluster import ClickHouseCluster + +cluster = ClickHouseCluster(__file__) +ch1 = cluster.add_instance( + "ch1", + main_configs=[ + "configs/config.d/clusters.xml", + "configs/config.d/distributed_ddl.xml", + ], + with_zookeeper=True, + macros={"replica": "node1"}, + stay_alive=True, +) + +database_name = "modify_engine_on_ordinary" + + +@pytest.fixture(scope="module") +def started_cluster(): + try: + cluster.start() + yield cluster + + finally: + cluster.shutdown() + + +def q(node, query): + return node.query(database=database_name, sql=query) + +def create_tables(): + q( + ch1, + "CREATE TABLE mt ( A Int64, D Date, S String ) ENGINE MergeTree() PARTITION BY toYYYYMM(D) ORDER BY A;", + ) + +def check_tables(): + # Check tables exists + assert ( + q( + ch1, + "SHOW TABLES", + ).strip() + == "mt" + ) + + # Check engines + assert ( + q( + ch1, + f"SELECT name, engine FROM system.tables WHERE database = '{database_name}'", + ).strip() + == f"mt\tMergeTree" + ) + + +def set_convert_flags(): + ch1.exec_in_container( + [ + "bash", + "-c", + f"mkdir /var/lib/clickhouse/data/{database_name}/mt/flags", + ] + ) + ch1.exec_in_container( + [ + "bash", + "-c", + f"touch /var/lib/clickhouse/data/{database_name}/mt/flags/convert_to_replicated", + ] + ) + +def remove_convert_flags(): + ch1.exec_in_container( + [ + "bash", + "-c", + f"rm -rf /var/lib/clickhouse/data/{database_name}/mt/flags", + ] + ) + +def test_modify_engine_on_restart_ordinary_database(started_cluster): + ch1.query( + sql=f"CREATE DATABASE {database_name} ENGINE = Ordinary", + settings={"allow_deprecated_database_ordinary": 1}, + ) + + create_tables() + + check_tables() + + set_convert_flags() + + cannot_start = False + try: + ch1.restart_clickhouse() + except: + cannot_start = True + assert cannot_start + + remove_convert_flags() + + ch1.restart_clickhouse() + + check_tables()