Debian Codegraph @

mysql-test/suite/rpl/include/rpl_gtid_index.inc

raw
1 # Include file for main test rpl.rpl_gtid_index.
2 # Test GTID indexes with given parameters.
3 #
4 # Parameters:
5 # $NUM_POS Number of GTIDs/binlog positions to create
6 # $NUM_DOMAIN Number of different domains to use
7 # $NUM_SERVER Number of different server_id to use
8 # $NUM_SLAVE_CONNECTS How many GTID slave connect positions to test
9 # $RND_SEED Random seed
10
11
12 --echo *** Testing $NUM_POS GTIDs with $NUM_SLAVE_CONNECTS test connects
13
14 --connection master
15 DELETE FROM t1 WHERE a >= 1000;
16 # Rotate binlogs to make new GTID index settings take effect.
17 FLUSH NO_WRITE_TO_BINLOG BINARY LOGS;
18
19 # Prepare some random values, but deterministic between test runs.
20 CREATE TABLE rand_data(idx INT PRIMARY KEY, domain_id INT, server_id INT)
21 ENGINE=InnoDB;
22 INSERT INTO rand_data(idx, domain_id, server_id) VALUES (0, 0, 1);
23 eval
24 INSERT INTO rand_data(idx, domain_id, server_id)
25 SELECT seq,
26 @tmp:=floor($NUM_DOMAIN*POW(rand($RND_SEED),2)),
27 100 + $NUM_SERVER*@tmp + floor($NUM_SERVER*rand($RND_SEED))
28 FROM seq_1_to_$NUM_POS;
29 # Let's check that the test data is deterministic.
30 # If this changes due to some server changes, it's fine, the .result can just
31 # be updated. But we want it to be identical between test runs on same code,
32 # to facilitate debugging test failures.
33 SELECT COUNT(*), SUM(domain_id), SUM(server_id) FROM rand_data;
34
35 # Create some data for the binlog (and GTID index), recording the correct
36 # binlog positions and GTIDs.
37 CREATE TABLE gtid_data(
38 idx INT PRIMARY KEY,
39 gtid VARCHAR(44),
40 gtid_pos VARCHAR(255),
41 file VARCHAR(100),
42 pos INT,
43 row_count INT,
44 KEY(file, pos)) ENGINE=InnoDB;
45 --let $gtid= `SELECT @@last_gtid`
46
47 --source include/save_master_gtid.inc
48
49 --connection slave
50 --source include/sync_with_master_gtid.inc
51 --source include/stop_slave.inc
52
53 --connection master
54 SET @orig_domain_id= @@gtid_domain_id;
55 SET @orig_server_id= @@server_id;
56 --let $i= 0
57 --let $rotate_point= `SELECT floor($NUM_POS/2)`
58 --let $base_count= `SELECT COUNT(*) FROM t1`
59 --disable_query_log
60 while ($i < $NUM_POS) {
61 --let $file= query_get_value(SHOW MASTER STATUS, File, 1)
62 --let $pos= query_get_value(SHOW MASTER STATUS, Position, 1)
63 --let $gtid_pos= `SELECT @@gtid_binlog_pos`
64 --let $row_count= `SELECT $base_count + $i`
65 eval SET gtid_domain_id= (SELECT domain_id FROM rand_data WHERE idx=$i+1);
66 eval SET server_id= (SELECT server_id FROM rand_data WHERE idx=$i+1);
67 BEGIN;
68 eval INSERT INTO gtid_data(idx, gtid, gtid_pos, file, pos, row_count)
69 VALUES ($i, '$gtid', '$gtid_pos', '$file', $pos, $row_count);
70 eval INSERT INTO t1 VALUES ($i + 1000, 0);
71 COMMIT;
72 --let $gtid= `SELECT @@last_gtid`
73 inc $i;
74 if ($i==$rotate_point) {
75 FLUSH NO_WRITE_TO_BINLOG BINARY LOGS;
76 }
77 }
78 --enable_query_log
79 SET gtid_domain_id= @orig_domain_id;
80 SET server_id= @orig_server_id;
81
82 SELECT COUNT(*) FROM gtid_data;
83
84 # Test that BINLOG_GTID_POS returns correct positions for every GTID position.
85 --echo *** The result should be empty, otherwise some result is wrong:
86 SELECT idx, gtid_pos, BINLOG_GTID_POS(file, pos)
87 FROM gtid_data
88 WHERE NOT gtid_eq(CONVERT(gtid_pos USING utf8),BINLOG_GTID_POS(file, pos))
89 ORDER BY idx;
90
91 # Prepare to rewind the slave to this point to test again on same binlog.
92 --connection slave
93 SET @orig_pos= @@GLOBAL.gtid_slave_pos;
94 SET @orig_t1_limit= (SELECT MAX(a) FROM t1);
95
96 --echo *** Now connect the slave to each position in turn, and test that
97 --echo *** the right amount of data is replicated at each point.
98 --let $old_silent= $keep_include_silent
99 --let $keep_include_silent= 1
100 --let $i= 0
101 --disable_query_log
102 while ($i < $NUM_POS) {
103 --connection master
104 --let $gtid_pos= `SELECT gtid_pos FROM gtid_data WHERE idx=$i`
105 --let $master_count= `SELECT row_count FROM gtid_data WHERE idx=$i`
106 --connection slave
107 --disable_result_log
108 eval START SLAVE UNTIL master_gtid_pos='$gtid_pos';
109 --enable_result_log
110 --let $res= `SELECT MASTER_GTID_WAIT('$gtid_pos')`
111 if ($res != 0) {
112 --die "FAIL: MASTER_GTID_WAIT($gtid_pos) returned $res, should have been 0"
113 }
114 --source include/wait_for_slave_to_stop.inc
115 --let $slave_count = `SELECT COUNT(*) FROM t1`
116 if ($master_count != $slave_count) {
117 SELECT * FROM gtid_data ORDER BY file, pos;
118 SELECT * FROM t1 ORDER BY a;
119 --die "Not all rows replicated. $master_count on master but $slave_count on slave."
120 }
121 --let $i= `SELECT $i + ceil($NUM_POS / $NUM_SLAVE_CONNECTS)`
122 }
123 --enable_query_log
124
125 --echo *** Test slave connecting to some GTID positions where the position in
126 --echo *** the master's binlog is different between the different domains.
127 --echo *** Revind the slave and test on the same binlog data from the master as before.
128 --connection slave
129 SET sql_log_bin= 0;
130 TRUNCATE gtid_data;
131 DELETE FROM t1 WHERE a > @orig_t1_limit;
132 SET sql_log_bin= 1;
133 SET GLOBAL gtid_slave_pos= @orig_pos;
134
135 --let $i= 0
136 --disable_query_log
137 while ($i <= $NUM_DOMAIN) {
138 # Build a GTID position from GTIDs that are picked at different locations
139 # in the gtid_data table for each domain.
140 --connection master
141 let $until_pos=`
142 SELECT GROUP_CONCAT(gtid SEPARATOR ',')
143 FROM gtid_data
144 WHERE idx IN (
145 SELECT MAX(gtid_data.idx) AS pick
146 FROM gtid_data
147 INNER JOIN rand_data ON (rand_data.idx = gtid_data.idx)
148 WHERE gtid_data.idx*$NUM_DOMAIN <= (domain_id + $i)*$NUM_POS
149 GROUP BY domain_id
150 )`;
151 --connection slave
152 --disable_result_log
153 eval START SLAVE UNTIL master_gtid_pos='$until_pos';
154 --enable_result_log
155 --let $res= `SELECT MASTER_GTID_WAIT('$until_pos')`
156 if ($res != 0) {
157 --die "FAIL: MASTER_GTID_WAIT($until_pos) returned $res, should have been 0"
158 }
159 --source include/wait_for_slave_to_stop.inc
160
161 inc $i;
162 }
163 --enable_query_log
164 --let $keep_include_silent= $old_silent
165
166 # Check that everything was replicated (nothing skipped).
167 # We have one less row on the slave since the last UNTIL is the one before
168 # the master inserted the last row.
169 --connection master
170 --let $master_count= `SELECT COUNT(*)-1 FROM t1`
171 --connection slave
172 --let $slave_count= `SELECT COUNT(*) FROM t1`
173 if ($master_count != $slave_count) {
174 SELECT * FROM gtid_data ORDER BY file, pos;
175 SELECT * FROM t1 ORDER BY a;
176 --die "Not all rows replicated. $master_count on master but $slave_count on slave."
177 }
178
179 --connection master
180 DROP TABLE gtid_data, rand_data;
181 --source include/save_master_gtid.inc
182
183 --connection slave
184 --source include/start_slave.inc
185 --source include/sync_with_master_gtid.inc
186
187 --connection master