MySQL 8.0.40
Source Code Documentation
service_locking.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2015, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License, version 2.0, for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef SERVICE_LOCKING_INCLUDED
27#define SERVICE_LOCKING_INCLUDED
28
29/**
30 @file include/mysql/service_locking.h
31
32 Implements ::mysql_locking_service_st
33*/
34
35#ifndef MYSQL_ABI_CHECK
36#include <stdint.h>
37#endif /* MYSQL_ABI_CHECK */
38
39#ifdef __cplusplus
40class THD;
41#define MYSQL_THD THD *
42#else
43#define MYSQL_THD void *
44#endif
45
46/**
47 Types of locking service locks.
48 LOCKING_SERVICE_READ is compatible with LOCKING_SERVICE_READ.
49 All other combinations are incompatible.
50*/
54};
55
56/**
57 Acquire locking service locks.
58
59 @param opaque_thd Thread handle. If NULL, current_thd will be used.
60 @param lock_namespace Namespace of the locks to acquire.
61 @param lock_names Array of names of the locks to acquire.
62 @param lock_num Number of elements in 'lock_names'.
63 @param lock_type Lock type to acquire. LOCKING_SERVICE_READ or _WRITE.
64 @param lock_timeout Number of seconds to wait before giving up.
65
66 @retval 1 Acquisition failed, error has been reported.
67 @retval 0 Acquisition successful, all locks acquired.
68
69 @note both lock_namespace and lock_names are limited to 64 characters max.
70 Names are compared using binary comparison.
71
72 @sa acquire_locking_service_locks, MDL_context::acquire_locks
73*/
74typedef int (*mysql_acquire_locks_t)(
75 MYSQL_THD opaque_thd, const char *lock_namespace, const char **lock_names,
76 size_t lock_num, enum enum_locking_service_lock_type lock_type,
77 uint64_t lock_timeout);
78
79/**
80 Release all lock service locks taken by the given connection
81 in the given namespace.
82
83 @param opaque_thd Thread handle. If NULL, current_thd will be used.
84 @param lock_namespace Namespace of the locks to release.
85
86 @retval 1 Release failed, error has been reported.
87 @retval 0 Release successful, all locks acquired.
88
89 @sa release_locking_service_locks, MDL_context::release_locks
90*/
91typedef int (*mysql_release_locks_t)(MYSQL_THD opaque_thd,
92 const char *lock_namespace);
93
94/**
95 @ingroup group_ext_plugin_services
96
97 This service provides support for taking read/write locks.
98 It is intended for use with fabric, but it is still a general
99 service. The locks are in a separate namespace from other
100 locks in the server, and there is also no interactions with
101 transactions (i.e. locks are not released on commit/abort).
102
103 These locks are implemented using the metadata lock (MDL) subsystem
104 and thus deadlocks involving locking service locks and other types
105 of metadata will be detected using the MDL deadlock detector.
106*/
107extern "C" struct mysql_locking_service_st {
111
112#ifdef MYSQL_DYNAMIC_PLUGIN
113
114#define mysql_acquire_locking_service_locks(_THD, _NAMESPACE, _NAMES, _NUM, \
115 _TYPE, _TIMEOUT) \
116 mysql_locking_service->mysql_acquire_locks(_THD, _NAMESPACE, _NAMES, _NUM, \
117 _TYPE, _TIMEOUT)
118#define mysql_release_locking_service_locks(_THD, _NAMESPACE) \
119 mysql_locking_service->mysql_release_locks(_THD, _NAMESPACE)
120
121#else
122
124 MYSQL_THD opaque_thd, const char *lock_namespace, const char **lock_names,
125 size_t lock_num, enum enum_locking_service_lock_type lock_type,
126 uint64_t lock_timeout);
127
129 const char *lock_namespace);
130
131#endif /* MYSQL_DYNAMIC_PLUGIN */
132
133#endif /* SERVICE_LOCKING_INCLUDED */
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
struct mysql_locking_service_st * mysql_locking_service
#define MYSQL_THD
Definition: service_locking.h:41
enum_locking_service_lock_type
Types of locking service locks.
Definition: service_locking.h:51
@ LOCKING_SERVICE_READ
Definition: service_locking.h:52
@ LOCKING_SERVICE_WRITE
Definition: service_locking.h:53
int(* mysql_release_locks_t)(MYSQL_THD opaque_thd, const char *lock_namespace)
Release all lock service locks taken by the given connection in the given namespace.
Definition: service_locking.h:91
int mysql_acquire_locking_service_locks(MYSQL_THD opaque_thd, const char *lock_namespace, const char **lock_names, size_t lock_num, enum enum_locking_service_lock_type lock_type, uint64_t lock_timeout)
int(* mysql_acquire_locks_t)(MYSQL_THD opaque_thd, const char *lock_namespace, const char **lock_names, size_t lock_num, enum enum_locking_service_lock_type lock_type, uint64_t lock_timeout)
Acquire locking service locks.
Definition: service_locking.h:74
int mysql_release_locking_service_locks(MYSQL_THD opaque_thd, const char *lock_namespace)
Definition: locking_service.cc:186
This service provides support for taking read/write locks.
Definition: service_locking.h:107
mysql_acquire_locks_t mysql_acquire_locks
Definition: service_locking.h:108
mysql_release_locks_t mysql_release_locks
Definition: service_locking.h:109