Debian Codegraph @

mysql-test/suite/binlog/t/binlog_xa_prepared.inc

raw
1 --source include/have_innodb.inc
2 --source include/have_perfschema.inc
3 #
4 # The test verifies binlogging of XA transaction and state of prepared XA
5 # as far as binlog is concerned.
6 #
7 # The prepared XA transactions can be disconnected from the client,
8 # discovered from another connection and commited or rolled back
9 # later. They also survive the server restart. The test runs two
10 # loops each consisting of prepared XA:s generation, their
11 # manipulation and a server restart followed with survived XA:s
12 # completion.
13 #
14 # Prepared XA can't get available to an external connection
15 # until connection that either leaves actively or is killed
16 # has completed a necessary part of its cleanup.
17 # Selecting from P_S.threads provides a method to learn that.
18 #
19 # Total number of connection each performing one insert into table
20 --let $conn_number=20
21 # Number of rollbacks and commits from either side of the server restart
22 --let $rollback_number=5
23 --let $commit_number=5
24 # Number of transactions that are terminated before server restarts
25 --let $term_number=`SELECT $rollback_number + $commit_number`
26 # Instead of disconnect make some connections killed when their
27 # transactions got prepared.
28 --let $killed_number=5
29 # make some connections disconnected by shutdown rather than actively
30 --let $server_disconn_number=5
31 --let $prepared_at_server_restart = `SELECT $conn_number - $term_number`
32 # number a "warmup" connection after server restart, they all commit
33 --let $post_restart_conn_number=10
34
35 # Counter to be used in GTID consistency check.
36 # It's incremented per each non-XA transaction commit.
37 # Local to this file variable to control one-phase commit loop
38 --let $one_phase_number = 5
39
40 --connection default
41
42 # Remove possibly preceeding binlogs and clear initialization time
43 # GTID executed info. In the following all transactions are counted
44 # to conduct verification at the end of the test.
45 if (`SELECT @@global.log_bin`)
46 {
47 RESET MASTER;
48 }
49
50 # Disconected and follower threads need synchronization
51 CREATE VIEW v_processlist as SELECT * FROM performance_schema.threads where type = 'FOREGROUND';
52
53 --eval call mtr.add_suppression("Found $prepared_at_server_restart prepared XA transactions")
54
55 CREATE TABLE t (a INT) ENGINE=innodb;
56
57 # MDEV-515 takes X-lock on the table for the first insert.
58 # So concurrent insert won't happen on the table
59 INSERT INTO t VALUES(100);
60
61 # Counter is incremented at the end of post restart to
62 # reflect number of loops done in correctness computation.
63 --let $restart_number = 0
64 --let $how_to_restart=restart_mysqld.inc
65 --source suite/binlog/include/binlog_xa_prepared_do_and_restart.inc
66
67 --let $how_to_restart=kill_and_restart_mysqld.inc
68 --source suite/binlog/include/binlog_xa_prepared_do_and_restart.inc
69
70 --connection default
71
72 # Few xs that commit in one phase, not subject to the server restart
73 # nor reconnect.
74 # This piece of test is related to mysqlbinlog recovery examine below.
75 --let $k = 0
76 while ($k < $one_phase_number)
77 {
78 --eval XA START 'one_phase_trx_$k'
79 --eval INSERT INTO t SET a=$k
80 --eval XA END 'one_phase_trx_$k'
81 --eval XA COMMIT 'one_phase_trx_$k' ONE PHASE
82
83 --inc $k
84 }
85
86 SELECT SUM(a) FROM t;
87 DROP TABLE t;
88 DROP VIEW v_processlist;
89
90 let $outfile= $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql;
91 if (`SELECT @@global.log_bin`)
92 {
93 # Recording proper samples of binlogged prepared XA:s
94 --source include/show_binlog_events.inc
95 --exec $MYSQL_BINLOG -R --to-last-log master-bin.000001 > $outfile
96 }
97
98 --echo All transactions must be completed, to empty-list the following:
99 XA RECOVER;
100
101 if (`SELECT @@global.log_bin`)
102 {
103 --exec $MYSQL test < $outfile
104 --remove_file $outfile
105 XA RECOVER;
106 }