1 /* Copyright (c) 2013, 2021, 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 PFS_EVENTS_TRANSACTIONS_H
24 #define PFS_EVENTS_TRANSACTIONS_H
25 
26 /**
27   @file storage/perfschema/pfs_events_transactions.h
28   Events transactions data structures (declarations).
29 */
30 
31 #include "pfs_column_types.h"
32 #include "pfs_events.h"
33 #include "rpl_gtid.h"
34 #include "mysql/plugin.h" /* MYSQL_XIDDATASIZE */
35 
36 struct PFS_thread;
37 struct PFS_account;
38 struct PFS_user;
39 struct PFS_host;
40 
41 /**
42   struct PSI_xid is binary compatible with the XID structure as
43   in the X/Open CAE Specification, Distributed Transaction Processing:
44   The XA Specification, X/Open Company Ltd., 1991.
45   http://www.opengroup.org/bookstore/catalog/c193.htm
46 
47   A value of -1 in formatID means that the XID is null.
48   Max length for bqual and gtrid is 64 bytes each.
49 
50   @see XID in sql/handler.h
51   @see MYSQL_XID in mysql/plugin.h
52 */
53 struct PSI_xid
54 {
55   /** Format identifier. */
56   long formatID;
57   /** GTRID length, value 1-64. */
58   long gtrid_length;
59   /** BQUAL length, value 1-64. */
60   long bqual_length;
61   /** XID raw data, not \0-terminated */
62   char data[MYSQL_XIDDATASIZE];
63 
PSI_xidPSI_xid64   PSI_xid() {null();}
is_nullPSI_xid65   bool is_null() { return formatID == -1; }
nullPSI_xid66   void null() { formatID= -1; gtrid_length= 0; bqual_length= 0;}
67 };
68 typedef struct PSI_xid PSI_xid;
69 
70 /** A transaction record. */
71 struct PFS_events_transactions : public PFS_events
72 {
73   /** Source identifier, mapped from internal format. */
74   rpl_sid m_sid;
75   /** InnoDB transaction ID. */
76   ulonglong m_trxid;
77   /** Status */
78   enum_transaction_state m_state;
79   /** Global Transaction ID specifier. */
80   Gtid_specification m_gtid_spec;
81   /** True if XA transaction. */
82   my_bool m_xa;
83   /** XA transaction ID. */
84   PSI_xid m_xid;
85   /** XA status */
86   enum_xa_transaction_state m_xa_state;
87   /** Transaction isolation level. */
88   enum_isolation_level m_isolation_level;
89   /** True if read-only transaction, otherwise read-write. */
90   my_bool m_read_only;
91   /** True if autocommit transaction. */
92   my_bool m_autocommit;
93   /** Total number of savepoints. */
94   ulonglong m_savepoint_count;
95   /** Number of rollback_to_savepoint. */
96   ulonglong m_rollback_to_savepoint_count;
97   /** Number of release_savepoint. */
98   ulonglong m_release_savepoint_count;
99 };
100 
101 bool xid_printable(PSI_xid *xid, size_t offset, size_t length);
102 
103 void insert_events_transactions_history(PFS_thread *thread, PFS_events_transactions *transaction);
104 void insert_events_transactions_history_long(PFS_events_transactions *transaction);
105 
106 extern bool flag_events_transactions_current;
107 extern bool flag_events_transactions_history;
108 extern bool flag_events_transactions_history_long;
109 
110 extern bool events_transactions_history_long_full;
111 extern PFS_cacheline_uint32 events_transactions_history_long_index;
112 extern PFS_events_transactions *events_transactions_history_long_array;
113 extern ulong events_transactions_history_long_size;
114 
115 int init_events_transactions_history_long(uint events_transactions_history_long_sizing);
116 void cleanup_events_transactions_history_long();
117 
118 void reset_events_transactions_current();
119 void reset_events_transactions_history();
120 void reset_events_transactions_history_long();
121 void reset_events_transactions_by_thread();
122 void reset_events_transactions_by_account();
123 void reset_events_transactions_by_user();
124 void reset_events_transactions_by_host();
125 void reset_events_transactions_global();
126 void aggregate_account_transactions(PFS_account *account);
127 void aggregate_user_transactions(PFS_user *user);
128 void aggregate_host_transactions(PFS_host *host);
129 
130 #endif
131 
132