MySQL 8.0.33
Source Code Documentation
sdi_api.h
Go to the documentation of this file.
1/* Copyright (c) 2016, 2023, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef DD_SDI_API_INCLUDED
24#define DD_SDI_API_INCLUDED
25
26#include <memory>
27
28#include "sql/dd/string_type.h"
29#include "sql/dd/types/table.h"
30
31struct MEM_ROOT;
32class MDL_request;
33class THD;
34class Table_ref;
35
36namespace dd {
37namespace sdi {
38
39/**
40 State and operations for importing an sdi file into the DD.
41 */
43 /** Full path to the sdi file being imported. */
45
46 /** True if path points inside data dir */
48
49 /** Temporary name for sdi files in data dir when import is ongoing */
51
52 /** Table object which the sdi will be deserialized into */
53 std::unique_ptr<dd::Table> m_table_object;
54
55 /** Schema name found in sdi */
57
58 /**
59 Lower-case representation of table name if
60 lower_case_table_names==2, nullptr otherwise.
61 */
62 std::unique_ptr<dd::String_type> m_lc_tname;
63
64 /**
65 Lower-case representation of schema name if
66 lower_case_table_names==2, nullptr otherwise.
67 */
68 std::unique_ptr<dd::String_type> m_lc_sname;
69
70 public:
71 /**
72 Creates an instance to handle the import of a single sdi file.
73 @param path full path to an sdi file to import
74 @param in_datadir true if the file is located somewhere under the
75 server's data directory.
76 */
77 Import_target(String_type &&path, bool in_datadir);
78
79 /**
80 Having a unique_ptr as member makes this a move-only type.
81 */
83 Import_target(const Import_target &) = delete;
84
85 /**
86 Finish import by removing tmp sdi file when importing from sdi
87 file in datadir.
88
89 @retval true if an error occurred
90 @retval false otherwise
91 */
92 bool commit() const;
93
94 /**
95 Restore old state by renaming tmp sdi file back to its original
96 name when importing from sdi file in datadir.
97
98 @retval true if an error occurred
99 @retval false otherwise
100 */
101 bool rollback() const;
102
103 /**
104 Obtains the canonical table name for use with MDL and
105 privilege-checking. For lower_case_table_names=0 and 1, this is
106 the same as the name of the Table object. For
107 lower_case_table_names=2 it is the lower case version of the
108 tablename.
109
110 @returns pointer to dd::String_type holding canonical name
111 */
112 const dd::String_type *can_table_name() const;
113
114 /**
115 Obtains the canonical schema name for use with MDL and
116 privilege-checking. For lower_case_table_names=0 and 1, this is
117 the same as the schema name of the table in the sdi. For
118 lower_case_table_names=2 it is the lower case version of the
119 schemaname.
120
121 @returns pointer to dd::String_type holding canonical name
122 */
123 const dd::String_type *can_schema_name() const;
124
125 /**
126 Reads the sdi file from disk and dserializes it into a Table
127 object and its schema name, but does not store Table object in the
128 DD.
129
130 @param thd thread context
131 @param shared_buffer pointer to a dd::String_type which is used to
132 store the sdi string until it is deserialized.
133 @retval true if an error occurred
134 @retval false otherwise
135 */
136 bool load(THD *thd, String_type *shared_buffer);
137
138 /**
139 Constructs a Table_ref object with info from this Import_target.
140 Table_ref::db and Table_ref::table_name are initialized to the
141 canonical (lowercased for lctn==2) representation,
142 Table_ref::alias to the native
143 table_name, and Table_ref::m_lock_descriptor.type is set to
144 TL_IGNORE.
145 */
147
148 /**
149 Update the schema reference in the Table object and store
150 it in the DD so that it becomes visible. Precondition: The
151 Import_target must be loaded and privileges checked before this
152 member function is called.
153
154 @param thd thread handle
155 @retval true if an error occurred
156 @retval false otherwise
157 */
158 bool store_in_dd(THD *thd) const;
159};
160
161/**
162 Check that we have the the necessary privileges to import this
163 table. Precondition: The Import_target must be loaded before this
164 member function is called.
165
166 @param thd thread handle
167 @param t import target context
168 @retval true if an error occurred
169 @retval false otherwise
170*/
171bool check_privileges(THD *thd, const Import_target &t);
172
173/**
174 Creates an MDL_request for exclusive MDL on the table being
175 imported. Does not actually lock the name, that must be done later
176 for all requests to avoid deadlock.
177
178 @param t import target context
179 @param mem_root where to allocate the MDL_request
180 @return pointer to mem_root allocated MDL_request
181*/
183
184/**
185 Drop all SDIs from all tablespaces associated with table. For a partitioned
186 table SDIs are deleted from all the partition tablespaces.
187*/
188bool drop_all_for_table(THD *, const Table *);
189
190/**
191 Drop all SDIs from all tablespaces associated with partition or
192 sub-partition. For a top-level partition of a sub-partitioned table, SDIs are
193 removed for all sub-partitions of that partition.
194*/
195bool drop_all_for_part(THD *, const Partition *);
196} // namespace sdi
197} // namespace dd
198
199#endif /* DD_SDI_API_INCLUDED */
A pending metadata lock request.
Definition: mdl.h:800
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
Definition: table.h:2761
Definition: partition.h:50
Definition: table.h:46
State and operations for importing an sdi file into the DD.
Definition: sdi_api.h:42
Import_target(String_type &&path, bool in_datadir)
Creates an instance to handle the import of a single sdi file.
Definition: sdi_api.cc:58
Import_target(Import_target &&)=default
Having a unique_ptr as member makes this a move-only type.
const dd::String_type * can_table_name() const
Obtains the canonical table name for use with MDL and privilege-checking.
Definition: sdi_api.cc:79
dd::String_type m_path
Full path to the sdi file being imported.
Definition: sdi_api.h:44
dd::String_type m_tmp_sdi_filename
Temporary name for sdi files in data dir when import is ongoing.
Definition: sdi_api.h:50
Import_target(const Import_target &)=delete
std::unique_ptr< dd::String_type > m_lc_sname
Lower-case representation of schema name if lower_case_table_names==2, nullptr otherwise.
Definition: sdi_api.h:68
bool m_in_datadir
True if path points inside data dir.
Definition: sdi_api.h:47
bool load(THD *thd, String_type *shared_buffer)
Reads the sdi file from disk and dserializes it into a Table object and its schema name,...
Definition: sdi_api.cc:87
bool rollback() const
Restore old state by renaming tmp sdi file back to its original name when importing from sdi file in ...
Definition: sdi_api.cc:73
bool commit() const
Finish import by removing tmp sdi file when importing from sdi file in datadir.
Definition: sdi_api.cc:63
std::unique_ptr< dd::String_type > m_lc_tname
Lower-case representation of table name if lower_case_table_names==2, nullptr otherwise.
Definition: sdi_api.h:62
bool store_in_dd(THD *thd) const
Update the schema reference in the Table object and store it in the DD so that it becomes visible.
Definition: sdi_api.cc:142
Table_ref make_table_ref() const
Constructs a Table_ref object with info from this Import_target.
Definition: sdi_api.cc:133
std::unique_ptr< dd::Table > m_table_object
Table object which the sdi will be deserialized into.
Definition: sdi_api.h:53
const dd::String_type * can_schema_name() const
Obtains the canonical schema name for use with MDL and privilege-checking.
Definition: sdi_api.cc:83
dd::String_type m_schema_name_in_sdi
Schema name found in sdi.
Definition: sdi_api.h:56
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
bool drop_all_for_table(THD *thd, const Table *tp)
Drop all SDIs from all tablespaces associated with table.
Definition: sdi.cc:684
bool drop_all_for_part(THD *thd, const Partition *pp)
Drop all SDIs from all tablespaces associated with partition or sub-partition.
Definition: sdi.cc:688
static char * path
Definition: mysqldump.cc:133
bool check_privileges(THD *thd, const Import_target &t)
Check that we have the the necessary privileges to import this table.
Definition: sdi_api.cc:211
MDL_request * mdl_request(const Import_target &t, MEM_ROOT *mem_root)
Creates an MDL_request for exclusive MDL on the table being imported.
Definition: sdi_api.cc:244
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:50
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82