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