-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathsdi_api.h
200 lines (162 loc) · 6.21 KB
/
sdi_api.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/* Copyright (c) 2016, 2024, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#ifndef DD_SDI_API_INCLUDED
#define DD_SDI_API_INCLUDED
#include <memory>
#include "sql/dd/string_type.h"
#include "sql/dd/types/table.h"
struct MEM_ROOT;
class MDL_request;
class THD;
class Table_ref;
namespace dd {
namespace sdi {
/**
State and operations for importing an sdi file into the DD.
*/
class Import_target {
/** Full path to the sdi file being imported. */
dd::String_type m_path;
/** True if path points inside data dir */
bool m_in_datadir;
/** Temporary name for sdi files in data dir when import is ongoing */
dd::String_type m_tmp_sdi_filename;
/** Table object which the sdi will be deserialized into */
std::unique_ptr<dd::Table> m_table_object;
/** Schema name found in sdi */
dd::String_type m_schema_name_in_sdi;
/**
Lower-case representation of table name if
lower_case_table_names==2, nullptr otherwise.
*/
std::unique_ptr<dd::String_type> m_lc_tname;
/**
Lower-case representation of schema name if
lower_case_table_names==2, nullptr otherwise.
*/
std::unique_ptr<dd::String_type> m_lc_sname;
public:
/**
Creates an instance to handle the import of a single sdi file.
@param path full path to an sdi file to import
@param in_datadir true if the file is located somewhere under the
server's data directory.
*/
Import_target(String_type &&path, bool in_datadir);
/**
Having a unique_ptr as member makes this a move-only type.
*/
Import_target(Import_target &&) = default;
Import_target(const Import_target &) = delete;
/**
Finish import by removing tmp sdi file when importing from sdi
file in datadir.
@retval true if an error occurred
@retval false otherwise
*/
bool commit() const;
/**
Restore old state by renaming tmp sdi file back to its original
name when importing from sdi file in datadir.
@retval true if an error occurred
@retval false otherwise
*/
bool rollback() const;
/**
Obtains the canonical table name for use with MDL and
privilege-checking. For lower_case_table_names=0 and 1, this is
the same as the name of the Table object. For
lower_case_table_names=2 it is the lower case version of the
tablename.
@returns pointer to dd::String_type holding canonical name
*/
const dd::String_type *can_table_name() const;
/**
Obtains the canonical schema name for use with MDL and
privilege-checking. For lower_case_table_names=0 and 1, this is
the same as the schema name of the table in the sdi. For
lower_case_table_names=2 it is the lower case version of the
schemaname.
@returns pointer to dd::String_type holding canonical name
*/
const dd::String_type *can_schema_name() const;
/**
Reads the sdi file from disk and dserializes it into a Table
object and its schema name, but does not store Table object in the
DD.
@param thd thread context
@param shared_buffer pointer to a dd::String_type which is used to
store the sdi string until it is deserialized.
@retval true if an error occurred
@retval false otherwise
*/
bool load(THD *thd, String_type *shared_buffer);
/**
Constructs a Table_ref object with info from this Import_target.
Table_ref::db and Table_ref::table_name are initialized to the
canonical (lowercased for lctn==2) representation,
Table_ref::alias to the native
table_name, and Table_ref::m_lock_descriptor.type is set to
TL_IGNORE.
*/
Table_ref make_table_ref() const;
/**
Update the schema reference in the Table object and store
it in the DD so that it becomes visible. Precondition: The
Import_target must be loaded and privileges checked before this
member function is called.
@param thd thread handle
@retval true if an error occurred
@retval false otherwise
*/
bool store_in_dd(THD *thd) const;
};
/**
Check that we have the the necessary privileges to import this
table. Precondition: The Import_target must be loaded before this
member function is called.
@param thd thread handle
@param t import target context
@retval true if an error occurred
@retval false otherwise
*/
bool check_privileges(THD *thd, const Import_target &t);
/**
Creates an MDL_request for exclusive MDL on the table being
imported. Does not actually lock the name, that must be done later
for all requests to avoid deadlock.
@param t import target context
@param mem_root where to allocate the MDL_request
@return pointer to mem_root allocated MDL_request
*/
MDL_request *mdl_request(const Import_target &t, MEM_ROOT *mem_root);
/**
Drop all SDIs from all tablespaces associated with table. For a partitioned
table SDIs are deleted from all the partition tablespaces.
*/
bool drop_all_for_table(THD *, const Table *);
/**
Drop all SDIs from all tablespaces associated with partition or
sub-partition. For a top-level partition of a sub-partitioned table, SDIs are
removed for all sub-partitions of that partition.
*/
bool drop_all_for_part(THD *, const Partition *);
} // namespace sdi
} // namespace dd
#endif /* DD_SDI_API_INCLUDED */