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
|
|
|
|
{
|
|
|
|
|
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,
|
2019-12-02 19:11:18 +00:00
|
|
|
const String & to_table_name) override;
|
2019-11-11 14:28:28 +00:00
|
|
|
|
2020-01-22 11:30:11 +00:00
|
|
|
//void removeTable(const Context & context, const String & table_name) override;
|
|
|
|
void dropTable(const Context & context, const String & table_name) override;
|
|
|
|
|
2019-11-11 11:34:03 +00:00
|
|
|
void attachTable(const String & name, const StoragePtr & table, const String & relative_table_path = {}) override;
|
|
|
|
StoragePtr detachTable(const String & name) override;
|
|
|
|
|
2019-12-25 21:17:49 +00:00
|
|
|
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-01-22 11:30:11 +00:00
|
|
|
void loadStoredObjects(Context & context, bool has_force_restore_data_flag) override;
|
|
|
|
void shutdown() override;
|
|
|
|
|
2019-11-11 11:34:03 +00:00
|
|
|
private:
|
2020-01-22 11:30:11 +00:00
|
|
|
void dropTableDataTask();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static constexpr time_t drop_delay_s = 10;
|
|
|
|
static constexpr size_t reschedule_time_ms = 5000;
|
|
|
|
|
2019-11-11 11:34:03 +00:00
|
|
|
//TODO store path in DatabaseWithOwnTables::tables
|
|
|
|
std::map<String, String> table_name_to_path;
|
2020-01-22 11:30:11 +00:00
|
|
|
struct TableToDrop
|
|
|
|
{
|
|
|
|
StoragePtr table;
|
|
|
|
String data_path;
|
|
|
|
time_t drop_time;
|
|
|
|
//time_t last_attempt_time;
|
|
|
|
};
|
|
|
|
using TablesToDrop = std::list<TableToDrop>;
|
|
|
|
TablesToDrop tables_to_drop;
|
|
|
|
std::mutex tables_to_drop_mutex;
|
|
|
|
|
|
|
|
BackgroundSchedulePoolTaskHolder drop_task;
|
2019-10-23 13:46:38 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|