Debian Codegraph @

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

raw
1 # ==== Purpose ====
2 #
3 # Verify that GTID events are always generated:
4 # - Every binary and relay log must begin with a Previous_gtids_log_event,
5 # regardless of GTID_MODE.
6 # - Every transaction must begin with an Anonymous_gtid event if GTID_MODE=OFF.
7 # - Every transaction must begin with a Gtid event if GTID_MODE=ON.
8 #
9 # ==== Implementation ====
10 #
11 # 1. Generate a binary log and verify that it contains anonymous
12 # events/gtid events.
13 #
14 # 2. Rotate binary logs in all possible ways:
15 # - RESET MASTER
16 # - FLUSH BINARY LOGS
17 # - Grow over the binlog size limit
18 # - Restart master server
19 #
20 # 3. Rotate relay logs in all possible ways:
21 # - Master rotates its binary log in one of the above ways.
22 # - Restart the receiver thread
23 # - FLUSH RELAY LOGS
24 # - Grow over the relay log size limit
25 # - Restart the slave server
26 #
27 # ==== References ====
28 #
29 # WL#7592: GTIDs: generate Gtid_log_event and Previous_gtids_log_event always
30 # - Test created in this worklog.
31
32 # No need to run test in more than one binlog_format.
33 --source include/have_binlog_format_statement.inc
34 --source include/master-slave.inc
35
36 --echo ==== Initialize ====
37
38 --let $gtid_event= Gtid
39 if (!$gtid_mode_on)
40 {
41 --let $gtid_event= Anonymous_Gtid
42 }
43
44 --echo ==== Test presence of transaction events ====
45
46 --source include/save_binlog_position.inc
47 CREATE TABLE t1 (a VARCHAR(10000));
48
49 --let $dont_print_pattern= 1
50 --let $event_sequence= $gtid_event # !Q(CREATE.*)
51 --source include/assert_binlog_events.inc
52 --let $dont_print_pattern= 0
53
54 --source include/save_binlog_position.inc
55 INSERT INTO t1 VALUES ('1');
56
57 --let $dont_print_pattern= 1
58 --let $event_sequence= $gtid_event # !Begin # !Q(INSERT.*) # !Commit
59 --source include/assert_binlog_events.inc
60 --let $dont_print_pattern= 0
61
62 --echo ==== Generate new binary logs in many ways ====
63
64 --echo ---- RESET MASTER ----
65
66 # RESET MASTER is with a running slave has undefined consequences.
67 --connection slave
68 --source include/stop_slave.inc
69 RESET SLAVE;
70 RESET MASTER;
71
72 --connection master
73 RESET MASTER;
74 INSERT INTO t1 VALUES ('2');
75
76 --connection slave
77 # Do not start the applier threads since that would purge processed relay logs.
78 --source include/start_slave_io.inc
79 --connection master
80
81 --echo ---- FLUSH LOGS ----
82
83 FLUSH LOGS;
84 INSERT INTO t1 VALUES ('3');
85
86 --echo ---- Grow over the limit ----
87
88 --let $old_max_binlog_size= `SELECT @@GLOBAL.MAX_BINLOG_SIZE`
89 SET @@GLOBAL.MAX_BINLOG_SIZE= 4096;
90 --let $long_text= `SELECT REPEAT('a', 4096)`
91 --replace_result $long_text <LONG_TEXT>
92 eval INSERT INTO t1 VALUES ('$long_text');
93 eval SET @@GLOBAL.MAX_BINLOG_SIZE= $old_max_binlog_size;
94 eval INSERT INTO t1 VALUES ('4');
95
96 --echo ---- Restart server ----
97
98 --source include/sync_slave_io_with_master.inc
99 --source include/stop_slave_io.inc
100 --connection master
101 --let $rpl_server_number= 1
102 --source include/rpl_restart_server.inc
103 INSERT INTO t1 VALUES ('5');
104
105 --echo ==== Generate new relay logs in many ways ====
106
107 --echo ---- Reconnect receiver thread ----
108
109 --source include/save_master_pos.inc
110 --connection slave
111 --source include/start_slave_io.inc
112 --source include/sync_slave_io.inc
113 # At this point, the slave running without GTID auto positioning will
114 # produce one relaylog file more than the slave running with GTID and auto
115 # positioning.
116 #
117 # This happens because the slave based on master positions will reconnect
118 # asking for the last known good position (at master-bin.000003) and will
119 # read the master rotating to master-bin.000004 and will rotate the relaylog.
120 #
121 # The slave based on GTIDs and AUTO_POSITION will ask for the transaction
122 # which GTID event is at master-bin.000004, so it will not read the master's
123 # rotate event to master-bin.000004.
124 #
125 # So, to make both configurations to have the same amount of relaylog files,
126 # we will generate a FLUSH RELAY LOG only if GTID AUTO_POSITION is enabled.
127
128 --let $is_auto_position_enabled= query_get_value(SHOW SLAVE STATUS, Auto_Position, 1)
129 if ($is_auto_position_enabled)
130 {
131 --disable_query_log
132 FLUSH RELAY LOGS;
133 --enable_query_log
134 }
135 --source include/stop_slave_io.inc
136 # Needed in the 'grow over the limit' case below. We don't want to
137 # disturb that case by reconnecting the receiver thread, so we set the
138 # variable here.
139 --let $old_max_relay_log_size= `SELECT @@GLOBAL.MAX_RELAY_LOG_SIZE`
140 SET @@GLOBAL.MAX_RELAY_LOG_SIZE= 4096;
141 --source include/start_slave_io.inc
142
143 --connection master
144 INSERT INTO t1 VALUES ('6');
145 --source include/sync_slave_io_with_master.inc
146 --connection master
147
148 --echo ---- FLUSH RELAY LOGS ----
149
150 --connection slave
151 FLUSH RELAY LOGS;
152
153 --connection master
154 INSERT INTO t1 VALUES ('7');
155 --source include/sync_slave_io_with_master.inc
156 --connection master
157
158 --echo ---- Grow over the limit ----
159
160 --replace_result $long_text <LONG_TEXT>
161 eval INSERT INTO t1 VALUES ('$long_text');
162 INSERT INTO t1 VALUES ('8');
163 --source include/sync_slave_io_with_master.inc
164 --connection master
165
166 --echo ---- Restart slave server ----
167
168 --let $rpl_server_number= 2
169 --source include/rpl_restart_server.inc
170
171 --connection slave
172 --source include/start_slave_io.inc
173
174 --connection master
175 INSERT INTO t1 VALUES ('9');
176 --source include/sync_slave_io_with_master.inc
177 --connection master
178
179 --echo ==== Test that binary logs contain Previous_gtids ====
180
181 --connection master
182
183 # Parameters for assert_binlog_events.
184 --let $binlog_position=
185 --let $binlog_file=
186 --let $include_header_events= 1
187
188 # Table to store binlog filenames.
189 --connection master
190 SET SQL_LOG_BIN= 0;
191 CREATE TEMPORARY TABLE binlogs
192 (id INT PRIMARY KEY AUTO_INCREMENT, filename VARCHAR(512));
193 --let $index_file= `SELECT @@GLOBAL.LOG_BIN_INDEX`
194 --let $table= binlogs
195 --source include/rpl_read_binlog_index_into_table.inc
196
197 # Verify that each binlog contains the events.
198 --let $count= `SELECT COUNT(*) FROM binlogs`
199 --let $i= 0
200 while ($i < $count)
201 {
202 --let $binlog_file= `SELECT filename FROM binlogs LIMIT $i, 1`
203 --echo $binlog_file
204 --let $event_sequence= Format_desc # Previous_gtids(.|#)*
205 --source include/assert_binlog_events.inc
206 --inc $i
207 }
208 DROP TEMPORARY TABLE binlogs;
209 SET SQL_LOG_BIN= 1;
210
211 --echo ==== Test that relay logs contain Previous_gtids ====
212
213 --connection slave
214
215 # Parameter for assert_binlog_events.
216 --let $relay_log= 1
217
218 SET SQL_LOG_BIN= 0;
219 CREATE TEMPORARY TABLE relay_logs
220 (id INT PRIMARY KEY AUTO_INCREMENT, filename VARCHAR(512));
221 --let $index_file= `SELECT @@GLOBAL.RELAY_LOG_INDEX`
222 --let $table= relay_logs
223 --source include/rpl_read_binlog_index_into_table.inc
224
225 # Verify that each binlog contains the events.
226 --let $count= `SELECT COUNT(*) FROM relay_logs`
227 --let $i= 0
228 while ($i < $count)
229 {
230 --let $binlog_file= `SELECT filename FROM relay_logs LIMIT $i, 1`
231 --let $event_sequence= Format_desc # Previous_gtids(.|#)*
232 --source include/assert_binlog_events.inc
233
234 --inc $i
235 }
236 DROP TEMPORARY TABLE relay_logs;
237 SET SQL_LOG_BIN= 1;
238
239 --echo ==== Clean up ====
240
241 --source include/start_slave_sql.inc
242
243 --connection master
244 DROP TABLE t1;
245
246 --source include/rpl_end.inc