Debian Codegraph @

mysql-test/suite/rpl/t/rpl_mts_replica_preserve_commit_order.test

raw
1 # This test check if the option slave-preserve-commit order
2 # preserves the commit order with slave binlog enabled.
3 --source include/not_group_replication_plugin.inc
4 --source include/have_debug.inc
5 --source include/have_debug_sync.inc
6 --source include/only_mts_replica_parallel_workers.inc
7 --source include/only_mts_replica_parallel_type_logical_clock.inc
8 --source include/only_replica_preserve_commit_order.inc
9 --source include/master-slave.inc
10
11 # METHOD: We will do some inserts of continious integers into a t1.a
12 # and enable a forced parallelization. These transactions are applied in
13 # parallel on the slave. We re-apply the transactions in slave binlog another
14 # table which contains an additional column (id) of auto increment integer.
15 # If trasactions are written in order into the slave binlog, then after
16 # reapplying there will be no rows where t.id != t.a
17 #
18 # This script is used with logical clock based MTS.
19 #
20
21 --source include/rpl_connection_master.inc
22 CREATE TABLE t1 (a INT) ENGINE = InnoDB;
23
24 --source include/sync_slave_sql_with_master.inc
25 --source include/rpl_connection_slave.inc
26 # Make all following INSERTs into the 2nd binlog.
27 FLUSH BINARY LOGS;
28 if (`SELECT @@GLOBAL.gtid_mode = "ON"`)
29 {
30 --disable_query_log
31 SET @gtid_set_before_insert = @@GLOBAL.gtid_executed;
32 --enable_query_log
33 }
34
35 --echo #
36 --echo # Verify the transactions are ordered correctly on slave
37 --echo #
38 --source include/rpl_connection_master.inc
39 # Make the following INSERTs have same commit parent. So they can be applied
40 # parallel on slave.
41 SET @save_debug = @@GLOBAL.debug;
42 SET GLOBAL debug = "+d,set_commit_parent_100";
43
44 # In each iteration, the master generates some transactions which can be applied
45 # parallel. Slave is running in MTS mode and has 6 workers. To guarantee all
46 # transactions are put into the queue togeter, LOCK TABLES is used to block
47 # workers. After all transactions are in the queue, then UNLOCK TABLES is
48 # called and all workers can resume.
49
50 --let $iteration = 1
51 # value is from 1 to 21
52 --let $value = 1
53
54 while ($iteration <= 6)
55 {
56 --source include/rpl_connection_slave.inc
57 LOCK TABLE t1 WRITE;
58
59 --source include/rpl_connection_master.inc
60 --let $row_count= 1
61 while ($row_count <= $iteration)
62 {
63 --eval INSERT INTO t1(a) VALUES ($value)
64 --inc $value
65 --inc $row_count
66 }
67 --source include/save_master_pos.inc
68
69 --source include/rpl_connection_slave.inc
70 # Wait until all workers are blocked by LOCK TABLE t1 WRITE. It implies all
71 # transactions are registered into the order commit queue.
72 let $wait_condition= SELECT count(*) = $iteration FROM INFORMATION_SCHEMA.PROCESSLIST WHERE State = 'Waiting for table metadata lock';
73 --source include/wait_condition.inc
74
75 UNLOCK TABLES;
76 --source include/sync_slave_sql.inc
77 SET DEBUG_SYNC = 'RESET';
78 --inc $iteration
79 }
80
81 #
82 # Verify above INSERTs are in the same order as master
83 #
84 --source include/rpl_connection_slave.inc
85 --let $SLAVE_MYSQLD_DATADIR= `SELECT @@DATADIR`
86 --let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
87 --copy_file $SLAVE_MYSQLD_DATADIR/$binlog_file $MYSQL_TMP_DIR/$binlog_file
88
89 # Slave's binlog will be replied one by one later through mysql. The table is
90 # recreated with an extra auto increment field. The new field 'id' will be
91 # filled by server automatically when replying slave's binlog. So It exactly
92 # records the binlogging order of the transactions.
93
94 DROP TABLE t1;
95 CREATE TABLE t1 (a INT, id INT AUTO_INCREMENT KEY) ENGINE = InnoDB;
96
97 # To clear gtid set when gtid mode is ON.
98 if (`SELECT @@GLOBAL.gtid_mode = "ON"`)
99 {
100 --disable_query_log
101 RESET MASTER;
102 SET @@global.gtid_purged= @gtid_set_before_insert;
103 --enable_query_log
104 }
105
106 # Replay slave's binlog
107 --exec $MYSQL_BINLOG $MYSQL_TMP_DIR/$binlog_file |$MYSQL_SLAVE
108
109 # The transactions should be binlogged in the same order as they are binlogged
110 # on master. Because the transactions inserts consecutive numbers starting from
111 # 1 and id starts from 1 and step 1 for each transaction. The table's data should
112 # look like:
113 # id a
114 # 1 1
115 # 2 2
116 # ... ...
117 # n n
118 # It means the values of field 'id' are always same to the values of field 'a'
119 SELECT * FROM t1 WHERE id <> a;
120
121 --let $assert_text= 'There are no mismatched rows'
122 --let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE t1.id <> t1.a, count, 1] = 0
123 --source include/assert.inc
124
125 --let $assert_text= 'There are no row which is null'
126 --let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE t1.a is NULL, count, 1] <= 0
127 --source include/assert.inc
128
129 --let $assert_text= 'There are 21 rows'
130 --let $assert_cond= [SELECT COUNT(*) AS count FROM t1, count, 1] = 21
131 --source include/assert.inc
132
133 --remove_file $MYSQL_TMP_DIR/$binlog_file
134
135 --source include/rpl_connection_master.inc
136 SET GLOBAL debug = @save_debug;
137
138 DROP TABLE t1;
139 --source include/sync_slave_sql_with_master.inc
140
141 --echo #
142 --echo # Verify that it will generate a warning if slave-preserve-commit is
143 --echo # used with DB PARTITIONED MTS together
144 --echo #
145 --source include/stop_slave_sql.inc
146 SET GLOBAL replica_parallel_type = 'DATABASE';
147 --error ER_DONT_SUPPORT_REPLICA_PRESERVE_COMMIT_ORDER
148 START SLAVE SQL_THREAD;
149
150 SET GLOBAL replica_parallel_type = 'LOGICAL_CLOCK';
151 --let rpl_only_running_threads= 1;
152 --source include/rpl_end.inc
153