MySQL 8.1.0
Source Code Documentation
mysql_transaction.h
Go to the documentation of this file.
1/* Copyright (c) 2013, 2023, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef MYSQL_TRANSACTION_H
24#define MYSQL_TRANSACTION_H
25
26/**
27 @file include/mysql/psi/mysql_transaction.h
28 Instrumentation helpers for transactions.
29*/
30
32
33#include "my_inttypes.h"
34
35#if defined(MYSQL_SERVER) || defined(PFS_DIRECT_CALL)
36/* PSI_TRANSACTION_CALL() as direct call. */
37#include "pfs_transaction_provider.h" // IWYU pragma: keep
38#endif
39
40#ifndef PSI_TRANSACTION_CALL
41#define PSI_TRANSACTION_CALL(M) psi_transaction_service->M
42#endif
43
44/**
45 @defgroup psi_api_transaction Transaction Instrumentation (API)
46 @ingroup psi_api
47 @{
48*/
49
50#ifdef HAVE_PSI_TRANSACTION_INTERFACE
51#define MYSQL_START_TRANSACTION(STATE, XID, TRXID, ISO, RO, AC) \
52 inline_mysql_start_transaction(STATE, XID, TRXID, ISO, RO, AC, __FILE__, \
53 __LINE__)
54#else
55#define MYSQL_START_TRANSACTION(STATE, XID, TRXID, ISO, RO, AC) \
56 do { \
57 } while (0)
58#endif
59
60#ifdef HAVE_PSI_TRANSACTION_INTERFACE
61#define MYSQL_SET_TRANSACTION_GTID(LOCKER, P1, P2) \
62 inline_mysql_set_transaction_gtid(LOCKER, P1, P2)
63#else
64#define MYSQL_SET_TRANSACTION_GTID(LOCKER, P1, P2) \
65 do { \
66 } while (0)
67#endif
68
69#ifdef HAVE_PSI_TRANSACTION_INTERFACE
70#define MYSQL_SET_TRANSACTION_XID(LOCKER, P1, P2) \
71 inline_mysql_set_transaction_xid(LOCKER, P1, P2)
72#else
73#define MYSQL_SET_TRANSACTION_XID(LOCKER, P1, P2) \
74 do { \
75 } while (0)
76#endif
77
78#ifdef HAVE_PSI_TRANSACTION_INTERFACE
79#define MYSQL_SET_TRANSACTION_XA_STATE(LOCKER, P1) \
80 inline_mysql_set_transaction_xa_state(LOCKER, P1)
81#else
82#define MYSQL_SET_TRANSACTION_XA_STATE(LOCKER, P1) \
83 do { \
84 } while (0)
85#endif
86
87#ifdef HAVE_PSI_TRANSACTION_INTERFACE
88#define MYSQL_SET_TRANSACTION_TRXID(LOCKER, P1) \
89 inline_mysql_set_transaction_trxid(LOCKER, P1)
90#else
91#define MYSQL_SET_TRANSACTION_TRXID(LOCKER, P1) \
92 do { \
93 } while (0)
94#endif
95
96#ifdef HAVE_PSI_TRANSACTION_INTERFACE
97#define MYSQL_INC_TRANSACTION_SAVEPOINTS(LOCKER, P1) \
98 inline_mysql_inc_transaction_savepoints(LOCKER, P1)
99#else
100#define MYSQL_INC_TRANSACTION_SAVEPOINTS(LOCKER, P1) \
101 do { \
102 } while (0)
103#endif
104
105#ifdef HAVE_PSI_TRANSACTION_INTERFACE
106#define MYSQL_INC_TRANSACTION_ROLLBACK_TO_SAVEPOINT(LOCKER, P1) \
107 inline_mysql_inc_transaction_rollback_to_savepoint(LOCKER, P1)
108#else
109#define MYSQL_INC_TRANSACTION_ROLLBACK_TO_SAVEPOINT(LOCKER, P1) \
110 do { \
111 } while (0)
112#endif
113
114#ifdef HAVE_PSI_TRANSACTION_INTERFACE
115#define MYSQL_INC_TRANSACTION_RELEASE_SAVEPOINT(LOCKER, P1) \
116 inline_mysql_inc_transaction_release_savepoint(LOCKER, P1)
117#else
118#define MYSQL_INC_TRANSACTION_RELEASE_SAVEPOINT(LOCKER, P1) \
119 do { \
120 } while (0)
121#endif
122
123#ifdef HAVE_PSI_TRANSACTION_INTERFACE
124#define MYSQL_ROLLBACK_TRANSACTION(LOCKER) \
125 inline_mysql_rollback_transaction(LOCKER)
126#else
127#define MYSQL_ROLLBACK_TRANSACTION(LOCKER) NULL
128#endif
129
130#ifdef HAVE_PSI_TRANSACTION_INTERFACE
131#define MYSQL_COMMIT_TRANSACTION(LOCKER) inline_mysql_commit_transaction(LOCKER)
132#else
133#define MYSQL_COMMIT_TRANSACTION(LOCKER) NULL
134#endif
135
136#ifdef HAVE_PSI_TRANSACTION_INTERFACE
138 PSI_transaction_locker_state *state, const void *xid,
139 const ulonglong *trxid, int isolation_level, bool read_only,
140 bool autocommit, const char *src_file, int src_line) {
142 locker = PSI_TRANSACTION_CALL(get_thread_transaction_locker)(
143 state, xid, trxid, isolation_level, read_only, autocommit);
144 if (likely(locker != nullptr)) {
145 PSI_TRANSACTION_CALL(start_transaction)(locker, src_file, src_line);
146 }
147 return locker;
148}
149
151 PSI_transaction_locker *locker, const void *sid, const void *gtid_spec) {
152 if (likely(locker != nullptr)) {
153 PSI_TRANSACTION_CALL(set_transaction_gtid)(locker, sid, gtid_spec);
154 }
155}
156
158 PSI_transaction_locker *locker, const void *xid, int xa_state) {
159 if (likely(locker != nullptr)) {
160 PSI_TRANSACTION_CALL(set_transaction_xid)(locker, xid, xa_state);
161 }
162}
163
165 PSI_transaction_locker *locker, int xa_state) {
166 if (likely(locker != nullptr)) {
167 PSI_TRANSACTION_CALL(set_transaction_xa_state)(locker, xa_state);
168 }
169}
170
172 PSI_transaction_locker *locker, const ulonglong *trxid) {
173 if (likely(locker != nullptr)) {
174 PSI_TRANSACTION_CALL(set_transaction_trxid)(locker, trxid);
175 }
176}
177
179 PSI_transaction_locker *locker, ulong count) {
180 if (likely(locker != nullptr)) {
181 PSI_TRANSACTION_CALL(inc_transaction_savepoints)(locker, count);
182 }
183}
184
186 PSI_transaction_locker *locker, ulong count) {
187 if (likely(locker != nullptr)) {
188 PSI_TRANSACTION_CALL(inc_transaction_rollback_to_savepoint)(locker, count);
189 }
190}
191
193 PSI_transaction_locker *locker, ulong count) {
194 if (likely(locker != nullptr)) {
195 PSI_TRANSACTION_CALL(inc_transaction_release_savepoint)(locker, count);
196 }
197}
198
200 struct PSI_transaction_locker *locker) {
201 if (likely(locker != nullptr)) {
203 }
204}
205
207 struct PSI_transaction_locker *locker) {
208 if (likely(locker != nullptr)) {
210 }
211}
212#endif
213
214/** @} (end of group psi_api_transaction) */
215
216#endif
#define PSI_TRANSACTION_CALL(M)
Definition: psi_transaction.h:35
struct PSI_transaction_locker PSI_transaction_locker
Definition: psi_transaction_bits.h:40
static void inline_mysql_set_transaction_xid(PSI_transaction_locker *locker, const void *xid, int xa_state)
Definition: mysql_transaction.h:157
static void inline_mysql_set_transaction_trxid(PSI_transaction_locker *locker, const ulonglong *trxid)
Definition: mysql_transaction.h:171
static void inline_mysql_inc_transaction_release_savepoint(PSI_transaction_locker *locker, ulong count)
Definition: mysql_transaction.h:192
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:137
static void inline_mysql_set_transaction_gtid(PSI_transaction_locker *locker, const void *sid, const void *gtid_spec)
Definition: mysql_transaction.h:150
static void inline_mysql_rollback_transaction(struct PSI_transaction_locker *locker)
Definition: mysql_transaction.h:199
static void inline_mysql_set_transaction_xa_state(PSI_transaction_locker *locker, int xa_state)
Definition: mysql_transaction.h:164
static void inline_mysql_commit_transaction(struct PSI_transaction_locker *locker)
Definition: mysql_transaction.h:206
static void inline_mysql_inc_transaction_rollback_to_savepoint(PSI_transaction_locker *locker, ulong count)
Definition: mysql_transaction.h:185
static void inline_mysql_inc_transaction_savepoints(PSI_transaction_locker *locker, ulong count)
Definition: mysql_transaction.h:178
constexpr bool likely(bool expr)
Definition: my_compiler.h:56
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
static int count
Definition: myisam_ftdump.cc:44
static int start_transaction(MYSQL *mysql_con)
Definition: mysqldump.cc:5228
constexpr value_type read_only
Definition: classic_protocol_constants.h:212
constexpr value_type autocommit
Definition: classic_protocol_constants.h:151
bool end_transaction(THD *thd, bool error)
Helper function to do rollback or commit, depending on error.
Definition: utils.cc:180
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:52