-
Notifications
You must be signed in to change notification settings - Fork 412
/
SchemaBuilder.h
98 lines (66 loc) · 3.91 KB
/
SchemaBuilder.h
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2022 PingCAP, Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <Interpreters/Context.h>
#include <Storages/Transaction/TMTStorages.h>
#include <TiDB/Schema/SchemaGetter.h>
namespace DB
{
template <typename Getter, typename NameMapper>
struct SchemaBuilder
{
NameMapper name_mapper;
Getter & getter;
Context & context;
std::unordered_map<DB::DatabaseID, TiDB::DBInfoPtr> & databases;
Int64 target_version;
Poco::Logger * log;
SchemaBuilder(Getter & getter_, Context & context_, std::unordered_map<DB::DatabaseID, TiDB::DBInfoPtr> & dbs_, Int64 version)
: getter(getter_)
, context(context_)
, databases(dbs_)
, target_version(version)
, log(&Poco::Logger::get("SchemaBuilder"))
{}
void applyDiff(const SchemaDiff & diff);
void syncAllSchema();
private:
void applyDropSchema(DatabaseID schema_id);
/// Parameter db_name should be mapped.
void applyDropSchema(const String & db_name);
bool applyCreateSchema(DatabaseID schema_id);
void applyCreateSchema(const TiDB::DBInfoPtr & db_info);
void applyCreateTable(const TiDB::DBInfoPtr & db_info, TableID table_id);
void applyCreateLogicalTable(const TiDB::DBInfoPtr & db_info, const TiDB::TableInfoPtr & table_info);
void applyCreatePhysicalTable(const TiDB::DBInfoPtr & db_info, const TiDB::TableInfoPtr & table_info);
void applyDropTable(const TiDB::DBInfoPtr & db_info, TableID table_id);
/// Parameter schema_name should be mapped.
void applyDropPhysicalTable(const String & db_name, TableID table_id);
void applyPartitionDiff(const TiDB::DBInfoPtr & db_info, TableID table_id);
void applyPartitionDiff(const TiDB::DBInfoPtr & db_info, const TiDB::TableInfoPtr & table_info, const ManageableStoragePtr & storage);
void applyAlterTable(const TiDB::DBInfoPtr & db_info, TableID table_id);
void applyAlterLogicalTable(const TiDB::DBInfoPtr & db_info, const TiDB::TableInfoPtr & table_info, const ManageableStoragePtr & storage);
void applyAlterPhysicalTable(const TiDB::DBInfoPtr & db_info, const TiDB::TableInfoPtr & table_info, const ManageableStoragePtr & storage);
void applyRenameTable(const TiDB::DBInfoPtr & new_db_info, TiDB::TableID table_id);
void applyRenameLogicalTable(const TiDB::DBInfoPtr & new_db_info, const TiDB::TableInfoPtr & new_table_info, const ManageableStoragePtr & storage);
void applyRenamePhysicalTable(const TiDB::DBInfoPtr & new_db_info, const TiDB::TableInfo & new_table_info, const ManageableStoragePtr & storage);
void applyExchangeTablePartition(const SchemaDiff & diff);
void applySetTiFlashReplica(const TiDB::DBInfoPtr & db_info, TableID table_id);
void applySetTiFlashReplicaOnLogicalTable(const TiDB::DBInfoPtr & db_info, const TiDB::TableInfoPtr & table_info, const ManageableStoragePtr & storage);
void applySetTiFlashReplicaOnPhysicalTable(const TiDB::DBInfoPtr & db_info, const TiDB::TableInfoPtr & table_info, const ManageableStoragePtr & storage);
void applySetTiFlashMode(const TiDB::DBInfoPtr & db_info, TableID table_id);
void applySetTiFlashModeOnLogicalTable(const TiDB::DBInfoPtr & db_info, const TiDB::TableInfoPtr & table_info, const ManageableStoragePtr & storage);
void applySetTiFlashModeOnPhysicalTable(const TiDB::DBInfoPtr & db_info, const TiDB::TableInfoPtr & table_info, const ManageableStoragePtr & storage);
};
} // namespace DB