MySQL 8.3.0
Source Code Documentation
dd_properties.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 2023, 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 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
34class THD;
35
36namespace dd {
37namespace tables {
38
39///////////////////////////////////////////////////////////////////////////
40
42 public:
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";
88 return "data";
90 return "space_id";
92 return "idx";
94 return "col";
96 return "def";
97 default:
98 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
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
Definition: object_table_impl.h:35
The Properties_impl class implements the Properties interface.
Definition: properties_impl.h:76
The Properties class defines an interface for storing key=value pairs, where both key and value may b...
Definition: properties.h:73
Definition: dd_properties.h:41
DD_properties()
Definition: dd_properties.cc:59
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:225
bool remove(THD *thd, const String_type &key)
Remove a property key.
Definition: dd_properties.cc:310
Properties_impl m_properties
Definition: dd_properties.h:201
static DD_properties & instance()
Definition: dd_properties.cc:53
bool init_cached_properties(THD *thd)
Initialize the cached properties by reading from disk.
Definition: dd_properties.cc:129
bool flush_cached_properties(THD *thd)
Flush the cached properties to disk.
Definition: dd_properties.cc:172
bool unchecked_set(THD *thd, const String_type &key, const String_type &value)
Set the value of the property key.
Definition: dd_properties.cc:245
Property_type
Definition: dd_properties.h:204
bool set(THD *thd, const String_type &key, uint value)
Set the integer value of the property key.
Definition: dd_properties.cc:266
enum_fields
Definition: dd_properties.h:45
@ FIELD_PROPERTIES
Definition: dd_properties.h:45
static const char * dd_key(DD_property label)
Property key names for DD table properties.
Definition: dd_properties.h:83
DD_property
The 'mysql.dd_properties' table will store key=value pairs.
Definition: dd_properties.h:74
std::map< String_type, Property_type > m_property_desc
Definition: dd_properties.h:207
bool get(THD *thd, const String_type &key, uint *value, bool *exists)
Get the integer value of the property key.
Definition: dd_properties.cc:256
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:50
static int exists(node_address *name, node_list const *nodes, u_int with_uid)
Definition: node_list.cc:105
required string key
Definition: replication_asynchronous_connection_failover.proto:59