From 0d392bbb34c142f6871a2bd2ab699f5baa768780 Mon Sep 17 00:00:00 2001 From: Val Date: Wed, 29 Apr 2020 14:19:16 +0300 Subject: [PATCH] fix after rebase --- src/Databases/DatabaseFactory.cpp | 17 +++++++++- src/Databases/DatabaseReplicated.cpp | 49 +++++++++++++++------------- src/Databases/DatabaseReplicated.h | 7 ++-- 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/src/Databases/DatabaseFactory.cpp b/src/Databases/DatabaseFactory.cpp index f27bc509ebe..0d7a711b530 100644 --- a/src/Databases/DatabaseFactory.cpp +++ b/src/Databases/DatabaseFactory.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -69,7 +70,7 @@ DatabasePtr DatabaseFactory::getImpl( { String engine_name = engine_define->engine->name; - if (engine_name != "MySQL" && engine_name != "Lazy" && engine_define->engine->arguments) + if (engine_name != "MySQL" && engine_name != "Lazy" && engine_name != "Replicated" && engine_define->engine->arguments) throw Exception("Database engine " + engine_name + " cannot have arguments", ErrorCodes::BAD_ARGUMENTS); if (engine_define->engine->parameters || engine_define->partition_by || engine_define->primary_key || engine_define->order_by || @@ -138,6 +139,20 @@ DatabasePtr DatabaseFactory::getImpl( return std::make_shared(database_name, metadata_path, cache_expiration_time_seconds, context); } + else if (engine_name == "Replicated") + { + const ASTFunction * engine = engine_define->engine; + + if (!engine->arguments || engine->arguments->children.size() != 2) + throw Exception("Replicated database requires zoo_path and replica_name arguments", ErrorCodes::BAD_ARGUMENTS); + + const auto & arguments = engine->arguments->children; + + const auto zoo_path = arguments[0]->as()->value.safeGet(); + const auto replica_name = arguments[1]->as()->value.safeGet(); + return std::make_shared(database_name, metadata_path, zoo_path, replica_name, context); + } + throw Exception("Unknown database engine: " + engine_name, ErrorCodes::UNKNOWN_DATABASE_ENGINE); } diff --git a/src/Databases/DatabaseReplicated.cpp b/src/Databases/DatabaseReplicated.cpp index fd5f53a596c..92af1c890c2 100644 --- a/src/Databases/DatabaseReplicated.cpp +++ b/src/Databases/DatabaseReplicated.cpp @@ -125,8 +125,8 @@ void DatabaseReplicated::createTable( Coordination::Requests ops; ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path, "", zkutil::CreateMode::Persistent)); - ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/metadata", metadata, - zkutil::CreateMode::Persistent)); + //ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/metadata", metadata, + //zkutil::CreateMode::Persistent)); // ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/columns", getColumns().toString(), // zkutil::CreateMode::Persistent)); ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/log", "", @@ -160,23 +160,24 @@ void DatabaseReplicated::renameTable( const String & table_name, IDatabase & to_database, const String & to_table_name, - TableStructureWriteLockHolder & lock) + bool exchange) { // try - DatabaseOnDisk::renameTable(context, table_name, to_database, to_table_name, lock); - // replicated stuff - String statement = getObjectDefinitionFromCreateQuery(query); + DatabaseOnDisk::renameTable(context, table_name, to_database, to_table_name, exchange); + // replicated stuff; what to put to a znode + // String statement = getObjectDefinitionFromCreateQuery(query); // this one is fairly more complex } -void DatabaseReplicated::removeTable( +void DatabaseReplicated::dropTable( const Context & context, - const String & table_name) + const String & table_name, + bool no_delay) { // try - DatabaseOnDisk::removeTable(context, table_name); + DatabaseOnDisk::dropTable(context, table_name, no_delay); // replicated stuff - String statement = getObjectDefinitionFromCreateQuery(query); + //String statement = getObjectDefinitionFromCreateQuery(query); // ... } @@ -184,13 +185,26 @@ void DatabaseReplicated::drop(const Context & context) { DatabaseOnDisk::drop(context); // replicated stuff - String statement = getObjectDefinitionFromCreateQuery(query); + //String statement = getObjectDefinitionFromCreateQuery(query); // should it be possible to recover after a drop. // if not, we can just delete all the zookeeper nodes starting from // zookeeper path. does it work recursively? hope so... } -void DatabaseOrdinary::loadStoredObjects( +// sync replica's zookeeper metadata +void DatabaseReplicated::syncReplicaState(Context & context) { + auto c = context; // fixes unuser parameter error + return; +} + +// get the up to date metadata from zookeeper to local metadata dir +// for replicated (only?) tables +void DatabaseReplicated::updateMetadata(Context & context) { + auto c = context; // fixes unuser parameter error + return; +} + +void DatabaseReplicated::loadStoredObjects( Context & context, bool has_force_restore_data_flag) { @@ -201,15 +215,6 @@ void DatabaseOrdinary::loadStoredObjects( } -// sync replica's zookeeper metadata -void syncReplicaState(Context & context) { - -} - -// get the up to date metadata from zookeeper to local metadata dir -// for replicated (only?) tables -void updateMetadata(Context & context) { - -} + } diff --git a/src/Databases/DatabaseReplicated.h b/src/Databases/DatabaseReplicated.h index 51f7763bb5a..bc1af923277 100644 --- a/src/Databases/DatabaseReplicated.h +++ b/src/Databases/DatabaseReplicated.h @@ -24,16 +24,17 @@ public: const StoragePtr & table, const ASTPtr & query) override; - void removeTable( + void dropTable( const Context & context, - const String & table_name) override; + const String & table_name, + bool no_delay) override; void renameTable( const Context & context, const String & table_name, IDatabase & to_database, const String & to_table_name, - TableStructureWriteLockHolder & lock) override; + bool exchange) override; void drop(const Context & context) override;