MySQL  8.0.17
Source Code Documentation
psi_data_lock.h
Go to the documentation of this file.
1 /* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
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 #include "psi_base.h"
38 
39 #ifdef HAVE_PSI_DATA_LOCK_INTERFACE
40 
41 /**
42  @def PSI_DATA_LOCK_VERSION_1
43  Performance Schema Row Lock Interface number for version 1.
44  This version is supported.
45 */
46 #define PSI_DATA_LOCK_VERSION_1 1
47 
48 /**
49  @def PSI_DATA_LOCK_VERSION_2
50  Performance Schema Row Lock Interface number for version 2.
51  This version is not implemented, it's a placeholder.
52 */
53 #define PSI_DATA_LOCK_VERSION_2 2
54 
55 /**
56  @def PSI_CURRENT_DATA_LOCK_VERSION
57  Performance Schema Row Lock Interface number for the most recent version.
58  The most current version is @c PSI_DATA_LOCK_VERSION_1
59 */
60 #define PSI_CURRENT_DATA_LOCK_VERSION 1
61 
62 #ifndef USE_PSI_DATA_LOCK_2
63 #ifndef USE_PSI_DATA_LOCK_1
64 #ifdef __cplusplus
65 #define USE_PSI_DATA_LOCK_1
66 #endif /* __cplusplus */
67 #endif /* USE_PSI_DATA_LOCK_1 */
68 #endif /* USE_PSI_DATA_LOCK_2 */
69 
70 #ifdef USE_PSI_DATA_LOCK_1
71 #define HAVE_PSI_DATA_LOCK_1
72 #endif /* USE_PSI_DATA_LOCK_1 */
73 
74 #ifdef USE_PSI_DATA_LOCK_2
75 #define HAVE_PSI_DATA_LOCK_2
76 #endif
77 
78 /** Entry point for the performance schema interface. */
80  /**
81  ABI interface finder.
82  Calling this method with an interface version number returns either
83  an instance of the ABI for this version, or NULL.
84  @sa PSI_DATA_LOCK_VERSION_1
85  @sa PSI_DATA_LOCK_VERSION_2
86  @sa PSI_CURRENT_DATA_LOCK_VERSION
87  */
88  void *(*get_interface)(int version);
89 };
91 
92 #ifdef HAVE_PSI_DATA_LOCK_1
93 
94 /**
95  Server interface, row lock container.
96  This is the interface exposed
97  - by the server
98  - to the storage engines
99  used to collect the data for table DATA_LOCKS.
100  The server is to implement this interface.
101  The storage engine is to call all_lock_row()
102  to advertise row locks that exists within
103  the storage engine tables.
104 */
106  public:
109 
110  /**
111  Add a string to the container cache.
112  Cached strings have the same life cycle as the data container,
113  and are freed when the container is destroyed.
114  Also, duplicated strings value are cached with the same copy,
115  avoiding memory duplication.
116  This is useful in particular to cache table schema or table names,
117  which are duplicated a lot for different row locks on the same table.
118  */
119  virtual const char *cache_string(const char *string) = 0;
120  /**
121  Add binary data to the container cache.
122  @sa cache_string
123  */
124  virtual const char *cache_data(const char *ptr, size_t length) = 0;
125 
126  /**
127  Check if the container accepts data for a particular engine.
128  This methods is used to prune data for queries like
129  @code SELECT * from performance_schema.data_locks WHERE ENGINE = ...
130  @endcode
131  */
132  virtual bool accept_engine(const char *engine, size_t engine_length) = 0;
133 
134  /**
135  Check if the container accepts data for a particular lock.
136  This methods is used to prune data for queries like
137  @code SELECT * from performance_schema.data_locks WHERE ENGINE_LOCK_ID = ...
138  @endcode
139  */
140  virtual bool accept_lock_id(const char *engine_lock_id,
141  size_t engine_lock_id_length) = 0;
142 
143  /**
144  Check if the container accepts data for a particular transaction.
145  This methods is used to prune data for queries like
146  @code SELECT * from performance_schema.data_locks WHERE
147  ENGINE_TRANSACTION_ID = ... @endcode
148  */
149  virtual bool accept_transaction_id(ulonglong transaction_id) = 0;
150 
151  /**
152  Check if the container accepts data for a particular event.
153  This methods is used to prune data for queries like
154  @code SELECT * from performance_schema.data_locks
155  WHERE THREAD_ID = ... AND EVENT_ID = ... @endcode
156  */
158  ulonglong event_id) = 0;
159 
160  /**
161  Check if the container accepts data for a particular object.
162  This methods is used to prune data for queries like
163  @code SELECT * from performance_schema.data_locks
164  WHERE OBJECT_SCHEMA = ...
165  AND OBJECT_NAME = ...
166  AND PARTITION_NAME = ...
167  AND SUBPARTITION_NAME = ... @endcode
168  */
169  virtual bool accept_object(const char *table_schema,
170  size_t table_schema_length, const char *table_name,
171  size_t table_name_length,
172  const char *partition_name,
173  size_t partition_name_length,
174  const char *sub_partition_name,
175  size_t sub_partition_name_length) = 0;
176 
177  /** Add a row to table performance_schema.data_locks. */
178  virtual void add_lock_row(
179  const char *engine, size_t engine_length, const char *engine_lock_id,
180  size_t engine_lock_id_length, ulonglong transaction_id,
181  ulonglong thread_id, ulonglong event_id, const char *table_schema,
182  size_t table_schema_length, const char *table_name,
183  size_t table_name_length, const char *partition_name,
184  size_t partition_name_length, const char *sub_partition_name,
185  size_t sub_partition_name_length, const char *index_name,
186  size_t index_name_length, const void *identity, const char *lock_mode,
187  const char *lock_type, const char *lock_status,
188  const char *lock_data) = 0;
189 };
190 
192  public:
195 
196  /** @sa PSI_server_data_lock_container::cache_string. */
197  virtual const char *cache_string(const char *string) = 0;
198 
199  /** @sa PSI_server_data_lock_container::cache_data. */
200  virtual const char *cache_data(const char *ptr, size_t length) = 0;
201 
202  /**
203  Check if the container accepts data for a particular engine.
204  This methods is used to prune data for queries like
205  @code SELECT * from performance_schema.data_lock_waits WHERE ENGINE = ...
206  @endcode
207  */
208  virtual bool accept_engine(const char *engine, size_t engine_length) = 0;
209 
210  /**
211  Check if the container accepts data for a particular requesting lock id.
212  This methods is used to prune data for queries like
213  @code SELECT * from performance_schema.data_lock_waits WHERE
214  REQUESTING_ENGINE_LOCK_ID = ... @endcode
215  */
216  virtual bool accept_requesting_lock_id(const char *engine_lock_id,
217  size_t engine_lock_id_length) = 0;
218 
219  /**
220  Check if the container accepts data for a particular blocking lock id.
221  This methods is used to prune data for queries like
222  @code SELECT * from performance_schema.data_lock_waits WHERE
223  BLOCKING_ENGINE_LOCK_ID = ... @endcode
224  */
225  virtual bool accept_blocking_lock_id(const char *engine_lock_id,
226  size_t engine_lock_id_length) = 0;
227 
228  /**
229  Check if the container accepts data for a particular requesting transaction
230  id.
231  This methods is used to prune data for queries like
232  @code SELECT * from performance_schema.data_lock_waits WHERE
233  REQUESTING_ENGINE_TRANSACTION_ID = ... @endcode
234  */
235  virtual bool accept_requesting_transaction_id(ulonglong transaction_id) = 0;
236 
237  /**
238  Check if the container accepts data for a particular blocking transaction
239  id.
240  This methods is used to prune data for queries like
241  @code SELECT * from performance_schema.data_lock_waits WHERE
242  BLOCKING_ENGINE_TRANSACTION_ID = ... @endcode
243  */
244  virtual bool accept_blocking_transaction_id(ulonglong transaction_id) = 0;
245 
246  /**
247  Check if the container accepts data for a particular requesting event.
248  This methods is used to prune data for queries like
249  @code SELECT * from performance_schema.data_lock_waits
250  WHERE REQUESTING_THREAD_ID = ... AND REQUESTING_EVENT_ID = ... @endcode
251  */
253  ulonglong event_id) = 0;
254 
255  /**
256  Check if the container accepts data for a particular blocking event.
257  This methods is used to prune data for queries like
258  @code SELECT * from performance_schema.data_lock_waits
259  WHERE BLOCKING_THREAD_ID = ... AND BLOCKING_EVENT_ID = ... @endcode
260  */
262  ulonglong event_id) = 0;
263 
264  /** Add a row to table performance_schema.data_lock_waits. */
265  virtual void add_lock_wait_row(
266  const char *engine, size_t engine_length,
267  const char *requesting_engine_lock_id,
268  size_t requesting_engine_lock_id_length,
269  ulonglong requesting_transaction_id, ulonglong requesting_thread_id,
270  ulonglong requesting_event_id, const void *requesting_identity,
271  const char *blocking_engine_lock_id,
272  size_t blocking_engine_lock_id_length, ulonglong blocking_transaction_id,
273  ulonglong blocking_thread_id, ulonglong blocking_event_id,
274  const void *blocking_identity) = 0;
275 };
276 
277 /**
278  Engine interface, row lock iterator.
279  This is the interface exposed
280  - by a storage engine
281  - to the server
282  used to iterate over all the row locks
283  present within the storage engine tables.
284  The storage engine is to implement this interface.
285  The server is to call scan() to ask the storage
286  engine to add more rows to the container given.
287 */
289  public:
292 
293  /**
294  Scan for more data locks.
295  @param container The container to fill
296  @param with_lock_data True if column LOCK_DATA is required.
297  @return true if the iterator is done
298  */
300  bool with_lock_data) = 0;
301 
302  /**
303  Fetch a given data lock.
304  @param container The container to fill
305  @param engine_lock_id The lock id to search
306  @param engine_lock_id_length Lock id length
307  @param with_lock_data True if column LOCK_DATA is required.
308  @return true if the iterator is done
309  */
311  const char *engine_lock_id, size_t engine_lock_id_length,
312  bool with_lock_data) = 0;
313 };
314 
316  public:
319 
320  /**
321  Scan for more data lock waits.
322  @param container The container to fill
323  @return true if the iterator is done
324  */
326 
327  /**
328  Fetch a given data lock wait.
329  @param container The container to fill
330  @param requesting_engine_lock_id The requesting lock id to search
331  @param requesting_engine_lock_id_length The requesting lock id length
332  @param blocking_engine_lock_id The blocking lock id to search
333  @param blocking_engine_lock_id_length The blocking lock id length
334  @return true if the iterator is done
335  */
337  const char *requesting_engine_lock_id,
338  size_t requesting_engine_lock_id_length,
339  const char *blocking_engine_lock_id,
340  size_t blocking_engine_lock_id_length) = 0;
341 };
342 
343 /**
344  Engine interface, row lock inspector.
345  This is the interface exposed
346  - by a storage engine
347  - to the server
348  to create an iterator over all row locks.
349  The storage engine is to implement this interface.
350  The server is to call create_iterator()
351  to ask the engine to create an iterator over all row locks.
352  A PSI_engine_data_lock_inspector is meant to be stateless,
353  and not associated to any opened table handle,
354  while the iterator created is meant to be stateful,
355  and dedicated to an opened performance_schema.row_locks table handle.
356 */
358  public:
361 
362  /**
363  Create a data lock iterator.
364  The iterator returned is used to extract data_locks rows from the storage
365  engine.
366  @sa destroy_data_lock_iterator
367  */
369 
370  /**
371  Create a data lock wait iterator.
372  The iterator returned is used to extract data_lock_waits rows from the
373  storage engine.
374  @sa destroy_data_lock_wait_iterator
375  */
378 
379  /**
380  Destroy a data lock iterator.
381  */
382  virtual void destroy_data_lock_iterator(
384 
385  /**
386  Destroy a data lock wait iterator.
387  */
388  virtual void destroy_data_lock_wait_iterator(
390 };
391 
392 /**
393  Row Lock registration API.
394 */
395 typedef void (*register_data_lock_v1_t)(
396  PSI_engine_data_lock_inspector *inspector);
397 
398 /**
399  Row Lock un registration API.
400 */
402  PSI_engine_data_lock_inspector *inspector);
403 
404 /**
405  Performance Schema Row Lock Interface, version 1.
406  @since PSI_DATA_LOCK_VERSION_1
407 */
411 };
412 
413 #endif /* HAVE_PSI_DATA_LOCK_1 */
414 
415 /* Export the required version */
416 #ifdef USE_PSI_DATA_LOCK_1
418 #else
420 #endif
421 
423 
424 #endif /* HAVE_PSI_DATA_LOCK_INTERFACE */
425 
426 /** @} (end of group psi_abi_data_lock) */
427 
428 #endif /* MYSQL_PSI_DATA_LOCK_H */
PSI_engine_data_lock_iterator()
Definition: psi_data_lock.h:290
void(* register_data_lock_v1_t)(PSI_engine_data_lock_inspector *inspector)
Row Lock registration API.
Definition: psi_data_lock.h:395
unsigned long long int ulonglong
Definition: my_inttypes.h:74
Definition: psi_base.h:125
ENGINE_HANDLE * engine
Definition: mock_server.c:28
virtual ~PSI_engine_data_lock_wait_iterator()
Definition: psi_data_lock.h:318
unregister_data_lock_v1_t unregister_data_lock
Definition: psi_data_lock.h:410
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.
Some integer typedefs for easier portability.
#define MYSQL_PLUGIN_IMPORT
Definition: my_sharedlib.h:70
virtual PSI_engine_data_lock_wait_iterator * create_data_lock_wait_iterator()=0
Create a data lock wait iterator.
virtual bool accept_engine(const char *engine, size_t engine_length)=0
Check if the container accepts data for a particular engine.
virtual bool scan(PSI_server_data_lock_container *container, bool with_lock_data)=0
Scan for more data locks.
Server interface, row lock container.
Definition: psi_data_lock.h:105
virtual void destroy_data_lock_wait_iterator(PSI_engine_data_lock_wait_iterator *it)=0
Destroy a data lock wait iterator.
virtual const char * cache_string(const char *string)=0
Definition: psi_data_lock.h:315
virtual ~PSI_engine_data_lock_iterator()
Definition: psi_data_lock.h:291
Performance Schema Row Lock Interface, version 1.
Definition: psi_data_lock.h:408
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.
Functions related to handling of plugins and other dynamically loaded libraries.
Performance schema instrumentation interface.
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_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.
Engine interface, row lock inspector.
Definition: psi_data_lock.h:357
virtual bool accept_requesting_transaction_id(ulonglong transaction_id)=0
Check if the container accepts data for a particular requesting transaction id.
virtual const char * cache_string(const char *string)=0
Add a string to the container cache.
void(* unregister_data_lock_v1_t)(PSI_engine_data_lock_inspector *inspector)
Row Lock un registration API.
Definition: psi_data_lock.h:401
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_data(const char *ptr, size_t length)=0
PSI_engine_data_lock_wait_iterator()
Definition: psi_data_lock.h:317
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.
Engine interface, row lock iterator.
Definition: psi_data_lock.h:288
virtual const char * cache_data(const char *ptr, size_t length)=0
Add binary data to the container cache.
MYSQL_PLUGIN_IMPORT PSI_data_lock_service_t * psi_data_lock_service
Definition: psi_noop.cc:923
virtual bool accept_engine(const char *engine, size_t engine_length)=0
Check if the container accepts data for a particular engine.
PSI_server_data_lock_wait_container()
Definition: psi_data_lock.h:193
const string version("\ersion\)
virtual ~PSI_server_data_lock_container()
Definition: psi_data_lock.h:108
virtual bool accept_transaction_id(ulonglong transaction_id)=0
Check if the container accepts data for a particular transaction.
virtual ~PSI_server_data_lock_wait_container()
Definition: psi_data_lock.h:194
Entry point for the performance schema interface.
Definition: psi_data_lock.h:79
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 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_thread_id_event_id(ulonglong thread_id, ulonglong event_id)=0
Check if the container accepts data for a particular event.
virtual void destroy_data_lock_iterator(PSI_engine_data_lock_iterator *it)=0
Destroy a data lock iterator.
Definition: psi_data_lock.h:191
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.
PSI_server_data_lock_container()
Definition: psi_data_lock.h:107
container
Following are enums defining column IDs indexing into each of three system tables.
Definition: innodb_config.h:78
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 ~PSI_engine_data_lock_inspector()
Definition: psi_data_lock.h:360
virtual PSI_engine_data_lock_iterator * create_data_lock_iterator()=0
Create a data lock iterator.
PSI_engine_data_lock_inspector()
Definition: psi_data_lock.h:359
lock_mode
Definition: lock0types.h:51
virtual bool accept_blocking_transaction_id(ulonglong transaction_id)=0
Check if the container accepts data for a particular blocking transaction id.
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
static my_thread_id thread_id
Definition: my_thr_init.cc:62
virtual bool scan(PSI_server_data_lock_wait_container *container)=0
Scan for more data lock waits.
register_data_lock_v1_t register_data_lock
Definition: psi_data_lock.h:409
const char * table_name
Definition: rules_table_service.cc:55