MySQL 9.0.0
Source Code Documentation
tablespace.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 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__TABLESPACE_INCLUDED
25#define DD__TABLESPACE_INCLUDED
26
27#include <vector>
28
29#include "lex_string.h"
30#include "my_inttypes.h"
31#include "sql/dd/collection.h" // dd::Collection
32#include "sql/dd/impl/raw/object_keys.h" // IWYU pragma: keep
33#include "sql/dd/sdi_fwd.h" // RJ_Document
34#include "sql/dd/types/entity_object.h" // dd::Entity_object
35#include "sql/mdl.h" // enum enum_mdl_type
36
37class THD;
38class MDL_request;
39
40namespace dd {
41
42///////////////////////////////////////////////////////////////////////////
43
44class Global_name_key;
45class Properties;
46class Tablespace_impl;
47class Tablespace_file;
48class Void_key;
49
50namespace tables {
51class Tablespaces;
52}
53
54///////////////////////////////////////////////////////////////////////////
55
56class Tablespace : virtual public Entity_object {
57 public:
65
66 // We need a set of functions to update a preallocated key.
67 virtual bool update_id_key(Id_key *key) const {
68 return update_id_key(key, id());
69 }
70
71 static bool update_id_key(Id_key *key, Object_id id);
72
73 virtual bool update_name_key(Name_key *key) const {
74 return update_name_key(key, name());
75 }
76
77 static bool update_name_key(Name_key *key, const String_type &name);
78
79 virtual bool update_aux_key(Aux_key *) const { return true; }
80
81 public:
82 ~Tablespace() override = default;
83
84 /**
85 Check if the tablespace is empty, i.e., whether it has any tables.
86
87 @param thd Thread context.
88 @param [out] empty Whether the tablespace is empty.
89
90 @return true if error, false if success.
91 */
92
93 virtual bool is_empty(THD *thd, bool *empty) const = 0;
94
95 /////////////////////////////////////////////////////////////////////////
96 // comment.
97 /////////////////////////////////////////////////////////////////////////
98
99 virtual const String_type &comment() const = 0;
100 virtual void set_comment(const String_type &comment) = 0;
101
102 /////////////////////////////////////////////////////////////////////////
103 // options.
104 /////////////////////////////////////////////////////////////////////////
105
106 virtual const Properties &options() const = 0;
107
108 virtual Properties &options() = 0;
109 virtual bool set_options(const String_type &options_raw) = 0;
110
111 /////////////////////////////////////////////////////////////////////////
112 // se_private_data.
113 /////////////////////////////////////////////////////////////////////////
114
115 virtual const Properties &se_private_data() const = 0;
116
118 virtual bool set_se_private_data(const String_type &se_private_data_raw) = 0;
119
120 /////////////////////////////////////////////////////////////////////////
121 // Engine.
122 /////////////////////////////////////////////////////////////////////////
123
124 virtual const String_type &engine() const = 0;
125 virtual void set_engine(const String_type &engine) = 0;
126
127 /////////////////////////////////////////////////////////////////////////
128 // SE-specific json attributes
129 /////////////////////////////////////////////////////////////////////////
130
131 virtual LEX_CSTRING engine_attribute() const = 0;
133
134 /////////////////////////////////////////////////////////////////////////
135 // Tablespace file collection.
136 /////////////////////////////////////////////////////////////////////////
137
138 virtual Tablespace_file *add_file() = 0;
139
140 virtual bool remove_file(String_type data_file) = 0;
141
142 virtual const Tablespace_file_collection &files() const = 0;
143
144 /**
145 Allocate a new object graph and invoke the copy constructor for
146 each object.
147
148 @return pointer to dynamically allocated copy
149 */
150 virtual Tablespace *clone() const = 0;
151
152 /**
153 Allocate a new object which can serve as a placeholder for the original
154 object in the Dictionary_client's dropped registry. Such object has the
155 same keys as the original but has no other info and as result occupies
156 less memory.
157 */
159
160 /**
161 Converts *this into json.
162
163 Converts all member variables that are to be included in the sdi
164 into json by transforming them appropriately and passing them to
165 the rapidjson writer provided.
166
167 @param wctx opaque context for data needed by serialization
168 @param w rapidjson writer which will perform conversion to json
169
170 */
171
172 virtual void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const = 0;
173
174 /**
175 Re-establishes the state of *this by reading sdi information from
176 the rapidjson DOM subobject provided.
177
178 Cross-references encountered within this object are tracked in
179 sdictx, so that they can be updated when the entire object graph
180 has been established.
181
182 @param rctx stores book-keeping information for the
183 deserialization process
184 @param val subobject of rapidjson DOM containing json
185 representation of this object
186 */
187
188 virtual bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val) = 0;
189};
190
191///////////////////////////////////////////////////////////////////////////
192
193/**
194 Represents tables with their id, name, schema id and schema name.
195 Needed to keep track of information when querying the dd to find
196 tables in a tablespace.
197 */
204 Tablespace_table_ref() = default; /* purecov: inspected */
206 Object_id schema_id)
207 : m_id{id},
208 m_name{std::move(name)},
209 m_schema_id{schema_id},
210 m_schema_encryption{false} {}
211};
212
213bool operator==(const Tablespace_table_ref &a, const Tablespace_table_ref &b);
214
215bool operator<(const Tablespace_table_ref &a, const Tablespace_table_ref &b);
216
217typedef std::vector<Tablespace_table_ref> Tablespace_table_ref_vec;
218
219/**
220 Fetch (by inserting into tblref vector) Tablespace_table_ref objects
221 which describe tables in a given tablespace.
222
223 @param thd thread context
224 @param tso dd object
225 @param tblrefs [OUT] Tablespace_table_ref objects for tables in tablespace
226 @retval true if error occurred
227 @retval false otherwise
228 */
229bool fetch_tablespace_table_refs(THD *thd, const Tablespace &tso,
230 Tablespace_table_ref_vec *tblrefs);
231
232/**
233 Create am MDL_request for a the table identified by a Tablespace_table_ref.
234 @param thd thread context
235 @param tref table to create request for
236 @param mdl_type The lock type requested.
237 @retval MDL_request (allocated on thd->memroot)
238 */
240 enum enum_mdl_type mdl_type);
241
242/**
243 Create am MDL_request for a the schema name provided.
244 @param thd thread context
245 @param schema_name on which to create request for
246 @retval MDL_request (allocated on thd->memroot)
247 */
248MDL_request *mdl_schema_req(THD *thd, const dd::String_type &schema_name);
249
250} // namespace dd
251
252#endif // DD__TABLESPACE_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: collection.h:44
Base class for dictionary objects which has single column integer primary key.
Definition: entity_object.h:48
virtual const String_type & name() const =0
Definition: object_keys.h:123
Definition: object_keys.h:77
The Properties class defines an interface for storing key=value pairs, where both key and value may b...
Definition: properties.h:74
Opaque context which keeps reusable resoureces needed during deserialization.
Definition: sdi.cc:231
Opaque context which keeps reusable resources needed during serialization.
Definition: sdi.cc:129
Definition: tablespace_file.h:45
Definition: tablespace_impl.h:57
Definition: tablespace.h:56
tables::Tablespaces DD_table
Definition: tablespace.h:60
virtual const Properties & se_private_data() const =0
virtual Tablespace_file * add_file()=0
Void_key Aux_key
Definition: tablespace.h:63
virtual Tablespace * clone() const =0
Allocate a new object graph and invoke the copy constructor for each object.
virtual Properties & options()=0
virtual Properties & se_private_data()=0
Tablespace Cache_partition
Definition: tablespace.h:59
virtual bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val)=0
Re-establishes the state of *this by reading sdi information from the rapidjson DOM subobject provide...
virtual const String_type & engine() const =0
virtual bool set_options(const String_type &options_raw)=0
Primary_id_key Id_key
Definition: tablespace.h:61
virtual void set_comment(const String_type &comment)=0
~Tablespace() override=default
virtual bool is_empty(THD *thd, bool *empty) const =0
Check if the tablespace is empty, i.e., whether it has any tables.
virtual bool update_aux_key(Aux_key *) const
Definition: tablespace.h:79
virtual Tablespace * clone_dropped_object_placeholder() const =0
Allocate a new object which can serve as a placeholder for the original object in the Dictionary_clie...
virtual const Tablespace_file_collection & files() const =0
virtual LEX_CSTRING engine_attribute() const =0
Tablespace_impl Impl
Definition: tablespace.h:58
virtual void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const =0
Converts *this into json.
virtual void set_engine(const String_type &engine)=0
virtual bool update_id_key(Id_key *key) const
Definition: tablespace.h:67
virtual bool set_se_private_data(const String_type &se_private_data_raw)=0
Collection< Tablespace_file * > Tablespace_file_collection
Definition: tablespace.h:64
virtual const String_type & comment() const =0
Global_name_key Name_key
Definition: tablespace.h:62
virtual bool update_name_key(Name_key *key) const
Definition: tablespace.h:73
virtual void set_engine_attribute(LEX_CSTRING a)=0
virtual bool remove_file(String_type data_file)=0
virtual const Properties & options() const =0
Definition: object_keys.h:54
Definition: tablespaces.h:41
Some integer typedefs for easier portability.
std::vector< Moved > Tablespaces
Definition: fil0fil.cc:127
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
RJ_Writer Sdi_writer
Alias for the rapidjson Writer type to use in serialization.
Definition: sdi_fwd.h:64
unsigned long long Object_id
Definition: object_id.h:31
bool operator<(const Tablespace_table_ref &a, const Tablespace_table_ref &b)
Definition: tablespace_impl.cc:404
bool fetch_tablespace_table_refs(THD *thd, const Tablespace &tso, Tablespace_table_ref_vec *tblrefsp)
Fetch (by inserting into tblref vector) Tablespace_table_ref objects which describe tables in a given...
Definition: tablespace_impl.cc:408
std::vector< Tablespace_table_ref > Tablespace_table_ref_vec
Definition: tablespace.h:217
bool operator==(const Tablespace_table_ref &a, const Tablespace_table_ref &b)
Definition: tablespace_impl.cc:400
MDL_request * mdl_req(THD *thd, const Tablespace_table_ref &tref, enum enum_mdl_type mdl_type)
Create am MDL_request for a the table identified by a Tablespace_table_ref.
Definition: tablespace_impl.cc:534
rapidjson::GenericValue< RJ_Encoding, RJ_Allocator > RJ_Value
Definition: sdi_fwd.h:49
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:51
MDL_request * mdl_schema_req(THD *thd, const dd::String_type &schema_name)
Create am MDL_request for a the schema name provided.
Definition: tablespace_impl.cc:552
Definition: gcs_xcom_synode.h:64
required string key
Definition: replication_asynchronous_connection_failover.proto:60
This header provides Rapidjson Type Aliases.
enum_mdl_type
Type of metadata lock request.
Definition: sql_lexer_yacc_state.h:106
case opt name
Definition: sslopt-case.h:29
Definition: mysql_lex_string.h:40
Represents tables with their id, name, schema id and schema name.
Definition: tablespace.h:198
Object_id m_id
Definition: tablespace.h:199
Tablespace_table_ref(Object_id id, const String_type &&name, Object_id schema_id)
Definition: tablespace.h:205
Object_id m_schema_id
Definition: tablespace.h:201
String_type m_schema_name
Definition: tablespace.h:202
String_type m_name
Definition: tablespace.h:200
bool m_schema_encryption
Definition: tablespace.h:203
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:510