-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathsql_tablespace.h
363 lines (301 loc) · 11.5 KB
/
sql_tablespace.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/* Copyright (c) 2006, 2025, 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 SQL_TABLESPACE_INCLUDED
#define SQL_TABLESPACE_INCLUDED
#include <sys/types.h>
#include <optional>
#include "lex_string.h"
#include "my_inttypes.h"
#include "my_sqlcommand.h"
#include "sql/handler.h" // ts_command_type
#include "sql/sql_cmd_ddl.h" // Sql_cmd_ddl
class THD;
/**
Structure used by parser to store options for tablespace statements
and pass them on to Execution classes.
*/
struct Tablespace_options {
ulonglong extent_size = 1024 * 1024; // Default 1 MByte
ulonglong undo_buffer_size = 8 * 1024 * 1024; // Default 8 MByte
ulonglong redo_buffer_size = 8 * 1024 * 1024; // Default 8 MByte
ulonglong initial_size = 128 * 1024 * 1024; // Default 128 MByte
std::optional<ulonglong> autoextend_size; // No autoextension as default
ulonglong max_size = 0; // Max size == initial size => no extension
ulonglong file_block_size = 0; // 0=default or must be a valid Page Size
uint nodegroup_id = UNDEF_NODEGROUP;
bool wait_until_completed = true;
LEX_STRING ts_comment = {nullptr, 0}; // FIXME: Rename to comment?
LEX_CSTRING engine_name = {nullptr, 0};
LEX_STRING encryption = {nullptr, 0};
LEX_CSTRING engine_attribute = NULL_CSTR;
};
/**
Check if tablespace name has valid length.
@param tablespace_name Name of the tablespace
@note Tablespace names are not reflected in the file system, so
character case conversion or consideration is not relevant.
@note Checking for path characters or ending space is not done.
The checks are for identifier length, both in terms of
number of characters and number of bytes.
@retval false No error encountered while checking length.
@retval true Error encountered and reported.
*/
bool validate_tablespace_name_length(const char *tablespace_name);
/**
Check if a tablespace name is valid.
SE specific validation is done by the SE by invoking a handlerton method.
@param ts_cmd Whether this is tablespace DDL or not.
@param tablespace_name Name of the tablespace
@param engine Handlerton for the tablespace.
@retval false No error encountered while checking the name.
@retval true Error encountered and reported.
*/
bool validate_tablespace_name(ts_command_type ts_cmd,
const char *tablespace_name,
const handlerton *engine);
/**
Base class for tablespace execution classes including
CREATE/ALTER/DROP TABLESPACE and LOGFILE GROUP commands.
*/
class Sql_cmd_tablespace : public Sql_cmd_ddl /* purecov: inspected */
{
protected:
const LEX_STRING m_tablespace_name;
const Tablespace_options *m_options;
/**
Creates shared base object.
@param name name of tablespace
@param options additional options to statement
*/
Sql_cmd_tablespace(const LEX_STRING &name, const Tablespace_options *options);
public:
/**
Provide access to the command code enum value.
@return command code enum value
*/
enum_sql_command sql_command_code() const final;
/**
Return the Tablespace_options for this object.
*/
const Tablespace_options get_options() const { return *m_options; }
};
/**
Execution class for CREATE TABLESPACE ... ADD DATAFILE ...
*/
class Sql_cmd_create_tablespace final
: public Sql_cmd_tablespace /* purecov: inspected */
{
const LEX_STRING m_datafile_name;
const LEX_STRING m_logfile_group_name;
bool m_auto_generate_datafile_name;
public:
/**
Creates execution class instance for create tablespace statement.
@param tsname name of tablespace
@param dfname name of data file
@param lfgname name of logfile group (may be {nullptr, 0})
@param options additional options to statement
*/
Sql_cmd_create_tablespace(const LEX_STRING &tsname, const LEX_STRING &dfname,
const LEX_STRING &lfgname,
const Tablespace_options *options);
bool execute(THD *) override;
};
/**
Execution class for DROP TABLESPACE ...
*/
class Sql_cmd_drop_tablespace final
: public Sql_cmd_tablespace /* purecov: inspected */
{
public:
/**
Creates execution class instance for drop tablespace statement.
@param tsname name of tablespace
@param options additional options to statement
*/
Sql_cmd_drop_tablespace(const LEX_STRING &tsname,
const Tablespace_options *options);
bool execute(THD *) override;
};
/**
Execution class for ALTER TABLESPACE ... tablespace_options
*/
class Sql_cmd_alter_tablespace final : public Sql_cmd_tablespace {
public:
/**
Creates execution class instance for plain alter tablespace
(modifying options).
@param ts_name name of tablespace
@param options additional options to statement
*/
Sql_cmd_alter_tablespace(const LEX_STRING &ts_name,
const Tablespace_options *options);
bool execute(THD *thd) override;
};
/**
Execution class for ALTER TABLESPACE ... ADD DATAFILE ...
*/
class Sql_cmd_alter_tablespace_add_datafile final
: public Sql_cmd_tablespace /* purecov: inspected */
{
const LEX_STRING m_datafile_name;
public:
/**
Creates execution class instance for add datafile statement.
@param tsname name of tablespace
@param dfname name of data file to add
@param options additional options to statement
*/
Sql_cmd_alter_tablespace_add_datafile(const LEX_STRING &tsname,
const LEX_STRING &dfname,
const Tablespace_options *options);
bool execute(THD *) override;
};
/**
Execution class for ALTER TABLESPACE ... DROP DATAFILE ...
*/
class Sql_cmd_alter_tablespace_drop_datafile final
: public Sql_cmd_tablespace /* purecov: inspected */
{
const LEX_STRING m_datafile_name;
public:
/**
Creates execution class instance for drop datafile statement.
@param tsname name of tablespace
@param dfname name of data file to drop
@param options additional options to statement
*/
Sql_cmd_alter_tablespace_drop_datafile(const LEX_STRING &tsname,
const LEX_STRING &dfname,
const Tablespace_options *options);
bool execute(THD *) override;
};
/**
Execution class for ALTER TABLESPACE ... RENAME TO ...
*/
class Sql_cmd_alter_tablespace_rename final
: public Sql_cmd_tablespace /* purecov: inspected */
{
const LEX_STRING m_new_name;
public:
/**
Creates execution class instance for rename statement.
@param old_name existing tablespace
@param new_name desired tablespace name
*/
Sql_cmd_alter_tablespace_rename(const LEX_STRING &old_name,
const LEX_STRING &new_name);
bool execute(THD *) override;
};
/**
Execution class for CREATE UNDO TABLESPACE
*/
class Sql_cmd_create_undo_tablespace final : public Sql_cmd {
const ts_command_type m_cmd;
const LEX_STRING m_undo_tablespace_name;
const LEX_STRING m_datafile_name;
const Tablespace_options *m_options;
public:
/**
Creates execution class instance for undo tablespace statements.
@param cmd_type subcommand passed to se
@param utsname name of undo tablespace
@param dfname name of data file
@param options additional options to statemente
*/
Sql_cmd_create_undo_tablespace(const ts_command_type cmd_type,
const LEX_STRING &utsname,
const LEX_STRING &dfname,
const Tablespace_options *options);
bool execute(THD *) override;
enum_sql_command sql_command_code() const override;
};
/**
Execution class for ALTER UNDO TABLESPACE
*/
class Sql_cmd_alter_undo_tablespace final : public Sql_cmd {
const ts_command_type m_cmd;
const LEX_STRING m_undo_tablespace_name;
const LEX_STRING m_datafile_name;
const ts_alter_tablespace_type m_at_type;
const Tablespace_options *m_options;
public:
/**
Creates execution class instance for undo tablespace statements.
@param cmd_type subcommand passed to se
@param utsname name of undo tablespace
@param dfname name of data file
@param options additional options to statemente
@param at_type alter tablespace subcommand passed to se
*/
Sql_cmd_alter_undo_tablespace(
const ts_command_type cmd_type, const LEX_STRING &utsname,
const LEX_STRING &dfname, const Tablespace_options *options,
ts_alter_tablespace_type at_type = TS_ALTER_TABLESPACE_TYPE_NOT_DEFINED);
bool execute(THD *) override;
enum_sql_command sql_command_code() const override;
};
/**
Execution class for DROP UNDO TABLESPACE
*/
class Sql_cmd_drop_undo_tablespace final : public Sql_cmd {
const ts_command_type m_cmd;
const LEX_STRING m_undo_tablespace_name;
const LEX_STRING m_datafile_name;
const Tablespace_options *m_options;
public:
/**
Creates execution class instance for drop undo tablespace statements.
@param cmd_type subcommand passed to se
@param utsname name of undo tablespace
@param dfname name of data file
@param options additional options to statemente
*/
Sql_cmd_drop_undo_tablespace(const ts_command_type cmd_type,
const LEX_STRING &utsname,
const LEX_STRING &dfname,
const Tablespace_options *options);
bool execute(THD *) override;
enum_sql_command sql_command_code() const override;
};
/**
Execution class for CREATE/DROP/ALTER LOGFILE GROUP ...
*/
class Sql_cmd_logfile_group final : public Sql_cmd /* purecov: inspected */
{
const ts_command_type m_cmd;
const LEX_STRING m_logfile_group_name;
const LEX_STRING m_undofile_name;
const Tablespace_options *m_options;
public:
/**
Creates execution class instance for logfile group statements.
@param cmd_type subcommand passed to se
@param logfile_group_name name of logfile group
@param options additional options to statement
@param undofile_name name of undo file
*/
Sql_cmd_logfile_group(const ts_command_type cmd_type,
const LEX_STRING &logfile_group_name,
const Tablespace_options *options,
const LEX_STRING &undofile_name = {nullptr, 0});
bool execute(THD *thd) override;
enum_sql_command sql_command_code() const override;
};
#endif /* SQL_TABLESPACE_INCLUDED */