aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Databases/MySQL/DatabaseMaterializedMySQL.h
blob: 9dfe02d46b0b6936096bdc8e6c254933ed821726 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once

#include "clickhouse_config.h"

#if USE_MYSQL

#error #include <mysqlxx/Pool.h>
#include <Core/MySQL/MySQLClient.h>
#include <base/UUID.h>
#include <Databases/IDatabase.h>
#include <Databases/DatabaseAtomic.h>
#include <Databases/MySQL/MaterializedMySQLSettings.h>
#include <Databases/MySQL/MaterializedMySQLSyncThread.h>
#include <Common/logger_useful.h>

namespace DB
{

/** Real-time pull table structure and data from remote MySQL
 *
 *  All table structure and data will be written to the local file system
 */
class DatabaseMaterializedMySQL : public DatabaseAtomic
{
public:
    DatabaseMaterializedMySQL(
        ContextPtr context,
        const String & database_name_,
        const String & metadata_path_,
        UUID uuid,
        const String & mysql_database_name_,
        mysqlxx::Pool && pool_,
        MySQLClient && client_,
        std::unique_ptr<MaterializedMySQLSettings> settings_);

    void rethrowExceptionIfNeeded() const;

    void setException(const std::exception_ptr & exception);
protected:

    std::unique_ptr<MaterializedMySQLSettings> settings;

    MaterializedMySQLSyncThread materialize_thread;

    std::exception_ptr exception;

    std::atomic_bool started_up{false};

public:
    String getEngineName() const override { return "MaterializedMySQL"; }

    void startupTables(ThreadPool & thread_pool, LoadingStrictnessLevel mode) override;

    void createTable(ContextPtr context_, const String & name, const StoragePtr & table, const ASTPtr & query) override;

    void dropTable(ContextPtr context_, const String & name, bool sync) override;

    void attachTable(ContextPtr context_, const String & name, const StoragePtr & table, const String & relative_table_path) override;

    StoragePtr detachTable(ContextPtr context_, const String & name) override;

    void renameTable(ContextPtr context_, const String & name, IDatabase & to_database, const String & to_name, bool exchange, bool dictionary) override;

    void alterTable(ContextPtr context_, const StorageID & table_id, const StorageInMemoryMetadata & metadata) override;

    void drop(ContextPtr context_) override;

    StoragePtr tryGetTable(const String & name, ContextPtr context_) const override;

    DatabaseTablesIteratorPtr getTablesIterator(ContextPtr context_, const DatabaseOnDisk::FilterByNameFunction & filter_by_table_name) const override;

    void checkIsInternalQuery(ContextPtr context_, const char * method) const;

    bool hasReplicationThread() const override { return true; }

    void stopReplication() override;

    friend class DatabaseMaterializedTablesIterator;
};

}

#endif