MySQL 8.0.39
Source Code Documentation
storage_adapter.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 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_CACHE__STORAGE_ADAPTER_INCLUDED
25#define DD_CACHE__STORAGE_ADAPTER_INCLUDED
26
27#include <stddef.h>
28
32#include "sql/dd/cache/object_registry.h" // Object_registry
33#include "sql/dd/object_id.h"
34#include "sql/handler.h" // enum_tx_isolation
35#include "thr_mutex.h"
36
37class THD;
38
39namespace dd_cache_unittest {
40class CacheStorageTest;
41}
42
43namespace dd {
44
45namespace cache {
46
47/**
48 Handling of access to persistent storage.
49
50 This class provides static template functions that manipulates an object on
51 persistent storage based on the submitted key and object type. There is also
52 an object registry instance to keep the core DD objects that are needed to
53 handle cache misses for table meta data. The storage adapter owns the objects
54 in the core registry. When adding objects to the registry using core_store(),
55 the storage adapter will clone the object and take ownership of the clone.
56 When retrieving objects from the registry using core_get(), a clone of the
57 object will be returned, and this is therefore owned by the caller.
58*/
59
62
63 private:
64 /**
65 Use an id not starting at 1 to make it easy to recognize ids generated
66 before objects are stored persistently.
67 */
68
69 static const Object_id FIRST_OID = 10001;
70
71 /**
72 Generate a new object id for a registry partition.
73
74 Simulate an auto increment column. Used when the server is starting,
75 while the scaffolding is being built.
76
77 @tparam T Object registry partition.
78
79 @return Next object id to be used.
80 */
81
82 template <typename T>
84
85 /**
86 Get a dictionary object from core storage.
87
88 A clone of the registry object will be returned, owned by the caller.
89
90 @tparam K Key type.
91 @tparam T Dictionary object type.
92 @param key Key for which to get the object.
93 @param [out] object Object retrieved, possibly nullptr if not present.
94 */
95
96 template <typename K, typename T>
97 void core_get(const K &key, const T **object);
98
99 Object_registry m_core_registry; // Object registry storing core DD objects.
100 mysql_mutex_t m_lock; // Single mutex to protect the registry.
101 static bool s_use_fake_storage; // Whether to use the core registry to
102 // simulate the storage engine.
103
106 }
107
113 }
114
115 public:
116 static Storage_adapter *instance();
117
118 /**
119 Get the number of core objects in a registry partition.
120
121 @tparam T Dictionary object type.
122 @return Number of elements.
123 */
124
125 template <typename T>
126 size_t core_size();
127
128 /**
129 Get a dictionary object id from core storage.
130
131 @tparam T Dictionary object type.
132 @param key Name key for which to get the object id.
133 @return Object id, INVALID_OBJECT_ID if the object is not present.
134 */
135
136 template <typename T>
137 Object_id core_get_id(const typename T::Name_key &key);
138
139 /**
140 Update the dd object in the core registry. This is a noop unless
141 this member function is overloaded for a given type. See below.
142 */
143 template <typename T>
144 void core_update(const T *) {}
145
146 /**
147 Overload of core_update for dd::Tablespace. Currently the core
148 registry can only be updated for the DD tablespace when
149 encrypting it. A clone of the dd::Tablespace object passed in is
150 stored in the registry.
151
152 @param new_tsp the new dd::Tablespace object to keep in the core registry.
153 */
154 void core_update(const dd::Tablespace *new_tsp);
155
156 /**
157 Get a dictionary object from persistent storage.
158
159 Create an access key based on the submitted key, and find the record
160 from the appropriate table. Restore the record into a new dictionary
161 object.
162
163 @tparam K Key type.
164 @tparam T Dictionary object type.
165 @param thd Thread context.
166 @param key Key for which to get the object.
167 @param isolation Isolation level.
168 @param bypass_core_registry If set to true, get the object from the
169 DD tables. Needed during DD bootstrap.
170 @param [out] object Object retrieved, possibly NULL if not present.
171
172 @retval false No error.
173 @retval true Error.
174 */
175
176 template <typename K, typename T>
177 static bool get(THD *thd, const K &key, enum_tx_isolation isolation,
178 bool bypass_core_registry, const T **object);
179
180 /**
181 Drop a dictionary object from core storage.
182
183 @tparam T Dictionary object type.
184 @param thd Thread context.
185 @param object Object to be dropped.
186 */
187
188 template <typename T>
189 void core_drop(THD *thd, const T *object);
190
191 /**
192 Drop a dictionary object from persistent storage.
193
194 @tparam T Dictionary object type.
195 @param thd Thread context.
196 @param object Object to be dropped.
197
198 @retval false No error.
199 @retval true Error.
200 */
201
202 template <typename T>
203 static bool drop(THD *thd, const T *object);
204
205 /**
206 Store a dictionary object to core storage.
207
208 A clone of the submitted object will be added to the core
209 storage. The caller is still the owner of the submitted
210 objecct.
211
212 @tparam T Dictionary object type.
213 @param thd Thread context.
214 @param object Object to be stored.
215 */
216
217 template <typename T>
218 void core_store(THD *thd, T *object);
219
220 /**
221 Store a dictionary object to persistent storage.
222
223 @tparam T Dictionary object type.
224 @param thd Thread context.
225 @param object Object to be stored.
226
227 @retval false No error.
228 @retval true Error.
229 */
230
231 template <typename T>
232 static bool store(THD *thd, T *object);
233
234 /**
235 Sync a dictionary object from persistent to core storage.
236
237 @tparam T Dictionary object type.
238 @param thd Thread context.
239 @param key Key for object to get from persistent storage.
240 @param object Object to drop from the core registry.
241 */
242
243 template <typename T>
244 bool core_sync(THD *thd, const typename T::Name_key &key, const T *object);
245
246 /**
247 Remove and delete all elements and objects from core storage.
248 */
249
250 void erase_all();
251
252 /**
253 Dump the contents of the core storage.
254 */
255
256 void dump();
257};
258
259} // namespace cache
260} // namespace dd
261
262#endif // DD_CACHE__STORAGE_ADAPTER_INCLUDED
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
Definition: tablespace.h:55
Object registry containing several maps.
Definition: object_registry.h:62
void erase_all()
Remove and delete all objects from the registry.
Definition: object_registry.h:321
Handling of access to persistent storage.
Definition: storage_adapter.h:60
void core_update(const T *)
Update the dd object in the core registry.
Definition: storage_adapter.h:144
static bool get(THD *thd, const K &key, enum_tx_isolation isolation, bool bypass_core_registry, const T **object)
Get a dictionary object from persistent storage.
Definition: storage_adapter.cc:151
static Storage_adapter * instance()
Definition: storage_adapter.cc:81
Object_id next_oid()
Generate a new object id for a registry partition.
Definition: storage_adapter.cc:90
static const Object_id FIRST_OID
Use an id not starting at 1 to make it easy to recognize ids generated before objects are stored pers...
Definition: storage_adapter.h:69
void erase_all()
Remove and delete all elements and objects from core storage.
Definition: storage_adapter.cc:416
static bool store(THD *thd, T *object)
Store a dictionary object to persistent storage.
Definition: storage_adapter.cc:314
void core_get(const K &key, const T **object)
Get a dictionary object from core storage.
Definition: storage_adapter.cc:117
void core_store(THD *thd, T *object)
Store a dictionary object to core storage.
Definition: storage_adapter.cc:275
static bool drop(THD *thd, const T *object)
Drop a dictionary object from persistent storage.
Definition: storage_adapter.cc:243
Object_id core_get_id(const typename T::Name_key &key)
Get a dictionary object id from core storage.
Definition: storage_adapter.cc:104
~Storage_adapter()
Definition: storage_adapter.h:108
bool core_sync(THD *thd, const typename T::Name_key &key, const T *object)
Sync a dictionary object from persistent to core storage.
Definition: storage_adapter.cc:354
Object_registry m_core_registry
Definition: storage_adapter.h:99
mysql_mutex_t m_lock
Definition: storage_adapter.h:100
size_t core_size()
Get the number of core objects in a registry partition.
Definition: storage_adapter.cc:97
static bool s_use_fake_storage
Definition: storage_adapter.h:101
void core_drop(THD *thd, const T *object)
Drop a dictionary object from core storage.
Definition: storage_adapter.cc:215
void dump()
Dump the contents of the core storage.
Definition: storage_adapter.cc:422
Storage_adapter()
Definition: storage_adapter.h:104
friend class dd_cache_unittest::CacheStorageTest
Definition: storage_adapter.h:61
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:50
#define mysql_mutex_destroy(M)
Definition: mysql_mutex.h:46
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:57
#define mysql_mutex_init(K, M, A)
Definition: mysql_mutex.h:41
ABI for instrumented mutexes.
Definition: dictionary_client.h:1274
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
unsigned long long Object_id
Definition: object_id.h:31
Instrumentation helpers for mutexes.
Performance schema instrumentation interface.
required string key
Definition: replication_asynchronous_connection_failover.proto:60
enum_tx_isolation
Definition: handler.h:3029
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
MySQL mutex implementation.
#define MY_MUTEX_INIT_FAST
Definition: thr_mutex.h:68
#define PSI_NOT_INSTRUMENTED
Definition: validate_password_imp.cc:42