MySQL 9.1.0
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 <stddef.h>
37#include <stdint.h>
38#endif /* MYSQL_ABI_CHECK */
39
40#ifdef __cplusplus
41class THD;
42#define MYSQL_THD THD *
43#else
44#define MYSQL_THD void *
45#endif
46
47/**
48 Types of locking service locks.
49 LOCKING_SERVICE_READ is compatible with LOCKING_SERVICE_READ.
50 All other combinations are incompatible.
51*/
55};
56
57/**
58 Acquire locking service locks.
59
60 @param opaque_thd Thread handle. If NULL, current_thd will be used.
61 @param lock_namespace Namespace of the locks to acquire.
62 @param lock_names Array of names of the locks to acquire.
63 @param lock_num Number of elements in 'lock_names'.
64 @param lock_type Lock type to acquire. LOCKING_SERVICE_READ or _WRITE.
65 @param lock_timeout Number of seconds to wait before giving up.
66
67 @retval 1 Acquisition failed, error has been reported.
68 @retval 0 Acquisition successful, all locks acquired.
69
70 @note both lock_namespace and lock_names are limited to 64 characters max.
71 Names are compared using binary comparison.
72
73 @sa acquire_locking_service_locks, MDL_context::acquire_locks
74*/
75typedef int (*mysql_acquire_locks_t)(
76 MYSQL_THD opaque_thd, const char *lock_namespace, const char **lock_names,
77 size_t lock_num, enum enum_locking_service_lock_type lock_type,
78 uint64_t lock_timeout);
79
80/**
81 Release all lock service locks taken by the given connection
82 in the given namespace.
83
84 @param opaque_thd Thread handle. If NULL, current_thd will be used.
85 @param lock_namespace Namespace of the locks to release.
86
87 @retval 1 Release failed, error has been reported.
88 @retval 0 Release successful, all locks acquired.
89
90 @sa release_locking_service_locks, MDL_context::release_locks
91*/
92typedef int (*mysql_release_locks_t)(MYSQL_THD opaque_thd,
93 const char *lock_namespace);
94
95/**
96 @ingroup group_ext_plugin_services
97
98 This service provides support for taking read/write locks.
99 It is intended for use with fabric, but it is still a general
100 service. The locks are in a separate namespace from other
101 locks in the server, and there is also no interactions with
102 transactions (i.e. locks are not released on commit/abort).
103
104 These locks are implemented using the metadata lock (MDL) subsystem
105 and thus deadlocks involving locking service locks and other types
106 of metadata will be detected using the MDL deadlock detector.
107*/
108extern "C" struct mysql_locking_service_st {
112
113#ifdef MYSQL_DYNAMIC_PLUGIN
114
115#define mysql_acquire_locking_service_locks(_THD, _NAMESPACE, _NAMES, _NUM, \
116 _TYPE, _TIMEOUT) \
117 mysql_locking_service->mysql_acquire_locks(_THD, _NAMESPACE, _NAMES, _NUM, \
118 _TYPE, _TIMEOUT)
119#define mysql_release_locking_service_locks(_THD, _NAMESPACE) \
120 mysql_locking_service->mysql_release_locks(_THD, _NAMESPACE)
121
122#else
123
125 MYSQL_THD opaque_thd, const char *lock_namespace, const char **lock_names,
126 size_t lock_num, enum enum_locking_service_lock_type lock_type,
127 uint64_t lock_timeout);
128
130 const char *lock_namespace);
131
132#endif /* MYSQL_DYNAMIC_PLUGIN */
133
134#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:36
struct mysql_locking_service_st * mysql_locking_service
#define MYSQL_THD
Definition: service_locking.h:42
enum_locking_service_lock_type
Types of locking service locks.
Definition: service_locking.h:52
@ LOCKING_SERVICE_READ
Definition: service_locking.h:53
@ LOCKING_SERVICE_WRITE
Definition: service_locking.h:54
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:92
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:75
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:108
mysql_acquire_locks_t mysql_acquire_locks
Definition: service_locking.h:109
mysql_release_locks_t mysql_release_locks
Definition: service_locking.h:110