Debian Codegraph @

mysql-test/suite/binlog_nogtid/t/binlog_anonymous_ownership.test

raw
1 # ==== Purpose ====
2 #
3 # Check that anonymous ownership is acquired and released as expected.
4 #
5 # When a client sets GTID_NEXT='ANONYMOUS', it 'acquires anonymous
6 # ownership'. Then, when it commits or rolls back, it 'releases
7 # anonymous ownership. If GTID_NEXT='AUTOMATIC' and GTID_MODE=OFF or
8 # OFF_PERMISSIVE, then a client 'acquires anonymous ownership' when
9 # the transaction is flushed to the binary log, and releases it on
10 # commit. If a client already has GTID_NEXT='ANONYMOUS' but anonymous
11 # ownership has been released by a commit or rollback, then anonymous
12 # ownership is re-acquired when the next statement begins to execute.
13 # As an exception, "innocent" statements do not re-acquire anonymous
14 # ownership; here "innocent" statements include SET, SHOW, SELECT, and
15 # DO statements that do not invoke stored functions.
16 #
17 # Multiple clients can 'hold anonymous ownership' at the same time.
18 # The global status variable ONGOING_ANONYMOUS_TRANSACTION_COUNT
19 # contains the number of clients that 'hold anonymous ownership'. The
20 # session variable @@session.gtid_owned contains the string
21 # 'ANONYMOUS' if the client hold anonymous ownership.
22 #
23 # This test checks different ways to acquire and release ownership,
24 # and verifies that ONGOING_ANONYMOUS_TRANSACTION_COUNT and
25 # @@SESSION.GTID_OWNED change accordingly.
26 #
27 # ==== Implementation ====
28 #
29 # We test a number of statements. For each statement we specify what
30 # is the expected values of GTID_NEXT, GTID_OWNED, and
31 # ONGOING_ANONYMOUS_TRANSACTION_COUNT after the statement. Each
32 # statement is stored together with the expected values of these
33 # variables in one row of the table 'statements'. Thus the test
34 # scenarios are specified by the contents of this table in the
35 # 'Initialize' section below. In the 'Test' section, we execute one
36 # row at a time from the table and check that the variables change as
37 # specified.
38 #
39 # ==== References ====
40 #
41 # WL#7083: GTIDs: set gtid_mode=ON online
42 # - Behavior of anonymous ownership was specified in this worklog.
43 # - Most of test was implemented in this worklog.
44 #
45 # WL#7592: GTIDs: generate Gtid_log_event and Previous_gtids_log_event always
46 # BUG#20341210: WL7592: ASSERT AT BINLOG.CC:1139 FOR IMPLICIT COMMIT WHEN GTID_NEXT=ANONYMOUS
47 # - The bugfix was verified by the test case
48 # binlog_gtid_next_anonymous_implicit_commit.test, which was
49 # subsequently moved into the present test (the cases for implicit
50 # commit inside a transaction).
51
52 # Test sets gtid_mode explicitly, no need to run in multiple combinations.
53
54 --source include/have_debug_sync.inc
55
56 --let $rpl_extra_connections_per_server= 3
57 --let $rpl_topology= none
58 --source include/rpl_init.inc
59
60
61 --echo ==== Initialize ====
62
63 SET GLOBAL ENFORCE_GTID_CONSISTENCY = ON;
64
65 CREATE TABLE statements (
66 id INT PRIMARY KEY AUTO_INCREMENT,
67 comment VARCHAR(100) NOT NULL,
68 connection INT,
69 statement VARCHAR(1000),
70 gtid_next VARCHAR(100) NOT NULL,
71 gtid_owned VARCHAR(100) NOT NULL,
72 anonymous_count INT NOT NULL,
73 sync_point VARCHAR(100) NOT NULL,
74 error VARCHAR(100) NOT NULL
75 ) ENGINE = InnoDB;
76
77 INSERT INTO statements
78 (comment, connection, statement, gtid_next, gtid_owned, anonymous_count,
79 sync_point, error)
80 VALUES
81 #comment
82 #con statement gtid_next gtid_owned count sync error
83 ('Nothing should be owned by default.',
84 1, '', 'AUTOMATIC', '', 0, '', ''),
85
86 ('Set gtid_next (automatic->anonymous) acquires ownership.',
87 1, 'SET GTID_NEXT="ANONYMOUS"', 'ANONYMOUS', 'ANONYMOUS', 1, '', ''),
88
89 ('Implicit commit releases ownership.',
90 1, 'CREATE TABLE t1 (a INT)', 'ANONYMOUS', '', 0, '', ''),
91
92 ('Implicitly committing statement re-acquires ownership.',
93 1, 'CREATE TABLE t2 (a INT)', '', '', 1, '->before_execute_sql_command', ''),
94
95 ('Implicitly committing statement releases ownership at the end.',
96 1, '#CREATE TABLE t2 (a INT)', 'ANONYMOUS', '', 0, 'before_execute_sql_command->', ''),
97
98 ('Set gtid_next (anonymous->anonymous) acquires ownership.',
99 1, 'SET GTID_NEXT="ANONYMOUS"', 'ANONYMOUS', 'ANONYMOUS', 1, '', ''),
100
101 ('Nothing special happens with ownership while inside a transaction.',
102 1, 'BEGIN', 'ANONYMOUS', 'ANONYMOUS', 1, '', ''),
103 ('',
104 1, 'INSERT INTO t1 VALUES (1)', 'ANONYMOUS', 'ANONYMOUS', 1, '', ''),
105
106 ('Commit releases ownership.',
107 1, 'COMMIT', 'ANONYMOUS', '', 0, '', ''),
108
109 ('Begin acquires ownership.',
110 1, 'BEGIN', 'ANONYMOUS', 'ANONYMOUS', 1, '', ''),
111
112 ('Commit releases ownership even if nothing executed.',
113 1, 'COMMIT', 'ANONYMOUS', '', 0, '', ''),
114
115 ('Rollback releases ownership.',
116 1, 'BEGIN', 'ANONYMOUS', 'ANONYMOUS', 1, '', ''),
117
118 ('',
119 1, 'ROLLBACK', 'ANONYMOUS', '', 0, '', ''),
120
121 ('Implicit commit in transaction releases ownership.',
122 1, 'BEGIN', 'ANONYMOUS', 'ANONYMOUS', 1, '', ''),
123
124 ('',
125 1, 'INSERT INTO t1 VALUES (1)', 'ANONYMOUS', 'ANONYMOUS', 1, '', ''),
126
127 ('',
128 1, 'DROP TABLE t2', 'ANONYMOUS', '', 0, '->after_implicit_pre_commit', ''),
129
130 ('',
131 1, '#DROP TABLE t2', 'ANONYMOUS', '', 0, 'after_implicit_pre_commit->', ''),
132
133 ('Autocommit transaction acquires ownership.',
134 1, 'INSERT INTO t1 VALUES (1)', '', '', 1, '->before_execute_sql_command', ''),
135
136 ('Autocommit transaction releases ownership at end.',
137 1, '#INSERT INTO t1 VALUES (1)', 'ANONYMOUS', '', 0, 'before_execute_sql_command->', ''),
138
139 ('SET does not acquire ownership.',
140 1, 'SET AUTOCOMMIT = 0', 'ANONYMOUS', '', 0, '', ''),
141
142 ('Non-autocommitted DML acquires ownership.',
143 1, 'INSERT INTO t1 VALUES (1)', 'ANONYMOUS', 'ANONYMOUS', 1, '', ''),
144 ('',
145 1, 'INSERT INTO t1 VALUES (1)', 'ANONYMOUS', 'ANONYMOUS', 1, '', ''),
146 ('',
147 1, 'ROLLBACK', 'ANONYMOUS', '', 0, '', ''),
148
149 ('Client disconnect releases ownership.',
150 1, 'BEGIN', 'ANONYMOUS', 'ANONYMOUS', 1, '', ''),
151 ('',
152 1, 'reconnect', 'AUTOMATIC', '', 0, '', ''),
153
154 ('Ongoing_anonymous_transaction_count > 1 when there are concurrent transactions.',
155 1, 'SET GTID_NEXT="ANONYMOUS"', 'ANONYMOUS', 'ANONYMOUS', 1, '', ''),
156 ('',
157 2, '', 'AUTOMATIC', '', 1, '', ''),
158 ('',
159 2, 'SET GTID_NEXT="ANONYMOUS"', 'ANONYMOUS', 'ANONYMOUS', 2, '', ''),
160 ('',
161 3, '', 'AUTOMATIC', '', 2, '', ''),
162 ('',
163 3, 'SET GTID_NEXT="ANONYMOUS"', 'ANONYMOUS', 'ANONYMOUS', 3, '', ''),
164 ('',
165 2, 'reconnect', 'AUTOMATIC', '', 2, '', ''),
166 ('',
167 1, 'COMMIT', 'ANONYMOUS', '', 1, '', ''),
168 ('',
169 3, 'ROLLBACK', 'ANONYMOUS', '', 0, '', ''),
170
171 ('Set gtid_next (anonymous->automatic) works.',
172 1, 'SET GTID_NEXT="AUTOMATIC"', 'AUTOMATIC', '', 0, '', ''),
173
174 ('Set gtid_next (automatic->automatic) works.',
175 1, 'SET GTID_NEXT="AUTOMATIC"', 'AUTOMATIC', '', 0, '', ''),
176
177 ('Can set gtid_mode!=on when Ongoing_anonymous_transaction_count > 0.',
178 2, 'SET GTID_NEXT="ANONYMOUS"', 'ANONYMOUS', 'ANONYMOUS', 1, '', ''),
179 ('',
180 1, 'SET GLOBAL GTID_MODE="OFF_PERMISSIVE"','AUTOMATIC', '', 1, '', ''),
181 ('',
182 1, 'SET GLOBAL GTID_MODE="ON_PERMISSIVE"', 'AUTOMATIC', '', 1, '', ''),
183 ('',
184 1, 'SET GLOBAL GTID_MODE="ON_PERMISSIVE"', 'AUTOMATIC', '', 1, '', ''),
185 ('',
186 1, 'SET GLOBAL GTID_MODE="OFF_PERMISSIVE"','AUTOMATIC', '', 1, '', ''),
187 ('',
188 1, 'SET GLOBAL GTID_MODE="OFF_PERMISSIVE"','AUTOMATIC', '', 1, '', ''),
189 ('',
190 1, 'SET GLOBAL GTID_MODE="OFF"', 'AUTOMATIC', '', 1, '', ''),
191 ('',
192 1, 'SET GLOBAL GTID_MODE="OFF"', 'AUTOMATIC', '', 1, '', ''),
193 ('',
194 2, 'ROLLBACK', 'ANONYMOUS', '', 0, '', '');
195
196
197 --echo ==== Test ====
198
199 --let $statement_count= `SELECT COUNT(*) FROM statements`
200 --let $statement_number= 0
201 while ($statement_number < $statement_count)
202 {
203 --connection default
204 --let $suffix= FROM statements ORDER BY id LIMIT $statement_number, 1
205 --let $comment= `SELECT comment $suffix`
206 --let $statement= `SELECT statement $suffix`
207 --let $connection_number= `SELECT connection $suffix`
208 --let $connection= server_1_$connection_number
209 --let $gtid_next= `SELECT gtid_next $suffix`
210 --let $gtid_owned= `SELECT gtid_owned $suffix`
211 --let $anonymous_count= `SELECT anonymous_count $suffix`
212 --let $sync_point= `SELECT sync_point $suffix`
213 --let $error= `SELECT error $suffix`
214
215 if ($comment != '')
216 {
217 --echo ---- Comment ----
218 }
219 --echo # Statement $statement_number:
220
221 --let $rpl_connection_name= $connection
222 --source include/rpl_connection.inc
223
224 if ($statement == 'reconnect')
225 {
226 # Get connection id.
227 --connection $connection
228 --let $thread_id= `SELECT CONNECTION_ID()`
229
230 # Disconnect
231 --connection default
232 --disconnect $connection
233
234 # Wait for session to disappear.
235 --let $wait_condition= SELECT COUNT(*) = 0 FROM performance_schema.threads WHERE PROCESSLIST_ID = $thread_id
236 --source include/wait_condition.inc
237
238 # Reconnect
239 --let $rpl_connection_name= $connection
240 --let $rpl_server_number= 1
241 --source include/rpl_connect.inc
242
243 --let $statement=
244 }
245
246 if ($sync_point != '')
247 {
248 --connection default
249 --let $sync_point_from= `SELECT SUBSTRING_INDEX('$sync_point', '->', 1)`
250 --let $sync_point_to= `SELECT SUBSTRING_INDEX('$sync_point', '->', -1)`
251 if ($sync_point_to != '')
252 {
253 --let $statement_connection= $connection
254 --let $auxiliary_connection= default
255 --let $sync_point= $sync_point_to
256 --source include/execute_to_sync_point.inc
257 }
258 if ($sync_point_from != '')
259 {
260 --let $statement_connection= $connection
261 --let $auxiliary_connection= default
262 --let $sync_point= $sync_point_from
263 --source include/execute_from_sync_point.inc
264 }
265 }
266
267 if ($sync_point == '')
268 {
269 if ($statement != '')
270 {
271 #Disabled because of BUG#13687542.
272 #if ($error != '')
273 #{
274 # --error $error
275 #}
276
277 eval $statement;
278 }
279 }
280
281 # If we used execute_to_sync_point.inc above, then the connection
282 # has changed and we cannot execute on $connection. So skip the
283 # checks for session variables in that case.
284 if ($CURRENT_CONNECTION == $connection)
285 {
286 --let $actual_gtid_owned= `SELECT @@SESSION.GTID_OWNED`
287 --let $actual_gtid_next= `SELECT @@SESSION.GTID_NEXT`
288
289 --connection default
290 --let $assert_text= GTID_NEXT should be '$gtid_next'
291 --let $assert_cond= "$actual_gtid_next" = "$gtid_next"
292 --source include/assert.inc
293
294 --let $assert_text= GTID_OWNED should be '$gtid_owned'
295 --let $assert_cond= "$actual_gtid_owned" = "$gtid_owned"
296 --source include/assert.inc
297 }
298
299 --let $assert_text= ONGOING_ANONYMOUS_TRANSACTION_COUNT should be $anonymous_count
300 --let $assert_cond= [SHOW STATUS LIKE "ONGOING_ANONYMOUS_TRANSACTION_COUNT", Value, 1] = $anonymous_count
301 --source include/assert.inc
302
303 --inc $statement_number
304 }
305
306 --connection server_1
307 SET GTID_NEXT = 'ANONYMOUS';
308 --connection server_1_1
309 SET GLOBAL GTID_MODE = 'OFF_PERMISSIVE';
310 SET GLOBAL GTID_MODE = 'ON_PERMISSIVE';
311 --error ER_CANT_SET_GTID_MODE
312 --connection server_1
313 ROLLBACK;
314 --connection server_1_1
315 SET GLOBAL GTID_MODE = 'ON';
316 --connection server_1
317 SELECT @@GLOBAL.GTID_MODE;
318 --error ER_CANT_SET_GTID_NEXT_TO_ANONYMOUS_WHEN_GTID_MODE_IS_ON
319 SET GTID_NEXT = 'ANONYMOUS';
320
321
322 --echo ==== Clean up ====
323
324 SET GLOBAL GTID_MODE = 'ON_PERMISSIVE';
325 SET GLOBAL GTID_MODE = 'OFF_PERMISSIVE';
326 SET GLOBAL GTID_MODE = 'OFF';
327 DROP TABLE statements;
328 DROP TABLE t1;
329 SET GLOBAL ENFORCE_GTID_CONSISTENCY = OFF;
330
331 --source include/rpl_end.inc