-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathdd_properties.h
269 lines (202 loc) · 8.63 KB
/
dd_properties.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/* Copyright (c) 2014, 2025, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#ifndef DD_TABLES__DD_PROPERTIES_INCLUDED
#define DD_TABLES__DD_PROPERTIES_INCLUDED
#include <sys/types.h>
#include <map>
#include <string>
#include "sql/dd/impl/properties_impl.h" // dd::Properties_impl
#include "sql/dd/impl/types/object_table_impl.h"
#include "sql/dd/string_type.h"
class THD;
namespace dd {
namespace tables {
///////////////////////////////////////////////////////////////////////////
class DD_properties : public Object_table_impl {
public:
DD_properties();
enum enum_fields { FIELD_PROPERTIES };
static DD_properties &instance();
/**
The 'mysql.dd_properties' table will store key=value pairs. The valid
keys are predefined, and represented in an internal map as pairs of
'key name','type'. This is used in get() and set() to verify that the
key is valid, and that the type of the value we are getting or setting
is correct.
One of the keys is 'SYSTEM_TABLES'. This is itself a property object
where the keys are names of DD tables, and the values are property
objects containing information about each table. These property objects
will also have a set of predefined keys. These are defined by an
enumeration, and there is a function that returns keys for each
enumeration value. The purpose of this is to avoid directly entering
keys in the source code, which is prone to mistyping etc.
The two structures of valid keys are separate because they are used for
different purposes. The top level keys defined in the internal map are
used when properties at the top level are being looked up. The keys for
the DD tables are used to lookup in the property object which is associated
with a table DD name.
*/
/**
Enumeration used to lookup the valid keys for the DD table properties.
*/
enum class DD_property { ID, DATA, SPACE_ID, IDX, COL, DEF };
/**
Property key names for DD table properties.
@param label Enumeration label of the key.
@return Key character string.
*/
static const char *dd_key(DD_property label) {
switch (label) {
case DD_property::ID:
return "id";
case DD_property::DATA:
return "data";
case DD_property::SPACE_ID:
return "space_id";
case DD_property::IDX:
return "idx";
case DD_property::COL:
return "col";
case DD_property::DEF:
return "def";
default:
assert(false);
return "";
}
}
/**
Get the integer value of the property key.
Will validate the key before retrieving the value.
@param thd Thread context.
@param key The key representing the property.
@param [out] value Corresponding value, if it exists, otherwise
undefined.
@param [out] exists Will be 'false' if key is not present.
@returns false on success otherwise true.
*/
bool get(THD *thd, const String_type &key, uint *value, bool *exists);
/**
Set the integer value of the property key.
Will validate the key before setting the value.
@param thd Thread context.
@param key The key representing the property.
@param value The value to be stored for 'key'.
@returns false on success otherwise true.
*/
bool set(THD *thd, const String_type &key, uint value);
/**
Get the character string value of the property key.
Will validate the key before retrieving the value.
@param thd Thread context.
@param key The key representing the property.
@param [out] value Corresponding value, if it exists, otherwise
undefined.
@param [out] exists Will be 'false' if key is not present.
@returns false on success otherwise true.
*/
bool get(THD *thd, const String_type &key, String_type *value, bool *exists);
/**
Set the character string value of the property key.
Will validate the key before setting the value.
@param thd Thread context.
@param key The key representing the property.
@param value The value to be stored for 'key'.
@returns false on success otherwise true.
*/
bool set(THD *thd, const String_type &key, const String_type &value);
/**
Get the properties object associated with a key.
Will validate the key before retrieving the properties. Used to
get hold of SE private data for the DD tables.
@param thd Thread context.
@param key Key name.
@param [out] properties Properties object associated with the key.
@param [out] exists Will be 'false' if key is not present.
@returns false on success otherwise true.
*/
bool get(THD *thd, const String_type &key,
std::unique_ptr<Properties> *properties, bool *exists);
/**
Set the properties object associated with a key.
Will validate the key before setting the properties. Used to
store SE private data for the DD tables.
@param thd Thread context.
@param key Key name.
@param properties Properties object associated with the key.
@returns false on success otherwise true.
*/
bool set(THD *thd, const String_type &key, const dd::Properties &properties);
/**
Remove a property key.
@param thd Thread context.
@param key Key name.
@returns false on success otherwise true.
*/
bool remove(THD *thd, const String_type &key);
private:
// A cache of the table contents.
Properties_impl m_properties;
// Definitions of the valid property types. Used for internal validation.
enum class Property_type { UNSIGNED_INT_32, CHARACTER_STRING, PROPERTIES };
// Map from valid property keys to types. Used for internal validation.
std::map<String_type, Property_type> m_property_desc;
/**
Initialize the cached properties by reading from disk.
@param thd Thread context.
@returns false on success otherwise true.
*/
bool init_cached_properties(THD *thd);
/**
Flush the cached properties to disk.
@param thd Thread context.
@returns false on success otherwise true.
*/
bool flush_cached_properties(THD *thd);
/**
Get the value of the property key.
Will initialize the cached properties stored in the DD_properties instance
if not already done. No key validation is done, this is expected to be
done before this function is called.
@param thd Thread context.
@param key The key representing the property.
@param [out] value Corresponding value, if it exists, otherwise
undefined.
@param [out] exists Will be 'false' if key is not present.
@returns false on success otherwise true.
*/
bool unchecked_get(THD *thd, const String_type &key, String_type *value,
bool *exists);
/**
Set the value of the property key.
Will initialize the cached properties stored in the DD_properties instance
if not already done. No key validation is done, this is expected to be
done before this function is called. Properties are flushed to disk after
the cache is updated.
@param thd Thread context.
@param key The key representing the property.
@param value The value to be stored for 'key'.
@returns false on success otherwise true.
*/
bool unchecked_set(THD *thd, const String_type &key,
const String_type &value);
};
///////////////////////////////////////////////////////////////////////////
} // namespace tables
} // namespace dd
#endif // DD_TABLES__DD_PROPERTIES_INCLUDED