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