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
6SET @old_max_binlog_size= @@global.max_binlog_size;
7SET GLOBAL max_binlog_size= 4096;
8SET @old_innodb_flush_log_at_trx_commit= @@global.innodb_flush_log_at_trx_commit;
9SET GLOBAL innodb_flush_log_at_trx_commit= 1;
10RESET MASTER;
11
12CREATE TABLE t1 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Innodb;
13CREATE 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.
18connect(con1,localhost,root,,);
19SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con1_ready WAIT_FOR con1_go";
20send INSERT INTO t1 VALUES (1, REPEAT("x", 4100));
21
22connection default;
23SET DEBUG_SYNC= "now WAIT_FOR con1_ready";
24# Let's add a few binlog rotations just for good measure.
25INSERT INTO t2 VALUES (1, REPEAT("x", 4100));
26INSERT 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
31SET DEBUG_SYNC= "execute_command_after_close_tables SIGNAL reset_master_done";
32send RESET MASTER;
33
34connect(con2,localhost,root,,);
35--echo This will timeout, as RESET MASTER is blocked
36SET DEBUG_SYNC= "now WAIT_FOR reset_master_done TIMEOUT 1";
37# Wake up transaction to allow RESET MASTER to complete.
38SET DEBUG_SYNC= "now SIGNAL con1_go";
39
40connection con1;
41reap;
42
43connection default;
44reap;
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
53connection con1;
54SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con1_ready WAIT_FOR con1_continue";
55send INSERT INTO t1 VALUES (20, REPEAT("x", 4100));
56
57connection default;
58SET DEBUG_SYNC= "now WAIT_FOR con1_ready";
59
60connection con2;
61SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con2_ready WAIT_FOR con2_continue";
62send INSERT INTO t1 VALUES (21, REPEAT("x", 4100));
63
64connection default;
65SET 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.
76SET DEBUG_SYNC= "RESET";
77SET @old_dbug= @@global.DEBUG_DBUG;
78SET GLOBAL debug_dbug="+d,binlog_background_checkpoint_processed";
79
80SET DEBUG_SYNC= "now SIGNAL con2_continue";
81
82connection con2;
83reap;
84
85connection 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.
89SET DEBUG_SYNC= "now WAIT_FOR binlog_background_checkpoint_processed";
90SET GLOBAL debug_dbug= @old_dbug;
91SET DEBUG_SYNC= "RESET";
92
93--let $binlog_file= master-bin.000003
94--source include/show_binlog_events.inc
95
96SET DEBUG_SYNC= "now SIGNAL con1_continue";
97
98connection con1;
99reap;
100
101connection 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
120connection 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
132SET @old_dbug= @@global.DEBUG_DBUG;
133SET GLOBAL debug_dbug="+d,inject_binlog_background_thread_before_mark_xid_done";
134
135FLUSH LOGS;
136INSERT INTO t1 VALUES (30, REPEAT("x", 4100));
137SET DEBUG_SYNC= "now WAIT_FOR injected_binlog_background_thread";
138SET GLOBAL debug_dbug= @old_dbug;
139INSERT INTO t1 VALUES (31, REPEAT("x", 4100));
140--source include/show_binary_logs.inc
141SET debug_sync = 'reset';
142
143
144--echo *** MDEV-7402: 'reset master' hangs, waits for signalled COND_xid_list ***
145
146--source include/wait_for_binlog_checkpoint.inc
147
148connect(con3,localhost,root,,);
149# Make the binlog background thread wait before clearing the pending checkpoint.
150# The bug was that one RESET MASTER would clear the reset_master_pending
151# flag set by another RESET MASTER; this could cause the wakeup from the
152# binlog background thread not to be sent, and thus the second RESET MASTER
153# to wait infinitely.
154SET debug_sync="reset_logs_after_set_reset_master_pending SIGNAL reset_master_ready WAIT_FOR reset_master_cont";
155send RESET MASTER;
156
157--connection default
158SET @old_dbug= @@global.DEBUG_DBUG;
159SET GLOBAL debug_dbug="+d,inject_binlog_background_thread_before_mark_xid_done";
160SET debug_sync="now WAIT_FOR reset_master_ready";
161RESET MASTER;
162SET debug_sync="now WAIT_FOR injected_binlog_background_thread";
163SET GLOBAL debug_dbug=@old_dbug;
164SET debug_sync="now SIGNAL reset_master_cont";
165
166--connection con3
167REAP;
168
169--connection default
170SET debug_sync = 'reset';
171
172
173# Clean up.
174DROP TABLE t1, t2;
175SET GLOBAL max_binlog_size= @old_max_binlog_size;
176SET GLOBAL innodb_flush_log_at_trx_commit= @old_innodb_flush_log_at_trx_commit;
177SET debug_sync = 'reset';
178