MySQL 8.0.39
Source Code Documentation
psi_data_lock.h
Go to the documentation of this file.
1/* Copyright (c) 2016, 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 MYSQL_PSI_DATA_LOCK_H
25#define MYSQL_PSI_DATA_LOCK_H
26
27/**
28 @file include/mysql/psi/psi_data_lock.h
29 Performance schema instrumentation interface.
30
31 @defgroup psi_abi_data_lock Row Lock Instrumentation (ABI)
32 @ingroup psi_abi
33 @{
34*/
35
36#include "my_inttypes.h"
37#include "my_sharedlib.h"
38
39/* HAVE_PSI_*_INTERFACE */
40#include "my_psi_config.h" // IWYU pragma: keep
41
42#ifdef HAVE_PSI_DATA_LOCK_INTERFACE
43
44/**
45 @def PSI_DATA_LOCK_VERSION_1
46 Performance Schema Row Lock Interface number for version 1.
47 This version is supported.
48*/
49#define PSI_DATA_LOCK_VERSION_1 1
50
51/**
52 @def PSI_DATA_LOCK_VERSION_2
53 Performance Schema Row Lock Interface number for version 2.
54 This version is not implemented, it's a placeholder.
55*/
56#define PSI_DATA_LOCK_VERSION_2 2
57
58/**
59 @def PSI_CURRENT_DATA_LOCK_VERSION
60 Performance Schema Row Lock Interface number for the most recent version.
61 The most current version is @c PSI_DATA_LOCK_VERSION_1
62*/
63#define PSI_CURRENT_DATA_LOCK_VERSION 1
64
65#ifndef USE_PSI_DATA_LOCK_2
66#ifndef USE_PSI_DATA_LOCK_1
67#ifdef __cplusplus
68#define USE_PSI_DATA_LOCK_1
69#endif /* __cplusplus */
70#endif /* USE_PSI_DATA_LOCK_1 */
71#endif /* USE_PSI_DATA_LOCK_2 */
72
73#ifdef USE_PSI_DATA_LOCK_1
74#define HAVE_PSI_DATA_LOCK_1
75#endif /* USE_PSI_DATA_LOCK_1 */
76
77#ifdef USE_PSI_DATA_LOCK_2
78#define HAVE_PSI_DATA_LOCK_2
79#endif
80
81/** Entry point for the performance schema interface. */
83 /**
84 ABI interface finder.
85 Calling this method with an interface version number returns either
86 an instance of the ABI for this version, or NULL.
87 @sa PSI_DATA_LOCK_VERSION_1
88 @sa PSI_DATA_LOCK_VERSION_2
89 @sa PSI_CURRENT_DATA_LOCK_VERSION
90 */
91 void *(*get_interface)(int version);
92};
94
95#ifdef HAVE_PSI_DATA_LOCK_1
96
105
106/**
107 Server interface, row lock container.
108 This is the interface exposed
109 - by the server
110 - to the storage engines
111 used to collect the data for table DATA_LOCKS.
112 The server is to implement this interface.
113 The storage engine is to call all_lock_row()
114 to advertise row locks that exists within
115 the storage engine tables.
116*/
118 public:
121
122 /**
123 Add a string to the container cache.
124 Cached strings have the same life cycle as the data container,
125 and are freed when the container is destroyed.
126 Also, duplicated strings value are cached with the same copy,
127 avoiding memory duplication.
128 This is useful in particular to cache table schema or table names,
129 which are duplicated a lot for different row locks on the same table.
130 */
131 virtual const char *cache_string(const char *string) = 0;
132 /**
133 Add binary data to the container cache.
134 @sa cache_string
135 */
136 virtual const char *cache_data(const char *ptr, size_t length) = 0;
137
138 /**
139 Add an identifier in the container cache.
140 Depending on the identifier kind, the string given may be
141 normalized, to comply with lower_case_table_names,
142 before adding the string into the cache.
143 Beware that the normalized string length may differ
144 from the input string length.
145 @param[in] kind Identifier kind, used for string normalization
146 @param[in] str Identifier input string
147 @param[in] length Identifier input string length
148 @param[out] cached_ptr Cached, possibly normalized, identifier string
149 @param[out] cached_length Cached identifier string length
150 */
151 virtual void cache_identifier(PSI_identifier kind, const char *str,
152 size_t length, const char **cached_ptr,
153 size_t *cached_length) = 0;
154
155 /**
156 Check if the container accepts data for a particular engine.
157 This methods is used to prune data for queries like
158 @code SELECT * from performance_schema.data_locks WHERE ENGINE = ...
159 @endcode
160 */
161 virtual bool accept_engine(const char *engine, size_t engine_length) = 0;
162
163 /**
164 Check if the container accepts data for a particular lock.
165 This methods is used to prune data for queries like
166 @code SELECT * from performance_schema.data_locks WHERE ENGINE_LOCK_ID = ...
167 @endcode
168 */
169 virtual bool accept_lock_id(const char *engine_lock_id,
170 size_t engine_lock_id_length) = 0;
171
172 /**
173 Check if the container accepts data for a particular transaction.
174 This methods is used to prune data for queries like
175 @code SELECT * from performance_schema.data_locks WHERE
176 ENGINE_TRANSACTION_ID = ... @endcode
177 */
178 virtual bool accept_transaction_id(ulonglong transaction_id) = 0;
179
180 /**
181 Check if the container accepts data for a particular event.
182 This methods is used to prune data for queries like
183 @code SELECT * from performance_schema.data_locks
184 WHERE THREAD_ID = ... AND EVENT_ID = ... @endcode
185 */
187 ulonglong event_id) = 0;
188
189 /**
190 Check if the container accepts data for a particular object.
191 This methods is used to prune data for queries like
192 @code SELECT * from performance_schema.data_locks
193 WHERE OBJECT_SCHEMA = ...
194 AND OBJECT_NAME = ...
195 AND PARTITION_NAME = ...
196 AND SUBPARTITION_NAME = ... @endcode
197 */
198 virtual bool accept_object(const char *table_schema,
199 size_t table_schema_length, const char *table_name,
200 size_t table_name_length,
201 const char *partition_name,
202 size_t partition_name_length,
203 const char *sub_partition_name,
204 size_t sub_partition_name_length) = 0;
205
206 /** Add a row to table performance_schema.data_locks. */
207 virtual void add_lock_row(
208 const char *engine, size_t engine_length, const char *engine_lock_id,
209 size_t engine_lock_id_length, ulonglong transaction_id,
210 ulonglong thread_id, ulonglong event_id, const char *table_schema,
211 size_t table_schema_length, const char *table_name,
212 size_t table_name_length, const char *partition_name,
213 size_t partition_name_length, const char *sub_partition_name,
214 size_t sub_partition_name_length, const char *index_name,
215 size_t index_name_length, const void *identity, const char *lock_mode,
216 const char *lock_type, const char *lock_status,
217 const char *lock_data) = 0;
218};
219
221 public:
224
225 /** @sa PSI_server_data_lock_container::cache_string. */
226 virtual const char *cache_string(const char *string) = 0;
227
228 /** @sa PSI_server_data_lock_container::cache_data. */
229 virtual const char *cache_data(const char *ptr, size_t length) = 0;
230
231 /**
232 Check if the container accepts data for a particular engine.
233 This methods is used to prune data for queries like
234 @code SELECT * from performance_schema.data_lock_waits WHERE ENGINE = ...
235 @endcode
236 */
237 virtual bool accept_engine(const char *engine, size_t engine_length) = 0;
238
239 /**
240 Check if the container accepts data for a particular requesting lock id.
241 This methods is used to prune data for queries like
242 @code SELECT * from performance_schema.data_lock_waits WHERE
243 REQUESTING_ENGINE_LOCK_ID = ... @endcode
244 */
245 virtual bool accept_requesting_lock_id(const char *engine_lock_id,
246 size_t engine_lock_id_length) = 0;
247
248 /**
249 Check if the container accepts data for a particular blocking lock id.
250 This methods is used to prune data for queries like
251 @code SELECT * from performance_schema.data_lock_waits WHERE
252 BLOCKING_ENGINE_LOCK_ID = ... @endcode
253 */
254 virtual bool accept_blocking_lock_id(const char *engine_lock_id,
255 size_t engine_lock_id_length) = 0;
256
257 /**
258 Check if the container accepts data for a particular requesting transaction
259 id.
260 This methods is used to prune data for queries like
261 @code SELECT * from performance_schema.data_lock_waits WHERE
262 REQUESTING_ENGINE_TRANSACTION_ID = ... @endcode
263 */
264 virtual bool accept_requesting_transaction_id(ulonglong transaction_id) = 0;
265
266 /**
267 Check if the container accepts data for a particular blocking transaction
268 id.
269 This methods is used to prune data for queries like
270 @code SELECT * from performance_schema.data_lock_waits WHERE
271 BLOCKING_ENGINE_TRANSACTION_ID = ... @endcode
272 */
273 virtual bool accept_blocking_transaction_id(ulonglong transaction_id) = 0;
274
275 /**
276 Check if the container accepts data for a particular requesting event.
277 This methods is used to prune data for queries like
278 @code SELECT * from performance_schema.data_lock_waits
279 WHERE REQUESTING_THREAD_ID = ... AND REQUESTING_EVENT_ID = ... @endcode
280 */
282 ulonglong event_id) = 0;
283
284 /**
285 Check if the container accepts data for a particular blocking event.
286 This methods is used to prune data for queries like
287 @code SELECT * from performance_schema.data_lock_waits
288 WHERE BLOCKING_THREAD_ID = ... AND BLOCKING_EVENT_ID = ... @endcode
289 */
291 ulonglong event_id) = 0;
292
293 /** Add a row to table performance_schema.data_lock_waits. */
294 virtual void add_lock_wait_row(
295 const char *engine, size_t engine_length,
296 const char *requesting_engine_lock_id,
297 size_t requesting_engine_lock_id_length,
298 ulonglong requesting_transaction_id, ulonglong requesting_thread_id,
299 ulonglong requesting_event_id, const void *requesting_identity,
300 const char *blocking_engine_lock_id,
301 size_t blocking_engine_lock_id_length, ulonglong blocking_transaction_id,
302 ulonglong blocking_thread_id, ulonglong blocking_event_id,
303 const void *blocking_identity) = 0;
304};
305
306/**
307 Engine interface, row lock iterator.
308 This is the interface exposed
309 - by a storage engine
310 - to the server
311 used to iterate over all the row locks
312 present within the storage engine tables.
313 The storage engine is to implement this interface.
314 The server is to call scan() to ask the storage
315 engine to add more rows to the container given.
316*/
318 public:
321
322 /**
323 Scan for more data locks.
324 @param container The container to fill
325 @param with_lock_data True if column LOCK_DATA is required.
326 @return true if the iterator is done
327 */
329 bool with_lock_data) = 0;
330
331 /**
332 Fetch a given data lock.
333 @param container The container to fill
334 @param engine_lock_id The lock id to search
335 @param engine_lock_id_length Lock id length
336 @param with_lock_data True if column LOCK_DATA is required.
337 @return true if the iterator is done
338 */
340 const char *engine_lock_id, size_t engine_lock_id_length,
341 bool with_lock_data) = 0;
342};
343
345 public:
348
349 /**
350 Scan for more data lock waits.
351 @param container The container to fill
352 @return true if the iterator is done
353 */
355
356 /**
357 Fetch a given data lock wait.
358 @param container The container to fill
359 @param requesting_engine_lock_id The requesting lock id to search
360 @param requesting_engine_lock_id_length The requesting lock id length
361 @param blocking_engine_lock_id The blocking lock id to search
362 @param blocking_engine_lock_id_length The blocking lock id length
363 @return true if the iterator is done
364 */
366 const char *requesting_engine_lock_id,
367 size_t requesting_engine_lock_id_length,
368 const char *blocking_engine_lock_id,
369 size_t blocking_engine_lock_id_length) = 0;
370};
371
372/**
373 Engine interface, row lock inspector.
374 This is the interface exposed
375 - by a storage engine
376 - to the server
377 to create an iterator over all row locks.
378 The storage engine is to implement this interface.
379 The server is to call create_iterator()
380 to ask the engine to create an iterator over all row locks.
381 A PSI_engine_data_lock_inspector is meant to be stateless,
382 and not associated to any opened table handle,
383 while the iterator created is meant to be stateful,
384 and dedicated to an opened performance_schema.row_locks table handle.
385*/
387 public:
390
391 /**
392 Create a data lock iterator.
393 The iterator returned is used to extract data_locks rows from the storage
394 engine.
395 @sa destroy_data_lock_iterator
396 */
398
399 /**
400 Create a data lock wait iterator.
401 The iterator returned is used to extract data_lock_waits rows from the
402 storage engine.
403 @sa destroy_data_lock_wait_iterator
404 */
407
408 /**
409 Destroy a data lock iterator.
410 */
413
414 /**
415 Destroy a data lock wait iterator.
416 */
419};
420
421/**
422 Row Lock registration API.
423*/
426
427/**
428 Row Lock un registration API.
429*/
432
433/**
434 Performance Schema Row Lock Interface, version 1.
435 @since PSI_DATA_LOCK_VERSION_1
436*/
440};
441
442#endif /* HAVE_PSI_DATA_LOCK_1 */
443
444/* Export the required version */
445#ifdef USE_PSI_DATA_LOCK_1
447#else
449#endif
450
452
453#endif /* HAVE_PSI_DATA_LOCK_INTERFACE */
454
455/** @} (end of group psi_abi_data_lock) */
456
457#endif /* MYSQL_PSI_DATA_LOCK_H */
Engine interface, row lock inspector.
Definition: psi_data_lock.h:386
virtual PSI_engine_data_lock_iterator * create_data_lock_iterator()=0
Create a data lock iterator.
virtual void destroy_data_lock_wait_iterator(PSI_engine_data_lock_wait_iterator *it)=0
Destroy a data lock wait iterator.
virtual ~PSI_engine_data_lock_inspector()=default
virtual PSI_engine_data_lock_wait_iterator * create_data_lock_wait_iterator()=0
Create a data lock wait iterator.
virtual void destroy_data_lock_iterator(PSI_engine_data_lock_iterator *it)=0
Destroy a data lock iterator.
Engine interface, row lock iterator.
Definition: psi_data_lock.h:317
virtual ~PSI_engine_data_lock_iterator()=default
virtual bool fetch(PSI_server_data_lock_container *container, const char *engine_lock_id, size_t engine_lock_id_length, bool with_lock_data)=0
Fetch a given data lock.
virtual bool scan(PSI_server_data_lock_container *container, bool with_lock_data)=0
Scan for more data locks.
Definition: psi_data_lock.h:344
virtual ~PSI_engine_data_lock_wait_iterator()=default
virtual bool scan(PSI_server_data_lock_wait_container *container)=0
Scan for more data lock waits.
virtual bool fetch(PSI_server_data_lock_wait_container *container, const char *requesting_engine_lock_id, size_t requesting_engine_lock_id_length, const char *blocking_engine_lock_id, size_t blocking_engine_lock_id_length)=0
Fetch a given data lock wait.
Server interface, row lock container.
Definition: psi_data_lock.h:117
virtual bool accept_thread_id_event_id(ulonglong thread_id, ulonglong event_id)=0
Check if the container accepts data for a particular event.
virtual void add_lock_row(const char *engine, size_t engine_length, const char *engine_lock_id, size_t engine_lock_id_length, ulonglong transaction_id, ulonglong thread_id, ulonglong event_id, const char *table_schema, size_t table_schema_length, const char *table_name, size_t table_name_length, const char *partition_name, size_t partition_name_length, const char *sub_partition_name, size_t sub_partition_name_length, const char *index_name, size_t index_name_length, const void *identity, const char *lock_mode, const char *lock_type, const char *lock_status, const char *lock_data)=0
Add a row to table performance_schema.data_locks.
virtual bool accept_lock_id(const char *engine_lock_id, size_t engine_lock_id_length)=0
Check if the container accepts data for a particular lock.
virtual void cache_identifier(PSI_identifier kind, const char *str, size_t length, const char **cached_ptr, size_t *cached_length)=0
Add an identifier in the container cache.
virtual bool accept_transaction_id(ulonglong transaction_id)=0
Check if the container accepts data for a particular transaction.
virtual ~PSI_server_data_lock_container()=default
virtual const char * cache_data(const char *ptr, size_t length)=0
Add binary data to the container cache.
virtual bool accept_engine(const char *engine, size_t engine_length)=0
Check if the container accepts data for a particular engine.
virtual bool accept_object(const char *table_schema, size_t table_schema_length, const char *table_name, size_t table_name_length, const char *partition_name, size_t partition_name_length, const char *sub_partition_name, size_t sub_partition_name_length)=0
Check if the container accepts data for a particular object.
virtual const char * cache_string(const char *string)=0
Add a string to the container cache.
Definition: psi_data_lock.h:220
virtual bool accept_requesting_lock_id(const char *engine_lock_id, size_t engine_lock_id_length)=0
Check if the container accepts data for a particular requesting lock id.
virtual bool accept_blocking_thread_id_event_id(ulonglong thread_id, ulonglong event_id)=0
Check if the container accepts data for a particular blocking event.
virtual const char * cache_string(const char *string)=0
virtual bool accept_blocking_lock_id(const char *engine_lock_id, size_t engine_lock_id_length)=0
Check if the container accepts data for a particular blocking lock id.
virtual bool accept_engine(const char *engine, size_t engine_length)=0
Check if the container accepts data for a particular engine.
virtual bool accept_requesting_thread_id_event_id(ulonglong thread_id, ulonglong event_id)=0
Check if the container accepts data for a particular requesting event.
virtual ~PSI_server_data_lock_wait_container()=default
virtual bool accept_requesting_transaction_id(ulonglong transaction_id)=0
Check if the container accepts data for a particular requesting transaction id.
virtual bool accept_blocking_transaction_id(ulonglong transaction_id)=0
Check if the container accepts data for a particular blocking transaction id.
virtual const char * cache_data(const char *ptr, size_t length)=0
virtual void add_lock_wait_row(const char *engine, size_t engine_length, const char *requesting_engine_lock_id, size_t requesting_engine_lock_id_length, ulonglong requesting_transaction_id, ulonglong requesting_thread_id, ulonglong requesting_event_id, const void *requesting_identity, const char *blocking_engine_lock_id, size_t blocking_engine_lock_id_length, ulonglong blocking_transaction_id, ulonglong blocking_thread_id, ulonglong blocking_event_id, const void *blocking_identity)=0
Add a row to table performance_schema.data_lock_waits.
PSI_identifier
Definition: psi_data_lock.h:97
MYSQL_PLUGIN_IMPORT PSI_data_lock_service_t * psi_data_lock_service
Definition: psi_noop.cc:973
void(* register_data_lock_v1_t)(PSI_engine_data_lock_inspector *inspector)
Row Lock registration API.
Definition: psi_data_lock.h:424
void(* unregister_data_lock_v1_t)(PSI_engine_data_lock_inspector *inspector)
Row Lock un registration API.
Definition: psi_data_lock.h:430
@ PSI_IDENTIFIER_PARTITION
Definition: psi_data_lock.h:102
@ PSI_IDENTIFIER_NONE
Definition: psi_data_lock.h:98
@ PSI_IDENTIFIER_SCHEMA
Definition: psi_data_lock.h:99
@ PSI_IDENTIFIER_TABLE
Definition: psi_data_lock.h:100
@ PSI_IDENTIFIER_SUBPARTITION
Definition: psi_data_lock.h:103
@ PSI_IDENTIFIER_INDEX
Definition: psi_data_lock.h:101
lock_mode
Definition: lock0types.h:52
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
Functions related to handling of plugins and other dynamically loaded libraries.
#define MYSQL_PLUGIN_IMPORT
Definition: my_sharedlib.h:71
static my_thread_id thread_id
Definition: my_thr_init.cc:63
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1052
Definition: atomics_array.h:39
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
const char * table_name
Definition: rules_table_service.cc:56
required uint64 version
Definition: replication_group_member_actions.proto:41
Entry point for the performance schema interface.
Definition: psi_data_lock.h:82
Performance Schema Row Lock Interface, version 1.
Definition: psi_data_lock.h:437
register_data_lock_v1_t register_data_lock
Definition: psi_data_lock.h:438
unregister_data_lock_v1_t unregister_data_lock
Definition: psi_data_lock.h:439
Definition: psi_bits.h:165