ClickHouse/src/Databases/DatabaseAtomic.h

74 lines
2.9 KiB
C++
Raw Normal View History

2019-10-23 13:46:38 +00:00
#pragma once
#include <Databases/DatabasesCommon.h>
2020-01-22 11:30:11 +00:00
#include <Core/BackgroundSchedulePool.h>
2019-10-23 13:46:38 +00:00
#include <Databases/DatabaseOrdinary.h>
namespace DB
{
2020-04-22 20:43:10 +00:00
/// All tables in DatabaseAtomic have persistent UUID and store data in
/// /clickhouse_path/store/xxx/xxxyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy/
/// where xxxyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy is UUID of the table.
/// RENAMEs are performed without changing UUID and moving table data.
/// Tables in Atomic databases can be accessed by UUID through DatabaseCatalog.
/// On DROP TABLE no data is removed, DatabaseAtomic just marks table as dropped
/// by moving metadata to /clickhouse_path/metadata_dropped/ and notifies DatabaseCatalog.
/// Running queries still may use dropped table. Table will be actually removed when it's not in use.
/// Allows to execute RENAME and DROP without IStorage-level RWLocks
2019-11-11 11:34:03 +00:00
class DatabaseAtomic : public DatabaseOrdinary
2019-10-23 13:46:38 +00:00
{
public:
2020-01-22 11:30:11 +00:00
DatabaseAtomic(String name_, String metadata_path_, Context & context_);
2019-10-23 13:46:38 +00:00
String getEngineName() const override { return "Atomic"; }
2019-11-11 14:28:28 +00:00
void renameTable(
const Context & context,
const String & table_name,
IDatabase & to_database,
2020-03-31 20:38:05 +00:00
const String & to_table_name,
bool exchange) override;
2019-11-11 14:28:28 +00:00
2020-03-20 00:07:52 +00:00
void dropTable(const Context & context, const String & table_name, bool no_delay) override;
2020-01-22 11:30:11 +00:00
2020-03-20 12:45:06 +00:00
void attachTable(const String & name, const StoragePtr & table, const String & relative_table_path) override;
2019-11-11 11:34:03 +00:00
StoragePtr detachTable(const String & name) override;
String getTableDataPath(const String & table_name) const override;
String getTableDataPath(const ASTCreateQuery & query) const override;
2019-11-11 11:34:03 +00:00
void drop(const Context & /*context*/) override;
2020-04-01 22:41:29 +00:00
DatabaseTablesIteratorPtr getTablesIterator(const FilterByNameFunction & filter_by_table_name) override;
2020-04-10 00:08:43 +00:00
void loadStoredObjects(Context & context, bool has_force_restore_data_flag) override;
2020-04-10 23:02:15 +00:00
void assertCanBeDetached(bool cleenup);
2020-04-13 14:09:56 +00:00
UUID tryGetTableUUID(const String & table_name) const override;
2019-11-11 11:34:03 +00:00
private:
2020-03-23 00:12:13 +00:00
void commitAlterTable(const StorageID & table_id, const String & table_metadata_tmp_path, const String & table_metadata_path) override;
void commitCreateTable(const ASTCreateQuery & query, const StoragePtr & table,
const String & table_metadata_tmp_path, const String & table_metadata_path) override;
2020-01-27 20:31:39 +00:00
void assertDetachedTableNotInUse(const UUID & uuid);
2020-04-10 00:08:43 +00:00
typedef std::unordered_map<UUID, StoragePtr> DetachedTables;
2020-04-22 20:43:10 +00:00
[[nodiscard]] DetachedTables cleenupDetachedTables();
2020-04-10 00:08:43 +00:00
void tryCreateSymlink(const String & table_name, const String & actual_data_path);
void tryRemoveSymlink(const String & table_name);
2020-01-27 20:31:39 +00:00
//TODO store path in DatabaseWithOwnTables::tables
2020-04-10 00:08:43 +00:00
typedef std::unordered_map<String, String> NameToPathMap;
NameToPathMap table_name_to_path;
2020-01-27 20:31:39 +00:00
2020-04-06 23:22:44 +00:00
DetachedTables detached_tables;
2020-04-10 00:08:43 +00:00
const String path_to_table_symlinks;
2019-10-23 13:46:38 +00:00
};
}