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