Debian Codegraph @

mysql-test/suite/perfschema/t/transaction_gtid.test

raw
1 # ==== Purpose ====
2 #
3 # Verify that the GTID column of
4 # performance_schema.events_transactions_current and
5 # performance_schema.events_transactions_history has the correct
6 # value, during different parts of the transaction life cycle.
7 #
8 # There are several cases:
9 #
10 # - When GTID_MODE=ON, a GTID of the form UUID:NUMBER is generated.
11 # When GTID_MODE=OFF, transactions have the special GTID
12 # "ANONYMOUS".
13 #
14 # - On a master, the GTID is generated during the transaction commit;
15 # prior to that it is "AUTOMATIC". On a slave, the GTID is specified
16 # (using SET GTID_NEXT) prior to executing the transaction.
17 #
18 # ==== Implementation ====
19 #
20 # Execute a transaction like:
21 # BEGIN;
22 # INSERT;
23 # COMMIT;
24 # On a different connection, check the GTID columns of the tables
25 # between each statement.
26 #
27 # Transactions to be checked are executed on connection
28 # 'default'. Auxiliary statements to read or truncate the tables are
29 # executed on connection 'server_1'.
30 #
31 # Also execute a ROLLBACK transaction.
32 #
33 # Execute the transaction in these two cases:
34 # - GTID_MODE=ON,
35 # - GTID_MODE=OFF.
36 #
37 # Execute the transaction in these two cases:
38 # - GTID_NEXT='UUID:NUMBER'/'ANONYMOUS' (when GTID_MODE=ON/OFF)
39 # - GTID_NEXT='AUTOMATIC'.
40 #
41 # Due to implementation details, there is a window in time at the
42 # beginning of the transaction when the GTID has not been copied from
43 # the server to the performance_schema internal structures. During
44 # this window, the GTID should be AUTOMATIC even if GTID_NEXT is set
45 # to 'UUID:NUMBER' or 'ANONYMOUS'. To verify this, we use a debug
46 # sync point during the execution of the BEGIN statement.
47 #
48 # ==== References ====
49 #
50 # WL#7592: GTIDS: generate Gtid_log_event and Previous_gtids_log_event always
51 # - The current behavior was specified and the test was introduced in
52 # this worklog.
53
54 --source include/have_debug_sync.inc
55 --source include/have_log_bin.inc
56 --let $rpl_topology= none
57 --let $rpl_server_count= 1
58 --source include/rpl_init.inc
59
60 --echo ==== Configure ====
61
62 --connection default
63
64 SET GLOBAL ENFORCE_GTID_CONSISTENCY = ON;
65
66 --let $thread_id= `SELECT THREAD_ID FROM performance_schema.threads WHERE PROCESSLIST_ID = CONNECTION_ID()`
67 --let $server_uuid= `SELECT @@GLOBAL.SERVER_UUID`
68
69 CREATE TABLE t1 (a INT);
70
71 # These are parameters to include/execute_at_sync_point.inc,
72 # which will remain the same each time the script is invoked.
73 --let $statement_connection= default
74 --let $auxiliary_connection= server_1
75 --let $auxiliary_file= suite/perfschema/include/show_transaction_gtid.inc
76 --let $quiet= 1
77
78 --echo ==== Test ====
79
80 --let $n= 1
81 while ($n <= 4) {
82 if ($n == 1) {
83 --echo ---- Case 1: Specify ANONYMOUS prior to transaction ----
84 --let $gtid= ANONYMOUS
85 }
86 if ($n == 2) {
87 --echo ---- Case 2: Generate ANONYMOUS at commit ----
88 --let $gtid= AUTOMATIC
89 }
90 if ($n == 3) {
91 --let $rpl_gtid_mode= ON
92 --source include/rpl_set_gtid_mode.inc
93 --echo ---- Case 3: Specify GTID prior to transaction ----
94 --let $gtid= aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1
95 }
96 if ($n == 4) {
97 --echo ---- Case 4: Generate GTID at commit ----
98 --let $gtid= AUTOMATIC
99 }
100
101 # Execute a transaction, show the GTID column of the tables
102 # after ROLLBACK.
103
104 --echo * BEGIN ... ROLLBACK
105 --source ../include/reset_transaction_gtid.inc
106
107 --source ../include/show_transaction_gtid.inc
108 eval SET SESSION GTID_NEXT = '$gtid';
109 BEGIN;
110 eval INSERT INTO t1 VALUES ($n);
111 ROLLBACK;
112 --source ../include/show_transaction_gtid.inc
113
114 # Same transaction as above, but with a commit. Show the GTID column
115 # of the tables between each statement, as well as in the middle of
116 # the BEGIN statement.
117
118 --echo * BEGIN ... COMMIT
119 --source ../include/reset_transaction_gtid.inc
120
121 --source ../include/show_transaction_gtid.inc
122 eval SET SESSION GTID_NEXT = '$gtid';
123 --source ../include/show_transaction_gtid.inc
124 --let $statement= BEGIN
125 --let $sync_point= after_set_transaction_psi_before_set_transaction_gtid
126 --source include/execute_at_sync_point.inc
127 --source ../include/show_transaction_gtid.inc
128 eval INSERT INTO t1 VALUES ($n);
129 --source ../include/show_transaction_gtid.inc
130 COMMIT;
131 --source ../include/show_transaction_gtid.inc
132
133 # A transaction executed with AUTOCOMMIT=OFF and no BEGIN. Show the
134 # GTID column between each statement, as well as in the middle of
135 # the first DML statement.
136
137 --echo * AUTOCOMMIT = OFF
138 SET @@SESSION.AUTOCOMMIT = 0;
139 --source ../include/reset_transaction_gtid.inc
140
141 --source ../include/show_transaction_gtid.inc
142 eval SET SESSION GTID_NEXT = '$gtid';
143 --source ../include/show_transaction_gtid.inc
144 --let $statement= INSERT INTO t1 VALUES ($n)
145 --let $sync_point= begin_decide_logging_format
146 --source include/execute_at_sync_point.inc
147 --source ../include/show_transaction_gtid.inc
148 COMMIT;
149 --source ../include/show_transaction_gtid.inc
150
151 # A single-statement transaction executed with AUTOCOMMIT=ON and no
152 # BEGIN. Show the GTID column before and after, as well as in the
153 # middle of the statement.
154
155 --echo * AUTOCOMMIT = ON
156 SET @@SESSION.AUTOCOMMIT = 1;
157 --source ../include/reset_transaction_gtid.inc
158
159 --source ../include/show_transaction_gtid.inc
160 eval SET SESSION GTID_NEXT = '$gtid';
161 --source ../include/show_transaction_gtid.inc
162 --let $statement= INSERT INTO t1 VALUES ($n)
163 --let $sync_point= begin_decide_logging_format
164 --source include/execute_at_sync_point.inc
165 --source ../include/show_transaction_gtid.inc
166
167 # Disabled because DDL is not inserted into the tables
168 if (0) {
169 # An implicitly committing statement (DDL), no BEGIN.
170 --echo * implicit commit (DDL)
171 --source ../include/reset_transaction_gtid.inc
172
173 --source ../include/show_transaction_gtid.inc
174 eval SET SESSION GTID_NEXT = '$gtid';
175 --source ../include/show_transaction_gtid.inc
176 --let $statement= CREATE TABLE t_$n (a INT)
177 --let $sync_point= begin_decide_logging_format
178 --source include/execute_at_sync_point.inc
179 --source ../include/show_transaction_gtid.inc
180 }
181
182 --inc $n
183 }
184
185 --echo ==== Clean up ====
186
187 DROP TABLE t1;
188 # DROP TABLE t_1, t_2, t_3, t_4;
189
190 --let $rpl_gtid_mode= OFF
191 --source include/rpl_set_gtid_mode.inc
192 SET GLOBAL ENFORCE_GTID_CONSISTENCY = OFF;
193
194 --source include/rpl_end.inc