#pragma once #include #include #include namespace DB { class ASTCreateNamedCollectionQuery; class ASTDropNamedCollectionQuery; class ASTAlterNamedCollectionQuery; class NamedCollectionFactory : boost::noncopyable { public: static NamedCollectionFactory & instance(); ~NamedCollectionFactory(); bool exists(const std::string & collection_name) const; NamedCollectionPtr get(const std::string & collection_name) const; NamedCollectionPtr tryGet(const std::string & collection_name) const; NamedCollectionsMap getAll() const; void reloadFromConfig(const Poco::Util::AbstractConfiguration & config); void reloadFromSQL(); void createFromSQL(const ASTCreateNamedCollectionQuery & query); void removeFromSQL(const ASTDropNamedCollectionQuery & query); void updateFromSQL(const ASTAlterNamedCollectionQuery & query); bool usesReplicatedStorage(); void loadIfNot(); void shutdown(); protected: mutable NamedCollectionsMap loaded_named_collections; mutable std::mutex mutex; const LoggerPtr log = getLogger("NamedCollectionFactory"); bool loaded = false; std::atomic shutdown_called = false; std::unique_ptr metadata_storage; BackgroundSchedulePool::TaskHolder update_task; bool loadIfNot(std::lock_guard & lock); bool exists( const std::string & collection_name, std::lock_guard & lock) const; MutableNamedCollectionPtr getMutable(const std::string & collection_name, std::lock_guard & lock) const; void add(const std::string & collection_name, MutableNamedCollectionPtr collection, std::lock_guard & lock); void add(NamedCollectionsMap collections, std::lock_guard & lock); void update(NamedCollectionsMap collections, std::lock_guard & lock); void remove(const std::string & collection_name, std::lock_guard & lock); bool removeIfExists(const std::string & collection_name, std::lock_guard & lock); MutableNamedCollectionPtr tryGet(const std::string & collection_name, std::lock_guard & lock) const; void removeById(NamedCollection::SourceId id, std::lock_guard & lock); void loadFromConfig( const Poco::Util::AbstractConfiguration & config, std::lock_guard & lock); void loadFromSQL(std::lock_guard & lock); void updateFunc(); }; }