MySQL  8.0.18
Source Code Documentation
service_locking.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
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
39 class 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 typedef int (*mysql_acquire_locks_t)(
56  MYSQL_THD opaque_thd, const char *lock_namespace, const char **lock_names,
57  size_t lock_num, enum enum_locking_service_lock_type lock_type,
58  uint64_t lock_timeout);
59 
60 typedef int (*mysql_release_locks_t)(MYSQL_THD opaque_thd,
61  const char *lock_namespace);
62 
63 /**
64  @ingroup group_ext_plugin_services
65 
66  This service provides support for taking read/write locks.
67  It is intended for use with fabric, but it is still a general
68  service. The locks are in a separate namespace from other
69  locks in the server, and there is also no interactions with
70  transactions (i.e. locks are not released on commit/abort).
71 
72  These locks are implemented using the metadata lock (MDL) subsystem
73  and thus deadlocks involving locking service locks and other types
74  of metadata will be detected using the MDL deadlock detector.
75 */
76 extern "C" struct mysql_locking_service_st {
77  /**
78  Acquire locking service locks.
79 
80  @param opaque_thd Thread handle. If NULL, current_thd will be used.
81  @param lock_namespace Namespace of the locks to acquire.
82  @param lock_names Array of names of the locks to acquire.
83  @param lock_num Number of elements in 'lock_names'.
84  @param lock_type Lock type to acquire. LOCKING_SERVICE_READ or _WRITE.
85  @param lock_timeout Number of seconds to wait before giving up.
86 
87  @retval 1 Acquisition failed, error has been reported.
88  @retval 0 Acquisition successful, all locks acquired.
89 
90  @note both lock_namespace and lock_names are limited to 64 characters max.
91  Names are compared using binary comparison.
92 
93  @sa acquire_locking_service_locks, MDL_context::acquire_locks
94  */
96  /**
97  Release all lock service locks taken by the given connection
98  in the given namespace.
99 
100  @param opaque_thd Thread handle. If NULL, current_thd will be used.
101  @param lock_namespace Namespace of the locks to release.
102 
103  @retval 1 Release failed, error has been reported.
104  @retval 0 Release successful, all locks acquired.
105 
106  @sa release_locking_service_locks, MDL_context::release_locks
107  */
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 */
#define MYSQL_THD
Definition: service_locking.h:40
Definition: service_locking.h:51
Definition: service_locking.h:52
int(* mysql_release_locks_t)(MYSQL_THD opaque_thd, const char *lock_namespace)
Definition: service_locking.h:60
mysql_acquire_locks_t mysql_acquire_locks
Acquire locking service locks.
Definition: service_locking.h:95
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)
Definition: service_locking.h:55
enum_locking_service_lock_type
Types of locking service locks.
Definition: service_locking.h:50
mysql_release_locks_t mysql_release_locks
Release all lock service locks taken by the given connection in the given namespace.
Definition: service_locking.h:108
struct mysql_locking_service_st * mysql_locking_service
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:76
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)
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:778