From 1cb96bf1762cc8b111f0cb58ed651059156442e2 Mon Sep 17 00:00:00 2001 From: Val Date: Wed, 29 Apr 2020 14:21:12 +0300 Subject: [PATCH] rm old files from nonexistant dir since the rebase --- dbms/src/Databases/DatabaseReplicated.cpp | 215 ---------------------- dbms/src/Databases/DatabaseReplicated.h | 61 ------ 2 files changed, 276 deletions(-) delete mode 100644 dbms/src/Databases/DatabaseReplicated.cpp delete mode 100644 dbms/src/Databases/DatabaseReplicated.h diff --git a/dbms/src/Databases/DatabaseReplicated.cpp b/dbms/src/Databases/DatabaseReplicated.cpp deleted file mode 100644 index fd5f53a596c..00000000000 --- a/dbms/src/Databases/DatabaseReplicated.cpp +++ /dev/null @@ -1,215 +0,0 @@ -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -namespace DB -{ - - -namespace ErrorCodes -{ - extern const int NO_ZOOKEEPER; -} - -void DatabaseReplicated::setZooKeeper(zkutil::ZooKeeperPtr zookeeper) -{ - std::lock_guard lock(current_zookeeper_mutex); - current_zookeeper = zookeeper; -} - -zkutil::ZooKeeperPtr DatabaseReplicated::tryGetZooKeeper() const -{ - std::lock_guard lock(current_zookeeper_mutex); - return current_zookeeper; -} - -zkutil::ZooKeeperPtr DatabaseReplicated::getZooKeeper() const -{ - auto res = tryGetZooKeeper(); - if (!res) - throw Exception("Cannot get ZooKeeper", ErrorCodes::NO_ZOOKEEPER); - return res; -} - - -DatabaseReplicated::DatabaseReplicated( - const String & name_, - const String & metadata_path_, - const String & zookeeper_path_, - const String & replica_name_, - const Context & context_) - : DatabaseOrdinary(name_, metadata_path_, context_) - , zookeeper_path(zookeeper_path_) - , replica_name(replica_name_) -{ - - if (!zookeeper_path.empty() && zookeeper_path.back() == '/') - zookeeper_path.resize(zookeeper_path.size() - 1); - /// If zookeeper chroot prefix is used, path should start with '/', because chroot concatenates without it. - if (!zookeeper_path.empty() && zookeeper_path.front() != '/') - zookeeper_path = "/" + zookeeper_path; - replica_path = zookeeper_path + "/replicas/" + replica_name; - - if (context_.hasZooKeeper()) { - current_zookeeper = context_.getZooKeeper(); - } - - if (!current_zookeeper) - { - // TODO wtf is attach - // if (!attach) - throw Exception("Can't create replicated table without ZooKeeper", ErrorCodes::NO_ZOOKEEPER); - - /// Do not activate the replica. It will be readonly. - // TODO is it relevant for engines? - // LOG_ERROR(log, "No ZooKeeper: database will be in readonly mode."); - // TODO is_readonly = true; - // return; - } - - // can the zk path exist and no metadata on disk be available at the same moment? if so, in such a case, the db instance must be restored. - - current_zookeeper->createIfNotExists(zookeeper_path, String()); - current_zookeeper->createIfNotExists(replica_path, String()); - // TODO what to do? - // TODO createDatabaseIfNotExists ? - // TODO check database structure ? -} - -void DatabaseReplicated::createTable( - const Context & context, - const String & table_name, - const StoragePtr & table, - const ASTPtr & query) -{ - // try - DatabaseOnDisk::createTable(context, table_name, table, query); - - // replicated stuff - String statement = getObjectDefinitionFromCreateQuery(query); - auto zookeeper = getZooKeeper(); - // TODO в чем прикол именно так создавать зиноды? - 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 + "/columns", getColumns().toString(), -// zkutil::CreateMode::Persistent)); - ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/log", "", - zkutil::CreateMode::Persistent)); -// ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/blocks", "", -// zkutil::CreateMode::Persistent)); -// ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/block_numbers", "", -// zkutil::CreateMode::Persistent)); -// ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/nonincrement_block_numbers", "", -// zkutil::CreateMode::Persistent)); /// /nonincrement_block_numbers dir is unused, but is created nonetheless for backwards compatibility. - // TODO do we need a leader here? (probably yes) what is it gonna do? - ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/leader_election", "", - zkutil::CreateMode::Persistent)); - ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/temp", "", - zkutil::CreateMode::Persistent)); - ops.emplace_back(zkutil::makeCreateRequest(zookeeper_path + "/replicas", "", - zkutil::CreateMode::Persistent)); - - Coordination::Responses responses; - auto code = zookeeper->tryMulti(ops, responses); - if (code && code != Coordination::ZNODEEXISTS) - throw Coordination::Exception(code); - - // ... - -} - - -void DatabaseReplicated::renameTable( - const Context & context, - const String & table_name, - IDatabase & to_database, - const String & to_table_name, - TableStructureWriteLockHolder & lock) -{ - // try - DatabaseOnDisk::renameTable(context, table_name, to_database, to_table_name, lock); - // replicated stuff - String statement = getObjectDefinitionFromCreateQuery(query); - // this one is fairly more complex -} - -void DatabaseReplicated::removeTable( - const Context & context, - const String & table_name) -{ - // try - DatabaseOnDisk::removeTable(context, table_name); - // replicated stuff - String statement = getObjectDefinitionFromCreateQuery(query); - // ... -} - -void DatabaseReplicated::drop(const Context & context) -{ - DatabaseOnDisk::drop(context); - // replicated stuff - 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( - Context & context, - bool has_force_restore_data_flag) -{ - syncReplicaState(context); - updateMetadata(context); - - DatabaseOrdinary::loadStoredObjects(context, has_force_restore_data_flag); - -} - -// 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/dbms/src/Databases/DatabaseReplicated.h b/dbms/src/Databases/DatabaseReplicated.h deleted file mode 100644 index 51f7763bb5a..00000000000 --- a/dbms/src/Databases/DatabaseReplicated.h +++ /dev/null @@ -1,61 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace DB -{ -/** Replicated database engine. - * It stores tables list using list of .sql files, - * that contain declaration of table represented by SQL ATTACH TABLE query - * and operation log in zookeeper - */ -class DatabaseReplicated : public DatabaseOrdinary -{ -public: - DatabaseReplicated(const String & name_, const String & metadata_path_, const String & zookeeper_path_, const String & replica_name_, const Context & context); - - String getEngineName() const override { return "Replicated"; } - - void createTable( - const Context & context, - const String & table_name, - const StoragePtr & table, - const ASTPtr & query) override; - - void removeTable( - const Context & context, - const String & table_name) override; - - void renameTable( - const Context & context, - const String & table_name, - IDatabase & to_database, - const String & to_table_name, - TableStructureWriteLockHolder & lock) override; - - void drop(const Context & context) override; - - void loadStoredObjects( - Context & context, - bool has_force_restore_data_flag) override; - -private: - String zookeeper_path; - String replica_name; - String replica_path; - - zkutil::ZooKeeperPtr current_zookeeper; /// Use only the methods below. - mutable std::mutex current_zookeeper_mutex; /// To recreate the session in the background thread. - - zkutil::ZooKeeperPtr tryGetZooKeeper() const; - zkutil::ZooKeeperPtr getZooKeeper() const; - void setZooKeeper(zkutil::ZooKeeperPtr zookeeper); - - void syncReplicaState(Context & context); - - void updateMetadata(Context & context); -}; - -}