MySQL  8.0.27
Source Code Documentation
psi_data_lock.h
Go to the documentation of this file.
1 /* Copyright (c) 2016, 2021, 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 
96 /**
97  Server interface, row lock container.
98  This is the interface exposed
99  - by the server
100  - to the storage engines
101  used to collect the data for table DATA_LOCKS.
102  The server is to implement this interface.
103  The storage engine is to call all_lock_row()
104  to advertise row locks that exists within
105  the storage engine tables.
106 */
108  public:
110  virtual ~PSI_server_data_lock_container() = default;
111 
112  /**
113  Add a string to the container cache.
114  Cached strings have the same life cycle as the data container,
115  and are freed when the container is destroyed.
116  Also, duplicated strings value are cached with the same copy,
117  avoiding memory duplication.
118  This is useful in particular to cache table schema or table names,
119  which are duplicated a lot for different row locks on the same table.
120  */
121  virtual const char *cache_string(const char *string) = 0;
122  /**
123  Add binary data to the container cache.
124  @sa cache_string
125  */
126  virtual const char *cache_data(const char *ptr, size_t length) = 0;
127 
128  /**
129  Check if the container accepts data for a particular engine.
130  This methods is used to prune data for queries like
131  @code SELECT * from performance_schema.data_locks WHERE ENGINE = ...
132  @endcode
133  */
134  virtual bool accept_engine(const char *engine, size_t engine_length) = 0;
135 
136  /**
137  Check if the container accepts data for a particular lock.
138  This methods is used to prune data for queries like
139  @code SELECT * from performance_schema.data_locks WHERE ENGINE_LOCK_ID = ...
140  @endcode
141  */
142  virtual bool accept_lock_id(const char *engine_lock_id,
143  size_t engine_lock_id_length) = 0;
144 
145  /**
146  Check if the container accepts data for a particular transaction.
147  This methods is used to prune data for queries like
148  @code SELECT * from performance_schema.data_locks WHERE
149  ENGINE_TRANSACTION_ID = ... @endcode
150  */
151  virtual bool accept_transaction_id(ulonglong transaction_id) = 0;
152 
153  /**
154  Check if the container accepts data for a particular event.
155  This methods is used to prune data for queries like
156  @code SELECT * from performance_schema.data_locks
157  WHERE THREAD_ID = ... AND EVENT_ID = ... @endcode
158  */
160  ulonglong event_id) = 0;
161 
162  /**
163  Check if the container accepts data for a particular object.
164  This methods is used to prune data for queries like
165  @code SELECT * from performance_schema.data_locks
166  WHERE OBJECT_SCHEMA = ...
167  AND OBJECT_NAME = ...
168  AND PARTITION_NAME = ...
169  AND SUBPARTITION_NAME = ... @endcode
170  */
171  virtual bool accept_object(const char *table_schema,
172  size_t table_schema_length, const char *table_name,
173  size_t table_name_length,
174  const char *partition_name,
175  size_t partition_name_length,
176  const char *sub_partition_name,
177  size_t sub_partition_name_length) = 0;
178 
179  /** Add a row to table performance_schema.data_locks. */
180  virtual void add_lock_row(
181  const char *engine, size_t engine_length, const char *engine_lock_id,
182  size_t engine_lock_id_length, ulonglong transaction_id,
183  ulonglong thread_id, ulonglong event_id, const char *table_schema,
184  size_t table_schema_length, const char *table_name,
185  size_t table_name_length, const char *partition_name,
186  size_t partition_name_length, const char *sub_partition_name,
187  size_t sub_partition_name_length, const char *index_name,
188  size_t index_name_length, const void *identity, const char *lock_mode,
189  const char *lock_type, const char *lock_status,
190  const char *lock_data) = 0;
191 };
192 
194  public:
197 
198  /** @sa PSI_server_data_lock_container::cache_string. */
199  virtual const char *cache_string(const char *string) = 0;
200 
201  /** @sa PSI_server_data_lock_container::cache_data. */
202  virtual const char *cache_data(const char *ptr, size_t length) = 0;
203 
204  /**
205  Check if the container accepts data for a particular engine.
206  This methods is used to prune data for queries like
207  @code SELECT * from performance_schema.data_lock_waits WHERE ENGINE = ...
208  @endcode
209  */
210  virtual bool accept_engine(const char *engine, size_t engine_length) = 0;
211 
212  /**
213  Check if the container accepts data for a particular requesting lock id.
214  This methods is used to prune data for queries like
215  @code SELECT * from performance_schema.data_lock_waits WHERE
216  REQUESTING_ENGINE_LOCK_ID = ... @endcode
217  */
218  virtual bool accept_requesting_lock_id(const char *engine_lock_id,
219  size_t engine_lock_id_length) = 0;
220 
221  /**
222  Check if the container accepts data for a particular blocking lock id.
223  This methods is used to prune data for queries like
224  @code SELECT * from performance_schema.data_lock_waits WHERE
225  BLOCKING_ENGINE_LOCK_ID = ... @endcode
226  */
227  virtual bool accept_blocking_lock_id(const char *engine_lock_id,
228  size_t engine_lock_id_length) = 0;
229 
230  /**
231  Check if the container accepts data for a particular requesting transaction
232  id.
233  This methods is used to prune data for queries like
234  @code SELECT * from performance_schema.data_lock_waits WHERE
235  REQUESTING_ENGINE_TRANSACTION_ID = ... @endcode
236  */
237  virtual bool accept_requesting_transaction_id(ulonglong transaction_id) = 0;
238 
239  /**
240  Check if the container accepts data for a particular blocking transaction
241  id.
242  This methods is used to prune data for queries like
243  @code SELECT * from performance_schema.data_lock_waits WHERE
244  BLOCKING_ENGINE_TRANSACTION_ID = ... @endcode
245  */
246  virtual bool accept_blocking_transaction_id(ulonglong transaction_id) = 0;
247 
248  /**
249  Check if the container accepts data for a particular requesting event.
250  This methods is used to prune data for queries like
251  @code SELECT * from performance_schema.data_lock_waits
252  WHERE REQUESTING_THREAD_ID = ... AND REQUESTING_EVENT_ID = ... @endcode
253  */
255  ulonglong event_id) = 0;
256 
257  /**
258  Check if the container accepts data for a particular blocking event.
259  This methods is used to prune data for queries like
260  @code SELECT * from performance_schema.data_lock_waits
261  WHERE BLOCKING_THREAD_ID = ... AND BLOCKING_EVENT_ID = ... @endcode
262  */
264  ulonglong event_id) = 0;
265 
266  /** Add a row to table performance_schema.data_lock_waits. */
267  virtual void add_lock_wait_row(
268  const char *engine, size_t engine_length,
269  const char *requesting_engine_lock_id,
270  size_t requesting_engine_lock_id_length,
271  ulonglong requesting_transaction_id, ulonglong requesting_thread_id,
272  ulonglong requesting_event_id, const void *requesting_identity,
273  const char *blocking_engine_lock_id,
274  size_t blocking_engine_lock_id_length, ulonglong blocking_transaction_id,
275  ulonglong blocking_thread_id, ulonglong blocking_event_id,
276  const void *blocking_identity) = 0;
277 };
278 
279 /**
280  Engine interface, row lock iterator.
281  This is the interface exposed
282  - by a storage engine
283  - to the server
284  used to iterate over all the row locks
285  present within the storage engine tables.
286  The storage engine is to implement this interface.
287  The server is to call scan() to ask the storage
288  engine to add more rows to the container given.
289 */
291  public:
293  virtual ~PSI_engine_data_lock_iterator() = default;
294 
295  /**
296  Scan for more data locks.
297  @param container The container to fill
298  @param with_lock_data True if column LOCK_DATA is required.
299  @return true if the iterator is done
300  */
302  bool with_lock_data) = 0;
303 
304  /**
305  Fetch a given data lock.
306  @param container The container to fill
307  @param engine_lock_id The lock id to search
308  @param engine_lock_id_length Lock id length
309  @param with_lock_data True if column LOCK_DATA is required.
310  @return true if the iterator is done
311  */
313  const char *engine_lock_id, size_t engine_lock_id_length,
314  bool with_lock_data) = 0;
315 };
316 
318  public:
321 
322  /**
323  Scan for more data lock waits.
324  @param container The container to fill
325  @return true if the iterator is done
326  */
328 
329  /**
330  Fetch a given data lock wait.
331  @param container The container to fill
332  @param requesting_engine_lock_id The requesting lock id to search
333  @param requesting_engine_lock_id_length The requesting lock id length
334  @param blocking_engine_lock_id The blocking lock id to search
335  @param blocking_engine_lock_id_length The blocking lock id length
336  @return true if the iterator is done
337  */
339  const char *requesting_engine_lock_id,
340  size_t requesting_engine_lock_id_length,
341  const char *blocking_engine_lock_id,
342  size_t blocking_engine_lock_id_length) = 0;
343 };
344 
345 /**
346  Engine interface, row lock inspector.
347  This is the interface exposed
348  - by a storage engine
349  - to the server
350  to create an iterator over all row locks.
351  The storage engine is to implement this interface.
352  The server is to call create_iterator()
353  to ask the engine to create an iterator over all row locks.
354  A PSI_engine_data_lock_inspector is meant to be stateless,
355  and not associated to any opened table handle,
356  while the iterator created is meant to be stateful,
357  and dedicated to an opened performance_schema.row_locks table handle.
358 */
360  public:
362  virtual ~PSI_engine_data_lock_inspector() = default;
363 
364  /**
365  Create a data lock iterator.
366  The iterator returned is used to extract data_locks rows from the storage
367  engine.
368  @sa destroy_data_lock_iterator
369  */
371 
372  /**
373  Create a data lock wait iterator.
374  The iterator returned is used to extract data_lock_waits rows from the
375  storage engine.
376  @sa destroy_data_lock_wait_iterator
377  */
380 
381  /**
382  Destroy a data lock iterator.
383  */
386 
387  /**
388  Destroy a data lock wait iterator.
389  */
392 };
393 
394 /**
395  Row Lock registration API.
396 */
397 typedef void (*register_data_lock_v1_t)(
398  PSI_engine_data_lock_inspector *inspector);
399 
400 /**
401  Row Lock un registration API.
402 */
404  PSI_engine_data_lock_inspector *inspector);
405 
406 /**
407  Performance Schema Row Lock Interface, version 1.
408  @since PSI_DATA_LOCK_VERSION_1
409 */
413 };
414 
415 #endif /* HAVE_PSI_DATA_LOCK_1 */
416 
417 /* Export the required version */
418 #ifdef USE_PSI_DATA_LOCK_1
420 #else
422 #endif
423 
425 
426 #endif /* HAVE_PSI_DATA_LOCK_INTERFACE */
427 
428 /** @} (end of group psi_abi_data_lock) */
429 
430 #endif /* MYSQL_PSI_DATA_LOCK_H */
Engine interface, row lock inspector.
Definition: psi_data_lock.h:359
virtual PSI_engine_data_lock_wait_iterator * create_data_lock_wait_iterator()=0
Create a data lock wait iterator.
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 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:290
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:317
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:107
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 const char * cache_data(const char *ptr, size_t length)=0
Add binary data to the container cache.
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 bool accept_transaction_id(ulonglong transaction_id)=0
Check if the container accepts data for a particular transaction.
virtual const char * cache_string(const char *string)=0
Add a string to the container cache.
virtual ~PSI_server_data_lock_container()=default
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.
Definition: psi_data_lock.h:193
virtual const char * cache_string(const char *string)=0
virtual const char * cache_data(const char *ptr, size_t length)=0
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 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 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.
MYSQL_PLUGIN_IMPORT PSI_data_lock_service_t * psi_data_lock_service
Definition: psi_noop.cc:940
void(* register_data_lock_v1_t)(PSI_engine_data_lock_inspector *inspector)
Row Lock registration API.
Definition: psi_data_lock.h:397
void(* unregister_data_lock_v1_t)(PSI_engine_data_lock_inspector *inspector)
Row Lock un registration API.
Definition: psi_data_lock.h:403
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
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:410
register_data_lock_v1_t register_data_lock
Definition: psi_data_lock.h:411
unregister_data_lock_v1_t unregister_data_lock
Definition: psi_data_lock.h:412
Definition: psi_bits.h:149