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