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