From c1c132502c64d52e5867e3cc4ed6e3b2523567d8 Mon Sep 17 00:00:00 2001 From: Val Date: Fri, 24 Apr 2020 17:12:54 +0300 Subject: [PATCH] add prototypes of loadStoredObject and some relevant helpers in replicateddb --- dbms/src/Databases/DatabaseReplicated.cpp | 22 ++++++++ dbms/src/Databases/DatabaseReplicated.h | 61 +++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 dbms/src/Databases/DatabaseReplicated.h diff --git a/dbms/src/Databases/DatabaseReplicated.cpp b/dbms/src/Databases/DatabaseReplicated.cpp index e18fc1db5f4..fd5f53a596c 100644 --- a/dbms/src/Databases/DatabaseReplicated.cpp +++ b/dbms/src/Databases/DatabaseReplicated.cpp @@ -190,4 +190,26 @@ void DatabaseReplicated::drop(const Context & context) // 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 new file mode 100644 index 00000000000..51f7763bb5a --- /dev/null +++ b/dbms/src/Databases/DatabaseReplicated.h @@ -0,0 +1,61 @@ +#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); +}; + +}