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