MySQL  8.0.19
Source Code Documentation
dd_properties.h
Go to the documentation of this file.
1 /* Copyright (c) 2014, 2018, 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_TABLES__DD_PROPERTIES_INCLUDED
24 #define DD_TABLES__DD_PROPERTIES_INCLUDED
25 
26 #include <sys/types.h>
27 #include <map>
28 #include <string>
29 
30 #include "sql/dd/impl/properties_impl.h" // dd::Properties_impl
32 #include "sql/dd/string_type.h"
33 
34 class THD;
35 
36 namespace dd {
37 namespace tables {
38 
39 ///////////////////////////////////////////////////////////////////////////
40 
42  public:
43  DD_properties();
44 
46 
47  static DD_properties &instance();
48 
49  /**
50  The 'mysql.dd_properties' table will store key=value pairs. The valid
51  keys are predefined, and represented in an internal map as pairs of
52  'key name','type'. This is used in get() and set() to verify that the
53  key is valid, and that the type of the value we are getting or setting
54  is correct.
55 
56  One of the keys is 'SYSTEM_TABLES'. This is itself a property object
57  where the keys are names of DD tables, and the values are property
58  objects containing information about each table. These property objects
59  will also have a set of predefined keys. These are defined by an
60  enumeration, and there is a function that returns keys for each
61  enumeration value. The purpose of this is to avoid directly entering
62  keys in the source code, which is prone to mistyping etc.
63 
64  The two structures of valid keys are separate because they are used for
65  different purposes. The top level keys defined in the internal map are
66  used when properties at the top level are being looked up. The keys for
67  the DD tables are used to lookup in the property object which is associated
68  with a table DD name.
69  */
70 
71  /**
72  Enumeration used to lookup the valid keys for the DD table properties.
73  */
74  enum class DD_property { ID, DATA, SPACE_ID, IDX, COL, DEF };
75 
76  /**
77  Property key names for DD table properties.
78 
79  @param label Enumeration label of the key.
80 
81  @return Key character string.
82  */
83  static const char *dd_key(DD_property label) {
84  switch (label) {
85  case DD_property::ID:
86  return "id";
87  case DD_property::DATA:
88  return "data";
90  return "space_id";
91  case DD_property::IDX:
92  return "idx";
93  case DD_property::COL:
94  return "col";
95  case DD_property::DEF:
96  return "def";
97  default:
98  DBUG_ASSERT(false);
99  return "";
100  }
101  }
102 
103  /**
104  Get the integer value of the property key.
105 
106  Will validate the key before retrieving the value.
107 
108  @param thd Thread context.
109  @param key The key representing the property.
110  @param [out] value Corresponding value, if it exists, otherwise
111  undefined.
112  @param [out] exists Will be 'false' if key is not present.
113 
114  @returns false on success otherwise true.
115  */
116  bool get(THD *thd, const String_type &key, uint *value, bool *exists);
117 
118  /**
119  Set the integer value of the property key.
120 
121  Will validate the key before setting the value.
122 
123  @param thd Thread context.
124  @param key The key representing the property.
125  @param value The value to be stored for 'key'.
126 
127  @returns false on success otherwise true.
128  */
129  bool set(THD *thd, const String_type &key, uint value);
130 
131  /**
132  Get the character string value of the property key.
133 
134  Will validate the key before retrieving the value.
135 
136  @param thd Thread context.
137  @param key The key representing the property.
138  @param [out] value Corresponding value, if it exists, otherwise
139  undefined.
140  @param [out] exists Will be 'false' if key is not present.
141 
142  @returns false on success otherwise true.
143  */
144  bool get(THD *thd, const String_type &key, String_type *value, bool *exists);
145 
146  /**
147  Set the character string value of the property key.
148 
149  Will validate the key before setting the value.
150 
151  @param thd Thread context.
152  @param key The key representing the property.
153  @param value The value to be stored for 'key'.
154 
155  @returns false on success otherwise true.
156  */
157  bool set(THD *thd, const String_type &key, const String_type &value);
158 
159  /**
160  Get the properties object associated with a key.
161 
162  Will validate the key before retrieving the properties. Used to
163  get hold of SE private data for the DD tables.
164 
165  @param thd Thread context.
166  @param key Key name.
167  @param [out] properties Properties object associated with the key.
168  @param [out] exists Will be 'false' if key is not present.
169 
170  @returns false on success otherwise true.
171  */
172  bool get(THD *thd, const String_type &key,
173  std::unique_ptr<Properties> *properties, bool *exists);
174 
175  /**
176  Set the properties object associated with a key.
177 
178  Will validate the key before setting the properties. Used to
179  store SE private data for the DD tables.
180 
181  @param thd Thread context.
182  @param key Key name.
183  @param properties Properties object associated with the key.
184 
185  @returns false on success otherwise true.
186  */
187  bool set(THD *thd, const String_type &key, const dd::Properties &properties);
188 
189  /**
190  Remove a property key.
191 
192  @param thd Thread context.
193  @param key Key name.
194 
195  @returns false on success otherwise true.
196  */
197  bool remove(THD *thd, const String_type &key);
198 
199  private:
200  // A cache of the table contents.
202 
203  // Definitions of the valid property types. Used for internal validation.
205 
206  // Map from valid property keys to types. Used for internal validation.
207  std::map<String_type, Property_type> m_property_desc;
208 
209  /**
210  Initialize the cached properties by reading from disk.
211 
212  @param thd Thread context.
213 
214  @returns false on success otherwise true.
215  */
216  bool init_cached_properties(THD *thd);
217 
218  /**
219  Flush the cached properties to disk.
220 
221  @param thd Thread context.
222 
223  @returns false on success otherwise true.
224  */
225  bool flush_cached_properties(THD *thd);
226 
227  /**
228  Get the value of the property key.
229 
230  Will initialize the cached properties stored in the DD_properties instance
231  if not already done. No key validation is done, this is expected to be
232  done before this function is called.
233 
234  @param thd Thread context.
235  @param key The key representing the property.
236  @param [out] value Corresponding value, if it exists, otherwise
237  undefined.
238  @param [out] exists Will be 'false' if key is not present.
239 
240  @returns false on success otherwise true.
241  */
242  bool unchecked_get(THD *thd, const String_type &key, String_type *value,
243  bool *exists);
244 
245  /**
246  Set the value of the property key.
247 
248  Will initialize the cached properties stored in the DD_properties instance
249  if not already done. No key validation is done, this is expected to be
250  done before this function is called. Properties are flushed to disk after
251  the cache is updated.
252 
253  @param thd Thread context.
254  @param key The key representing the property.
255  @param value The value to be stored for 'key'.
256 
257  @returns false on success otherwise true.
258  */
259  bool unchecked_set(THD *thd, const String_type &key,
260  const String_type &value);
261 };
262 
263 ///////////////////////////////////////////////////////////////////////////
264 
265 } // namespace tables
266 } // namespace dd
267 
268 #endif // DD_TABLES__DD_PROPERTIES_INCLUDED
dd::Properties
The Properties class defines an interface for storing key=value pairs, where both key and value may b...
Definition: properties.h:73
dd::tables::DD_properties::unchecked_set
bool unchecked_set(THD *thd, const String_type &key, const String_type &value)
Set the value of the property key.
Definition: dd_properties.cc:229
THD
Definition: sql_class.h:764
dd::String_type
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:50
properties_impl.h
dd::tables::DD_properties::Property_type::UNSIGNED_INT_32
@ UNSIGNED_INT_32
dd::tables::DD_properties::DD_property::COL
@ COL
dd::tables::DD_properties::DD_properties
DD_properties()
Definition: dd_properties.cc:58
dd::tables::DD_properties::m_property_desc
std::map< String_type, Property_type > m_property_desc
Definition: dd_properties.h:207
dd::tables::DD_properties::enum_fields
enum_fields
Definition: dd_properties.h:45
value
const string value("\"Value\"")
dd::tables::DD_properties::get
bool get(THD *thd, const String_type &key, uint *value, bool *exists)
Get the integer value of the property key.
Definition: dd_properties.cc:240
dd
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:39
key
static const char * key
Definition: suite_stubs.c:14
dd::tables::DD_properties::DD_property::ID
@ ID
dd::tables::DD_properties::flush_cached_properties
bool flush_cached_properties(THD *thd)
Flush the cached properties to disk.
Definition: dd_properties.cc:156
dd::tables::DD_properties::Property_type::PROPERTIES
@ PROPERTIES
dd::Object_table_impl
Definition: object_table_impl.h:35
dd::Properties_impl
The Properties_impl class implements the Properties interface.
Definition: properties_impl.h:75
dd::tables::DD_properties::DD_property::SPACE_ID
@ SPACE_ID
dd::tables::DD_properties::Property_type
Property_type
Definition: dd_properties.h:204
uint
unsigned int uint
Definition: uca-dump.cc:29
dd::tables::DD_properties::unchecked_get
bool unchecked_get(THD *thd, const String_type &key, String_type *value, bool *exists)
Get the value of the property key.
Definition: dd_properties.cc:209
dd::tables::DD_properties::m_properties
Properties_impl m_properties
Definition: dd_properties.h:201
string_type.h
dd::tables::DD_properties
Definition: dd_properties.h:41
exists
static int exists(node_address *name, node_list const *nodes, u_int with_uid)
Definition: node_list.c:108
dd::tables::DD_properties::set
bool set(THD *thd, const String_type &key, uint value)
Set the integer value of the property key.
Definition: dd_properties.cc:250
dd::tables::DD_properties::DD_property::DEF
@ DEF
dd::tables::DD_properties::DD_property::IDX
@ IDX
DBUG_ASSERT
#define DBUG_ASSERT(A)
Definition: my_dbug.h:197
dd::tables::DD_properties::FIELD_PROPERTIES
@ FIELD_PROPERTIES
Definition: dd_properties.h:45
dd::tables::DD_properties::remove
bool remove(THD *thd, const String_type &key)
Remove a property key.
Definition: dd_properties.cc:294
dd::tables::DD_properties::init_cached_properties
bool init_cached_properties(THD *thd)
Initialize the cached properties by reading from disk.
Definition: dd_properties.cc:113
dd::tables::DD_properties::DD_property
DD_property
The 'mysql.dd_properties' table will store key=value pairs.
Definition: dd_properties.h:74
dd::tables::DD_properties::instance
static DD_properties & instance()
Definition: dd_properties.cc:52
dd::tables::DD_properties::dd_key
static const char * dd_key(DD_property label)
Property key names for DD table properties.
Definition: dd_properties.h:83
dd::tables::DD_properties::Property_type::CHARACTER_STRING
@ CHARACTER_STRING
object_table_impl.h
dd::tables::DD_properties::DD_property::DATA
@ DATA