From cdc529fa2a3cd4c464ff674f57657c07e6c14ea7 Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Fri, 11 Mar 2022 16:03:05 +0000 Subject: [PATCH] Add database_replicated_allow_only_replicated_engine setting. --- src/Core/Settings.h | 1 + src/Interpreters/InterpreterCreateQuery.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/Core/Settings.h b/src/Core/Settings.h index 5280e4b3eeb..821b1a44625 100644 --- a/src/Core/Settings.h +++ b/src/Core/Settings.h @@ -506,6 +506,7 @@ class IColumn; M(UInt64, database_replicated_initial_query_timeout_sec, 300, "How long initial DDL query should wait for Replicated database to precess previous DDL queue entries", 0) \ M(UInt64, max_distributed_depth, 5, "Maximum distributed query depth", 0) \ M(Bool, database_replicated_always_detach_permanently, false, "Execute DETACH TABLE as DETACH TABLE PERMANENTLY if database engine is Replicated", 0) \ + M(Bool, database_replicated_allow_only_replicated_engine, false, "Allow to create only Replicated tables in database with engine Replicated", 0) \ M(DistributedDDLOutputMode, distributed_ddl_output_mode, DistributedDDLOutputMode::THROW, "Format of distributed DDL query result", 0) \ M(UInt64, distributed_ddl_entry_format_version, 1, "Version of DDL entry to write into ZooKeeper", 0) \ \ diff --git a/src/Interpreters/InterpreterCreateQuery.cpp b/src/Interpreters/InterpreterCreateQuery.cpp index ed996430996..517e6cf89dd 100644 --- a/src/Interpreters/InterpreterCreateQuery.cpp +++ b/src/Interpreters/InterpreterCreateQuery.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -94,6 +95,7 @@ namespace ErrorCodes extern const int PATH_ACCESS_DENIED; extern const int NOT_IMPLEMENTED; extern const int ENGINE_REQUIRED; + extern const int UNKNOWN_STORAGE; } namespace fs = std::filesystem; @@ -1195,6 +1197,14 @@ bool InterpreterCreateQuery::doCreateTable(ASTCreateQuery & create, addColumnsDescriptionToCreateQueryIfNecessary(query_ptr->as(), res); } + if (!create.attach && getContext()->getSettingsRef().database_replicated_allow_only_replicated_engine) + { + bool is_replicated_storage = typeid_cast(res.get()) != nullptr; + if (!is_replicated_storage && database && database->getEngineName() != "Replicated") + throw Exception(ErrorCodes::UNKNOWN_STORAGE, + "Only Replicated tables are allowed in database engine is Replicated"); + } + if (from_path && !res->storesDataOnDisk()) throw Exception(ErrorCodes::NOT_IMPLEMENTED, "ATTACH ... FROM ... query is not supported for {} table engine, "