MySQL 8.0.39
Source Code Documentation
mysql_transaction.h
Go to the documentation of this file.
1/* Copyright (c) 2013, 2024, Oracle and/or its affiliates.
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 designed to work 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 either included with
13 the program or referenced in the documentation.
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#ifndef MYSQL_TRANSACTION_H
25#define MYSQL_TRANSACTION_H
26
27/**
28 @file include/mysql/psi/mysql_transaction.h
29 Instrumentation helpers for transactions.
30*/
31
33
34#include "my_inttypes.h"
35
36#if defined(MYSQL_SERVER) || defined(PFS_DIRECT_CALL)
37/* PSI_TRANSACTION_CALL() as direct call. */
38#include "pfs_transaction_provider.h" // IWYU pragma: keep
39#endif
40
41#ifndef PSI_TRANSACTION_CALL
42#define PSI_TRANSACTION_CALL(M) psi_transaction_service->M
43#endif
44
45/**
46 @defgroup psi_api_transaction Transaction Instrumentation (API)
47 @ingroup psi_api
48 @{
49*/
50
51#ifdef HAVE_PSI_TRANSACTION_INTERFACE
52#define MYSQL_START_TRANSACTION(STATE, XID, TRXID, ISO, RO, AC) \
53 inline_mysql_start_transaction(STATE, XID, TRXID, ISO, RO, AC, __FILE__, \
54 __LINE__)
55#else
56#define MYSQL_START_TRANSACTION(STATE, XID, TRXID, ISO, RO, AC) \
57 do { \
58 } while (0)
59#endif
60
61#ifdef HAVE_PSI_TRANSACTION_INTERFACE
62#define MYSQL_SET_TRANSACTION_GTID(LOCKER, P1, P2) \
63 inline_mysql_set_transaction_gtid(LOCKER, P1, P2)
64#else
65#define MYSQL_SET_TRANSACTION_GTID(LOCKER, P1, P2) \
66 do { \
67 } while (0)
68#endif
69
70#ifdef HAVE_PSI_TRANSACTION_INTERFACE
71#define MYSQL_SET_TRANSACTION_XID(LOCKER, P1, P2) \
72 inline_mysql_set_transaction_xid(LOCKER, P1, P2)
73#else
74#define MYSQL_SET_TRANSACTION_XID(LOCKER, P1, P2) \
75 do { \
76 } while (0)
77#endif
78
79#ifdef HAVE_PSI_TRANSACTION_INTERFACE
80#define MYSQL_SET_TRANSACTION_XA_STATE(LOCKER, P1) \
81 inline_mysql_set_transaction_xa_state(LOCKER, P1)
82#else
83#define MYSQL_SET_TRANSACTION_XA_STATE(LOCKER, P1) \
84 do { \
85 } while (0)
86#endif
87
88#ifdef HAVE_PSI_TRANSACTION_INTERFACE
89#define MYSQL_SET_TRANSACTION_TRXID(LOCKER, P1) \
90 inline_mysql_set_transaction_trxid(LOCKER, P1)
91#else
92#define MYSQL_SET_TRANSACTION_TRXID(LOCKER, P1) \
93 do { \
94 } while (0)
95#endif
96
97#ifdef HAVE_PSI_TRANSACTION_INTERFACE
98#define MYSQL_INC_TRANSACTION_SAVEPOINTS(LOCKER, P1) \
99 inline_mysql_inc_transaction_savepoints(LOCKER, P1)
100#else
101#define MYSQL_INC_TRANSACTION_SAVEPOINTS(LOCKER, P1) \
102 do { \
103 } while (0)
104#endif
105
106#ifdef HAVE_PSI_TRANSACTION_INTERFACE
107#define MYSQL_INC_TRANSACTION_ROLLBACK_TO_SAVEPOINT(LOCKER, P1) \
108 inline_mysql_inc_transaction_rollback_to_savepoint(LOCKER, P1)
109#else
110#define MYSQL_INC_TRANSACTION_ROLLBACK_TO_SAVEPOINT(LOCKER, P1) \
111 do { \
112 } while (0)
113#endif
114
115#ifdef HAVE_PSI_TRANSACTION_INTERFACE
116#define MYSQL_INC_TRANSACTION_RELEASE_SAVEPOINT(LOCKER, P1) \
117 inline_mysql_inc_transaction_release_savepoint(LOCKER, P1)
118#else
119#define MYSQL_INC_TRANSACTION_RELEASE_SAVEPOINT(LOCKER, P1) \
120 do { \
121 } while (0)
122#endif
123
124#ifdef HAVE_PSI_TRANSACTION_INTERFACE
125#define MYSQL_ROLLBACK_TRANSACTION(LOCKER) \
126 inline_mysql_rollback_transaction(LOCKER)
127#else
128#define MYSQL_ROLLBACK_TRANSACTION(LOCKER) NULL
129#endif
130
131#ifdef HAVE_PSI_TRANSACTION_INTERFACE
132#define MYSQL_COMMIT_TRANSACTION(LOCKER) inline_mysql_commit_transaction(LOCKER)
133#else
134#define MYSQL_COMMIT_TRANSACTION(LOCKER) NULL
135#endif
136
137#ifdef HAVE_PSI_TRANSACTION_INTERFACE
139 PSI_transaction_locker_state *state, const void *xid,
140 const ulonglong *trxid, int isolation_level, bool read_only,
141 bool autocommit, const char *src_file, int src_line) {
143 locker = PSI_TRANSACTION_CALL(get_thread_transaction_locker)(
144 state, xid, trxid, isolation_level, read_only, autocommit);
145 if (likely(locker != nullptr)) {
146 PSI_TRANSACTION_CALL(start_transaction)(locker, src_file, src_line);
147 }
148 return locker;
149}
150
152 PSI_transaction_locker *locker, const void *sid, const void *gtid_spec) {
153 if (likely(locker != nullptr)) {
154 PSI_TRANSACTION_CALL(set_transaction_gtid)(locker, sid, gtid_spec);
155 }
156}
157
159 PSI_transaction_locker *locker, const void *xid, int xa_state) {
160 if (likely(locker != nullptr)) {
161 PSI_TRANSACTION_CALL(set_transaction_xid)(locker, xid, xa_state);
162 }
163}
164
166 PSI_transaction_locker *locker, int xa_state) {
167 if (likely(locker != nullptr)) {
168 PSI_TRANSACTION_CALL(set_transaction_xa_state)(locker, xa_state);
169 }
170}
171
173 PSI_transaction_locker *locker, const ulonglong *trxid) {
174 if (likely(locker != nullptr)) {
175 PSI_TRANSACTION_CALL(set_transaction_trxid)(locker, trxid);
176 }
177}
178
180 PSI_transaction_locker *locker, ulong count) {
181 if (likely(locker != nullptr)) {
182 PSI_TRANSACTION_CALL(inc_transaction_savepoints)(locker, count);
183 }
184}
185
187 PSI_transaction_locker *locker, ulong count) {
188 if (likely(locker != nullptr)) {
189 PSI_TRANSACTION_CALL(inc_transaction_rollback_to_savepoint)(locker, count);
190 }
191}
192
194 PSI_transaction_locker *locker, ulong count) {
195 if (likely(locker != nullptr)) {
196 PSI_TRANSACTION_CALL(inc_transaction_release_savepoint)(locker, count);
197 }
198}
199
201 struct PSI_transaction_locker *locker) {
202 if (likely(locker != nullptr)) {
204 }
205}
206
208 struct PSI_transaction_locker *locker) {
209 if (likely(locker != nullptr)) {
211 }
212}
213#endif
214
215/** @} (end of group psi_api_transaction) */
216
217#endif
#define PSI_TRANSACTION_CALL(M)
Definition: psi_transaction.h:36
struct PSI_transaction_locker PSI_transaction_locker
Definition: psi_transaction_bits.h:41
static void inline_mysql_set_transaction_xid(PSI_transaction_locker *locker, const void *xid, int xa_state)
Definition: mysql_transaction.h:158
static void inline_mysql_set_transaction_trxid(PSI_transaction_locker *locker, const ulonglong *trxid)
Definition: mysql_transaction.h:172
static void inline_mysql_inc_transaction_release_savepoint(PSI_transaction_locker *locker, ulong count)
Definition: mysql_transaction.h:193
static struct PSI_transaction_locker * inline_mysql_start_transaction(PSI_transaction_locker_state *state, const void *xid, const ulonglong *trxid, int isolation_level, bool read_only, bool autocommit, const char *src_file, int src_line)
Definition: mysql_transaction.h:138
static void inline_mysql_set_transaction_gtid(PSI_transaction_locker *locker, const void *sid, const void *gtid_spec)
Definition: mysql_transaction.h:151
static void inline_mysql_rollback_transaction(struct PSI_transaction_locker *locker)
Definition: mysql_transaction.h:200
static void inline_mysql_set_transaction_xa_state(PSI_transaction_locker *locker, int xa_state)
Definition: mysql_transaction.h:165
static void inline_mysql_commit_transaction(struct PSI_transaction_locker *locker)
Definition: mysql_transaction.h:207
static void inline_mysql_inc_transaction_rollback_to_savepoint(PSI_transaction_locker *locker, ulong count)
Definition: mysql_transaction.h:186
static void inline_mysql_inc_transaction_savepoints(PSI_transaction_locker *locker, ulong count)
Definition: mysql_transaction.h:179
constexpr bool likely(bool expr)
Definition: my_compiler.h:55
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
static int count
Definition: myisam_ftdump.cc:43
static int start_transaction(MYSQL *mysql_con)
Definition: mysqldump.cc:5256
constexpr value_type read_only
Definition: classic_protocol_constants.h:213
constexpr value_type autocommit
Definition: classic_protocol_constants.h:152
bool end_transaction(THD *thd, bool error)
Helper function to do rollback or commit, depending on error.
Definition: utils.cc:181
Performance schema instrumentation (declarations).
Performance schema instrumentation interface.
State data storage for get_thread_transaction_locker_v1_t, get_thread_transaction_locker_v1_t.
Definition: psi_transaction_bits.h:53