File: rpl_mts_replica_preserve_commit_order.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (153 lines) | stat: -rw-r--r-- 5,263 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# This test check if the option slave-preserve-commit order
# preserves the commit order with slave binlog enabled.
--source include/not_group_replication_plugin.inc
--source include/have_debug.inc
--source include/have_debug_sync.inc
--source include/only_mts_replica_parallel_workers.inc
--source include/only_mts_replica_parallel_type_logical_clock.inc
--source include/only_replica_preserve_commit_order.inc
--source include/master-slave.inc

# METHOD: We will do some inserts of continious integers into a t1.a
# and enable a forced parallelization. These transactions are applied in
# parallel on the slave. We re-apply the transactions in slave binlog another
# table which contains an additional column (id) of auto increment integer.
# If trasactions are written in order into the slave binlog, then after
# reapplying there will be no rows where t.id != t.a
#
# This script is used with logical clock based MTS.
#

--source include/rpl_connection_master.inc
CREATE TABLE t1 (a INT) ENGINE = InnoDB;

--source include/sync_slave_sql_with_master.inc
--source include/rpl_connection_slave.inc
# Make all following INSERTs into the 2nd binlog.
FLUSH BINARY LOGS;
if (`SELECT @@GLOBAL.gtid_mode = "ON"`)
{
  --disable_query_log
  SET @gtid_set_before_insert = @@GLOBAL.gtid_executed;
  --enable_query_log
}

--echo #
--echo # Verify the transactions are ordered correctly on slave
--echo #
--source include/rpl_connection_master.inc
# Make the following INSERTs have same commit parent. So they can be applied
# parallel on slave.
SET @save_debug = @@GLOBAL.debug;
SET GLOBAL debug = "+d,set_commit_parent_100";

# In each iteration, the master generates some transactions which can be applied
# parallel. Slave is running in MTS mode and has 6 workers. To guarantee all
# transactions are put into the queue togeter, LOCK TABLES is used to block
# workers. After all transactions are in the queue, then UNLOCK TABLES is
# called and all workers can resume.

--let $iteration = 1
# value is from 1 to 21
--let $value = 1

while ($iteration <= 6)
{
  --source include/rpl_connection_slave.inc
  LOCK TABLE t1 WRITE;

  --source include/rpl_connection_master.inc
  --let $row_count= 1
  while ($row_count <= $iteration)
  {
    --eval INSERT INTO t1(a) VALUES ($value)
    --inc $value
    --inc $row_count
  }
  --source include/save_master_pos.inc

  --source include/rpl_connection_slave.inc
  # Wait until all workers are blocked by LOCK TABLE t1 WRITE. It implies all
  # transactions are registered into the order commit queue.
  let $wait_condition= SELECT count(*) = $iteration FROM INFORMATION_SCHEMA.PROCESSLIST WHERE State = 'Waiting for table metadata lock';
  --source include/wait_condition.inc

  UNLOCK TABLES;
  --source include/sync_slave_sql.inc
  SET DEBUG_SYNC = 'RESET';
  --inc $iteration
}

#
# Verify above INSERTs are in the same order as master
#
--source include/rpl_connection_slave.inc
--let $SLAVE_MYSQLD_DATADIR= `SELECT @@DATADIR`
--let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
--copy_file $SLAVE_MYSQLD_DATADIR/$binlog_file $MYSQL_TMP_DIR/$binlog_file

# Slave's binlog will be replied one by one later through mysql. The table is
# recreated with an extra auto increment field. The new field 'id' will be
# filled by server automatically when replying slave's binlog. So It exactly
# records the binlogging order of the transactions.

DROP TABLE t1;
CREATE TABLE t1 (a INT, id INT AUTO_INCREMENT KEY) ENGINE = InnoDB;

# To clear gtid set when gtid mode is ON.
if (`SELECT @@GLOBAL.gtid_mode = "ON"`)
{
  --disable_query_log
  RESET MASTER;
  SET @@global.gtid_purged= @gtid_set_before_insert;
  --enable_query_log
}

# Replay slave's binlog
--exec $MYSQL_BINLOG $MYSQL_TMP_DIR/$binlog_file |$MYSQL_SLAVE

# The transactions should be binlogged in the same order as they are binlogged
# on master. Because the transactions inserts consecutive numbers starting from
# 1 and id starts from 1 and step 1 for each transaction. The table's data should
# look like:
# id    a
# 1     1
# 2     2
# ...  ...
# n     n
# It means the values of field 'id' are always same to the values of field 'a'
SELECT * FROM t1 WHERE id <> a;

--let $assert_text= 'There are no mismatched rows'
--let $assert_cond= [SELECT  COUNT(*) AS count FROM t1 WHERE t1.id <> t1.a, count, 1] = 0
--source include/assert.inc

--let $assert_text= 'There are no row which is null'
--let $assert_cond= [SELECT  COUNT(*) AS count FROM t1 WHERE t1.a is NULL, count, 1] <= 0
--source include/assert.inc

--let $assert_text= 'There are 21 rows'
--let $assert_cond= [SELECT COUNT(*) AS count FROM t1, count, 1] = 21
--source include/assert.inc

--remove_file $MYSQL_TMP_DIR/$binlog_file

--source include/rpl_connection_master.inc
SET GLOBAL debug = @save_debug;

DROP TABLE t1;
--source include/sync_slave_sql_with_master.inc

--echo #
--echo # Verify that it will generate a warning if slave-preserve-commit is
--echo # used with DB PARTITIONED MTS together
--echo #
--source include/stop_slave_sql.inc
SET GLOBAL replica_parallel_type = 'DATABASE';
--error ER_DONT_SUPPORT_REPLICA_PRESERVE_COMMIT_ORDER
START SLAVE SQL_THREAD;

SET GLOBAL replica_parallel_type = 'LOGICAL_CLOCK';
--let rpl_only_running_threads= 1;
--source include/rpl_end.inc