Debian Codegraph @

mysql-test/suite/binlog/t/binlog_checkpoint.test

raw
1 --source include/have_innodb.inc
2 --source include/have_debug.inc
3 --source include/have_debug_sync.inc
4 --source include/have_binlog_format_row.inc
5
6 SET @old_max_binlog_size= @@global.max_binlog_size;
7 SET GLOBAL max_binlog_size= 4096;
8 SET @old_innodb_flush_log_at_trx_commit= @@global.innodb_flush_log_at_trx_commit;
9 SET GLOBAL innodb_flush_log_at_trx_commit= 1;
10 RESET MASTER;
11
12 CREATE TABLE t1 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Innodb;
13 CREATE TABLE t2 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Myisam;
14
15 --echo *** Test that RESET MASTER waits for pending commit checkpoints to complete.
16
17 # con1 will hang before doing commit checkpoint, blocking RESET MASTER.
18 connect(con1,localhost,root,,);
19 SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con1_ready WAIT_FOR con1_go";
20 send INSERT INTO t1 VALUES (1, REPEAT("x", 4100));
21
22 connection default;
23 SET DEBUG_SYNC= "now WAIT_FOR con1_ready";
24 # Let's add a few binlog rotations just for good measure.
25 INSERT INTO t2 VALUES (1, REPEAT("x", 4100));
26 INSERT INTO t2 VALUES (2, REPEAT("x", 4100));
27 --source include/show_binary_logs.inc
28 --let $binlog_file= master-bin.000004
29 --let $binlog_start= 4
30 --source include/show_binlog_events.inc
31 SET DEBUG_SYNC= "execute_command_after_close_tables SIGNAL reset_master_done";
32 send RESET MASTER;
33
34 connect(con2,localhost,root,,);
35 --echo This will timeout, as RESET MASTER is blocked
36 SET DEBUG_SYNC= "now WAIT_FOR reset_master_done TIMEOUT 1";
37 # Wake up transaction to allow RESET MASTER to complete.
38 SET DEBUG_SYNC= "now SIGNAL con1_go";
39
40 connection con1;
41 reap;
42
43 connection default;
44 reap;
45 --source include/show_binary_logs.inc
46 --let $binlog_file= master-bin.000001
47 --let $binlog_start= 4
48 --source include/show_binlog_events.inc
49
50 --echo *** Test that binlog N is active, and commit checkpoint for (N-1) is
51 --echo *** done while there is still a pending commit checkpoint for (N-2).
52
53 connection con1;
54 SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con1_ready WAIT_FOR con1_continue";
55 send INSERT INTO t1 VALUES (20, REPEAT("x", 4100));
56
57 connection default;
58 SET DEBUG_SYNC= "now WAIT_FOR con1_ready";
59
60 connection con2;
61 SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con2_ready WAIT_FOR con2_continue";
62 send INSERT INTO t1 VALUES (21, REPEAT("x", 4100));
63
64 connection default;
65 SET DEBUG_SYNC= "now WAIT_FOR con2_ready";
66 --source include/show_binary_logs.inc
67 --let $binlog_file= master-bin.000001
68 --source include/show_binlog_events.inc
69 --let $binlog_file= master-bin.000002
70 --source include/show_binlog_events.inc
71 --let $binlog_file= master-bin.000003
72 --source include/show_binlog_events.inc
73
74 # We need to sync the test case with the background processing of the
75 # commit checkpoint, otherwise we get nondeterministic results.
76 SET DEBUG_SYNC= "RESET";
77 SET @old_dbug= @@global.DEBUG_DBUG;
78 SET GLOBAL debug_dbug="+d,binlog_background_checkpoint_processed";
79
80 SET DEBUG_SYNC= "now SIGNAL con2_continue";
81
82 connection con2;
83 reap;
84
85 connection default;
86 --echo con1 is still pending, no new binlog checkpoint should have been logged.
87 # Make sure commit checkpoint is processed before we check that no checkpoint
88 # event has been binlogged.
89 SET DEBUG_SYNC= "now WAIT_FOR binlog_background_checkpoint_processed";
90 SET GLOBAL debug_dbug= @old_dbug;
91 SET DEBUG_SYNC= "RESET";
92
93 --let $binlog_file= master-bin.000003
94 --source include/show_binlog_events.inc
95
96 SET DEBUG_SYNC= "now SIGNAL con1_continue";
97
98 connection con1;
99 reap;
100
101 connection default;
102
103 --echo No commit checkpoints are pending, a new binlog checkpoint should have been logged.
104 --let $binlog_file= master-bin.000003
105
106 # Wait for the master-bin.000003 binlog checkpoint to appear.
107 --let $wait_for_all= 0
108 --let $show_statement= SHOW BINLOG EVENTS IN "$binlog_file"
109 --let $field= Info
110 --let $condition= = "master-bin.000003"
111 --source include/wait_show_condition.inc
112
113 --source include/show_binlog_events.inc
114
115
116 --echo *** MDEV-4322: Broken XID counting during binlog rotation ***
117
118 # Test that binlog shutdown waits for any pending binlog checkpoints to have time to complete.
119
120 connection default;
121 # We will use debug_sync to setup a wait inside the background processing
122 # of binlog checkpoints. The wait is newer resumed, and will eventually
123 # time out. If server shutdown does not wait for checkpoint processing to
124 # complete, we will get an assert.
125 #
126 # It is a bit tricky to inject the wait properly as it has to happen in a
127 # background thread during shutdown. So we first inject a DBUG to set the
128 # debug_sync wait in the correct thread, then wait to be signalled that
129 # the inject happened so that we can remove it again from DBUG (else
130 # check_testcase will complain).
131
132 SET @old_dbug= @@global.DEBUG_DBUG;
133 SET GLOBAL debug_dbug="+d,inject_binlog_background_thread_before_mark_xid_done";
134
135 FLUSH LOGS;
136 INSERT INTO t1 VALUES (30, REPEAT("x", 4100));
137 SET DEBUG_SYNC= "now WAIT_FOR injected_binlog_background_thread";
138 SET GLOBAL debug_dbug= @old_dbug;
139 INSERT INTO t1 VALUES (31, REPEAT("x", 4100));
140 --source include/show_binary_logs.inc
141 SET debug_sync = 'reset';
142
143 SET GLOBAL max_binlog_size= @old_max_binlog_size;
144 SET GLOBAL innodb_flush_log_at_trx_commit= @old_innodb_flush_log_at_trx_commit;
145
146 --source include/shutdown_mysqld.inc
147 --source include/start_mysqld.inc
148
149
150 --echo *** MDEV-7402: 'reset master' hangs, waits for signalled COND_xid_list ***
151
152
153 connect(con3,localhost,root,,);
154 # Make the binlog background thread wait before clearing the pending checkpoint.
155 # The bug was that one RESET MASTER would clear the reset_master_pending
156 # flag set by another RESET MASTER; this could cause the wakeup from the
157 # binlog background thread not to be sent, and thus the second RESET MASTER
158 # to wait infinitely.
159 SET debug_sync="reset_logs_after_set_reset_master_pending SIGNAL reset_master_ready WAIT_FOR reset_master_cont";
160 send RESET MASTER;
161
162 --connection default
163 SET @old_dbug= @@global.DEBUG_DBUG;
164 SET GLOBAL debug_dbug="+d,inject_binlog_background_thread_before_mark_xid_done";
165 SET debug_sync="now WAIT_FOR reset_master_ready";
166 RESET MASTER;
167 SET debug_sync="now WAIT_FOR injected_binlog_background_thread";
168 SET GLOBAL debug_dbug=@old_dbug;
169 SET debug_sync="now SIGNAL reset_master_cont";
170
171 --connection con3
172 REAP;
173
174 --connection default
175 SET debug_sync = 'reset';
176
177 --echo *** MDEV-24660: MYSQL_BIN_LOG::cleanup(): Assertion `b->xid_count == 0' failed in MYSQL_BIN_LOG::cleanup
178 # Test a scenario of forcibly rolled back mixed engine "unsafe" transaction
179 # at shutdown. That should not let to the assert.
180
181 SET @old_max_binlog_size= @@global.max_binlog_size;
182 SET GLOBAL max_binlog_size= 4096;
183
184 --connect(con_24660,localhost,root,,)
185
186 # Construct an unsafe xa transaction that is rolled back
187 # in binlog at the shutdown time. That requires STATEMENT binlog format.
188 FLUSH LOGS;
189 --let $binlog_file = query_get_value(SHOW MASTER STATUS, File, 1)
190 SET @@session.binlog_format = STATEMENT;
191 CREATE TABLE tm (a INT) ENGINE = myisam;
192
193 call mtr.add_suppression("Table './test/tm' is marked as crashed");
194 call mtr.add_suppression("Checking table");
195
196 XA START 'xa1';
197 --let $a = `SELECT a + 1 FROM t1`
198 --eval INSERT INTO t1 VALUES ($a, 1)
199 INSERT INTO tm SET a = 1;
200 --inc $a
201 --let $repeat_x = `SELECT REPEAT("x", 4100)`
202 --disable_query_log
203 --eval INSERT INTO t1 VALUES ($a, "$repeat_x")
204 --enable_query_log
205 XA END 'xa1';
206
207 --connection default
208 # In the patch's base BBT would exit first to win the race against
209 # the XA transaction's binloging.
210 SET GLOBAL debug_dbug="+d,only_kill_system_threads_no_loop";
211 --source include/shutdown_mysqld.inc
212 --source include/start_mysqld.inc
213
214 --echo ** Proof of shutdown caused ROLLBACK-completed transaction
215
216 --let assert_file=$MYSQLTEST_VARDIR/tmp/binlog_decoded.out
217 --let datadir=`select @@datadir`
218
219 --echo # MYSQL_BINLOG datadir/binlog_file --result-file=assert_file
220 --exec $MYSQL_BINLOG $datadir/$binlog_file --result-file=$assert_file
221
222 --let $assert_text= No XA statements should be written into the binary log
223 --let $assert_count= 0
224 --let assert_select= XA START|XA END|XA PREPARE|XA COMMIT|XA ROLLBACK
225 --source include/assert_grep.inc
226
227 --let $assert_text= The transaction should be rolled back
228 --let $assert_count= 1
229 --let assert_select= ^ROLLBACK\$
230 --source include/assert_grep.inc
231
232 SELECT * FROM tm;
233 --eval SELECT * FROM t1 WHERE a = $a
234
235 # Clean up.
236 DROP TABLE t1, t2, tm;