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