ClickHouse/src/Databases/DatabasesCommon.h

56 lines
2.2 KiB
C++
Raw Normal View History

#pragma once
2021-10-02 07:13:14 +00:00
#include <base/types.h>
#include <Parsers/IAST.h>
#include <Storages/IStorage_fwd.h>
#include <Databases/IDatabase.h>
2019-08-28 13:21:19 +00:00
#include <mutex>
2017-05-23 18:33:48 +00:00
2017-04-17 11:56:55 +00:00
/// General functionality for several different database engines.
namespace DB
{
void applyMetadataChangesToCreateQuery(const ASTPtr & query, const StorageInMemoryMetadata & metadata);
ASTPtr getCreateQueryFromStorage(const StoragePtr & storage, const ASTPtr & ast_storage, bool only_ordinary, uint32_t max_parser_depth, bool throw_on_error);
2017-05-23 18:33:48 +00:00
class Context;
/// A base class for databases that manage their own list of tables.
class DatabaseWithOwnTablesBase : public IDatabase, protected WithContext
{
public:
bool isTableExist(const String & table_name, ContextPtr context) const override;
StoragePtr tryGetTable(const String & table_name, ContextPtr context) const override;
bool empty() const override;
void attachTable(ContextPtr context, const String & table_name, const StoragePtr & table, const String & relative_table_path) override;
StoragePtr detachTable(ContextPtr context, const String & table_name) override;
DatabaseTablesIteratorPtr getTablesIterator(ContextPtr context, const FilterByNameFunction & filter_by_table_name) const override;
2019-10-10 17:33:01 +00:00
DatabaseTablesIteratorPtr getTablesIteratorForBackup(const BackupEntriesCollector & backup_entries_collector) const override;
void backupCreateTableQuery(BackupEntriesCollector & backup_entries_collector, const StoragePtr & storage, const ASTPtr & create_table_query) override;
void createTableRestoredFromBackup(const RestorerFromBackup & restorer, const ASTPtr & create_table_query) override;
void shutdown() override;
2020-05-28 20:10:45 +00:00
~DatabaseWithOwnTablesBase() override;
protected:
Tables tables;
Poco::Logger * log;
DatabaseWithOwnTablesBase(const String & name_, const String & logger, ContextPtr context);
2020-01-30 12:51:47 +00:00
2020-04-22 20:43:10 +00:00
void attachTableUnlocked(const String & table_name, const StoragePtr & table, std::unique_lock<std::mutex> & lock);
StoragePtr detachTableUnlocked(const String & table_name, std::unique_lock<std::mutex> & lock);
StoragePtr getTableUnlocked(const String & table_name, std::unique_lock<std::mutex> & lock) const;
};
}