MySQL  8.0.19
Source Code Documentation
sdi_api.h
Go to the documentation of this file.
1 /* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
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 
31 struct MEM_ROOT;
32 class MDL_request;
33 class THD;
34 struct TABLE_LIST;
35 
36 namespace dd {
37 namespace 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 directrory.
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  */
82  Import_target(Import_target &&) = default;
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_LIST object with info from this Import_target.
140  TABLE_LIST::db and TABLE_LIST::table_name are initialized to the
141  canonical (lowercased for lctn==2) representation,
142  TABLE_LIST::alias to the native
143  table_name, and TABLE_LIST::m_lock_descriptor.type is set to
144  TL_IGNORE.
145  */
146  TABLE_LIST make_table_list() const;
147 
148  /**
149  Upadate 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 */
171 bool 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 } // namespace sdi
185 } // namespace dd
186 
187 #endif /* DD_SDI_API_INCLUDED */
dd::sdi::mdl_request
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
THD
Definition: sql_class.h:764
dd::sdi::Import_target::Import_target
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
dd::sdi::Import_target::can_table_name
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
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:50
dd::sdi::Import_target::m_path
dd::String_type m_path
Full path to the sdi file being imported.
Definition: sdi_api.h:44
dd::sdi::Import_target::load
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
dd::sdi::check_privileges
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
dd::sdi::Import_target::rollback
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
mem_root
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
dd::sdi::Import_target::store_in_dd
bool store_in_dd(THD *thd) const
Upadate the schema reference in the Table object and store it in the DD so that it becomes visible.
Definition: sdi_api.cc:142
dd
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:39
dd::sdi::Import_target::m_lc_tname
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
MDL_request
A pending metadata lock request.
Definition: mdl.h:782
MEM_ROOT
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
dd::sdi::Import_target::make_table_list
TABLE_LIST make_table_list() const
Constructs a TABLE_LIST object with info from this Import_target.
Definition: sdi_api.cc:133
dd::sdi::Import_target::can_schema_name
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
string_type.h
TABLE_LIST
Definition: table.h:2467
table.h
dd::sdi::Import_target::m_tmp_sdi_filename
dd::String_type m_tmp_sdi_filename
Temporary name for sdi files in data dir when import is ongoing.
Definition: sdi_api.h:50
path
static char * path
Definition: mysqldump.cc:130
dd::sdi::Import_target
State and operations for importing an sdi file into the DD.
Definition: sdi_api.h:42
dd::sdi::Import_target::m_schema_name_in_sdi
dd::String_type m_schema_name_in_sdi
Schema name found in sdi.
Definition: sdi_api.h:56
dd::sdi::Import_target::commit
bool commit() const
Finish import by removing tmp sdi file when importing from sdi file in datadir.
Definition: sdi_api.cc:63
dd::sdi::Import_target::m_in_datadir
bool m_in_datadir
True if path points inside data dir.
Definition: sdi_api.h:47
dd::sdi::Import_target::m_table_object
std::unique_ptr< dd::Table > m_table_object
Table object which the sdi will be deserialized into.
Definition: sdi_api.h:53
dd::sdi::Import_target::m_lc_sname
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