MySQL  8.0.17
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  Initializes 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  @param tlp object to initialize
147  */
148  void init_table_list(TABLE_LIST *tlp) const;
149 
150  /**
151  Upadate the schema reference in the Table object and store
152  it in the DD so that it becomes visible. Precondition: The
153  Import_target must be loaded and privileges checked before this
154  member function is called.
155 
156  @param thd thread handle
157  @retval true if an error occurred
158  @retval false otherwise
159  */
160  bool store_in_dd(THD *thd) const;
161 };
162 
163 /**
164  Check that we have the the necessary privileges to import this
165  table. Precondition: The Import_target must be loaded before this
166  member function is called.
167 
168  @param thd thread handle
169  @param t import target context
170  @retval true if an error occurred
171  @retval false otherwise
172 */
173 bool check_privileges(THD *thd, const Import_target &t);
174 
175 /**
176  Creates an MDL_request for exclusive MDL on the table being
177  imported. Does not actually lock the name, that must be done later
178  for all requests to avoid deadlock.
179 
180  @param t import target context
181  @param mem_root where to allocate the MDL_request
182  @return pointer to mem_root allocated MDL_request
183 */
185 
186 } // namespace sdi
187 } // namespace dd
188 
189 #endif /* DD_SDI_API_INCLUDED */
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
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
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
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
bool commit() const
Finish import by removing tmp sdi file when importing from sdi file in datadir.
Definition: sdi_api.cc:63
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:50
dd::String_type m_schema_name_in_sdi
Schema name found in sdi.
Definition: sdi_api.h:56
bool m_in_datadir
True if path points inside data dir.
Definition: sdi_api.h:47
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 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
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
static char * path
Definition: mysqldump.cc:123
State and operations for importing an sdi file into the DD.
Definition: sdi_api.h:42
t
Definition: dbug_analyze.cc:147
std::unique_ptr< dd::Table > m_table_object
Table object which the sdi will be deserialized into.
Definition: sdi_api.h:53
A pending metadata lock request.
Definition: mdl.h:782
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_path
Full path to the sdi file being imported.
Definition: sdi_api.h:44
static MEM_ROOT mem_root
Definition: client_plugin.cc:107
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
void init_table_list(TABLE_LIST *tlp) const
Initializes a TABLE_LIST object with info from this Import_target.
Definition: sdi_api.cc:133
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
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:39
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
Definition: table.h:2442
dd::String_type m_tmp_sdi_filename
Temporary name for sdi files in data dir when import is ongoing.
Definition: sdi_api.h:50
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:777