mysql_transaction.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License, version 2.0,
  4. as published by the Free Software Foundation.
  5. This program is also distributed with certain software (including
  6. but not limited to OpenSSL) that is licensed under separate terms,
  7. as designated in a particular file or component or in included license
  8. documentation. The authors of MySQL hereby grant you an additional
  9. permission to link the program and your derivative works with the
  10. separately licensed software that they have included with MySQL.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License, version 2.0, for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  18. #ifndef MYSQL_TRANSACTION_H
  19. #define MYSQL_TRANSACTION_H
  20. /**
  21. @file mysql/psi/mysql_transaction.h
  22. Instrumentation helpers for transactions.
  23. */
  24. #include "mysql/psi/psi.h"
  25. #ifndef PSI_TRANSACTION_CALL
  26. #define PSI_TRANSACTION_CALL(M) PSI_DYNAMIC_CALL(M)
  27. #endif
  28. /**
  29. @defgroup Transaction_instrumentation Transaction Instrumentation
  30. @ingroup Instrumentation_interface
  31. @{
  32. */
  33. #ifdef HAVE_PSI_TRANSACTION_INTERFACE
  34. #define MYSQL_START_TRANSACTION(STATE, XID, TRXID, ISO, RO, AC) \
  35. inline_mysql_start_transaction(STATE, XID, TRXID, ISO, RO, AC, __FILE__, __LINE__)
  36. #else
  37. #define MYSQL_START_TRANSACTION(STATE, XID, TRXID, ISO, RO, AC) \
  38. do {} while (0)
  39. #endif
  40. #ifdef HAVE_PSI_TRANSACTION_INTERFACE
  41. #define MYSQL_SET_TRANSACTION_GTID(LOCKER, P1, P2) \
  42. inline_mysql_set_transaction_gtid(LOCKER, P1, P2)
  43. #else
  44. #define MYSQL_SET_TRANSACTION_GTID(LOCKER, P1, P2) \
  45. do {} while (0)
  46. #endif
  47. #ifdef HAVE_PSI_TRANSACTION_INTERFACE
  48. #define MYSQL_SET_TRANSACTION_XID(LOCKER, P1, P2) \
  49. inline_mysql_set_transaction_xid(LOCKER, P1, P2)
  50. #else
  51. #define MYSQL_SET_TRANSACTION_XID(LOCKER, P1, P2) \
  52. do {} while (0)
  53. #endif
  54. #ifdef HAVE_PSI_TRANSACTION_INTERFACE
  55. #define MYSQL_SET_TRANSACTION_XA_STATE(LOCKER, P1) \
  56. inline_mysql_set_transaction_xa_state(LOCKER, P1)
  57. #else
  58. #define MYSQL_SET_TRANSACTION_XA_STATE(LOCKER, P1) \
  59. do {} while (0)
  60. #endif
  61. #ifdef HAVE_PSI_TRANSACTION_INTERFACE
  62. #define MYSQL_SET_TRANSACTION_TRXID(LOCKER, P1) \
  63. inline_mysql_set_transaction_trxid(LOCKER, P1)
  64. #else
  65. #define MYSQL_SET_TRANSACTION_TRXID(LOCKER, P1) \
  66. do {} while (0)
  67. #endif
  68. #ifdef HAVE_PSI_TRANSACTION_INTERFACE
  69. #define MYSQL_INC_TRANSACTION_SAVEPOINTS(LOCKER, P1) \
  70. inline_mysql_inc_transaction_savepoints(LOCKER, P1)
  71. #else
  72. #define MYSQL_INC_TRANSACTION_SAVEPOINTS(LOCKER, P1) \
  73. do {} while (0)
  74. #endif
  75. #ifdef HAVE_PSI_TRANSACTION_INTERFACE
  76. #define MYSQL_INC_TRANSACTION_ROLLBACK_TO_SAVEPOINT(LOCKER, P1) \
  77. inline_mysql_inc_transaction_rollback_to_savepoint(LOCKER, P1)
  78. #else
  79. #define MYSQL_INC_TRANSACTION_ROLLBACK_TO_SAVEPOINT(LOCKER, P1) \
  80. do {} while (0)
  81. #endif
  82. #ifdef HAVE_PSI_TRANSACTION_INTERFACE
  83. #define MYSQL_INC_TRANSACTION_RELEASE_SAVEPOINT(LOCKER, P1) \
  84. inline_mysql_inc_transaction_release_savepoint(LOCKER, P1)
  85. #else
  86. #define MYSQL_INC_TRANSACTION_RELEASE_SAVEPOINT(LOCKER, P1) \
  87. do {} while (0)
  88. #endif
  89. #ifdef HAVE_PSI_TRANSACTION_INTERFACE
  90. #define MYSQL_ROLLBACK_TRANSACTION(LOCKER) \
  91. inline_mysql_rollback_transaction(LOCKER)
  92. #else
  93. #define MYSQL_ROLLBACK_TRANSACTION(LOCKER) \
  94. NULL
  95. #endif
  96. #ifdef HAVE_PSI_TRANSACTION_INTERFACE
  97. #define MYSQL_COMMIT_TRANSACTION(LOCKER) \
  98. inline_mysql_commit_transaction(LOCKER)
  99. #else
  100. #define MYSQL_COMMIT_TRANSACTION(LOCKER) \
  101. NULL
  102. #endif
  103. #ifdef HAVE_PSI_TRANSACTION_INTERFACE
  104. static inline struct PSI_transaction_locker *
  105. inline_mysql_start_transaction(PSI_transaction_locker_state *state,
  106. const void *xid,
  107. const ulonglong *trxid,
  108. int isolation_level,
  109. my_bool read_only,
  110. my_bool autocommit,
  111. const char *src_file, int src_line)
  112. {
  113. PSI_transaction_locker *locker;
  114. locker= PSI_TRANSACTION_CALL(get_thread_transaction_locker)(state,
  115. xid, trxid,
  116. isolation_level,
  117. read_only,
  118. autocommit);
  119. if (likely(locker != NULL))
  120. PSI_TRANSACTION_CALL(start_transaction)(locker, src_file, src_line);
  121. return locker;
  122. }
  123. static inline void
  124. inline_mysql_set_transaction_gtid(PSI_transaction_locker *locker,
  125. const void *sid,
  126. const void *gtid_spec)
  127. {
  128. if (likely(locker != NULL))
  129. PSI_TRANSACTION_CALL(set_transaction_gtid)(locker, sid, gtid_spec);
  130. }
  131. static inline void
  132. inline_mysql_set_transaction_xid(PSI_transaction_locker *locker,
  133. const void *xid,
  134. int xa_state)
  135. {
  136. if (likely(locker != NULL))
  137. PSI_TRANSACTION_CALL(set_transaction_xid)(locker, xid, xa_state);
  138. }
  139. static inline void
  140. inline_mysql_set_transaction_xa_state(PSI_transaction_locker *locker,
  141. int xa_state)
  142. {
  143. if (likely(locker != NULL))
  144. PSI_TRANSACTION_CALL(set_transaction_xa_state)(locker, xa_state);
  145. }
  146. static inline void
  147. inline_mysql_set_transaction_trxid(PSI_transaction_locker *locker,
  148. const ulonglong *trxid)
  149. {
  150. if (likely(locker != NULL))
  151. PSI_TRANSACTION_CALL(set_transaction_trxid)(locker, trxid);
  152. }
  153. static inline void
  154. inline_mysql_inc_transaction_savepoints(PSI_transaction_locker *locker,
  155. ulong count)
  156. {
  157. if (likely(locker != NULL))
  158. PSI_TRANSACTION_CALL(inc_transaction_savepoints)(locker, count);
  159. }
  160. static inline void
  161. inline_mysql_inc_transaction_rollback_to_savepoint(PSI_transaction_locker *locker,
  162. ulong count)
  163. {
  164. if (likely(locker != NULL))
  165. PSI_TRANSACTION_CALL(inc_transaction_rollback_to_savepoint)(locker, count);
  166. }
  167. static inline void
  168. inline_mysql_inc_transaction_release_savepoint(PSI_transaction_locker *locker,
  169. ulong count)
  170. {
  171. if (likely(locker != NULL))
  172. PSI_TRANSACTION_CALL(inc_transaction_release_savepoint)(locker, count);
  173. }
  174. static inline void
  175. inline_mysql_rollback_transaction(struct PSI_transaction_locker *locker)
  176. {
  177. if (likely(locker != NULL))
  178. PSI_TRANSACTION_CALL(end_transaction)(locker, false);
  179. }
  180. static inline void
  181. inline_mysql_commit_transaction(struct PSI_transaction_locker *locker)
  182. {
  183. if (likely(locker != NULL))
  184. PSI_TRANSACTION_CALL(end_transaction)(locker, true);
  185. }
  186. #endif
  187. /** @} (end of group Transaction_instrumentation) */
  188. #endif