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