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# References:
7#
8# MDEV-24526 binlog rotate via FLUSH LOGS may obsolate binlog file too eary
9#
10# The test for MDEV-24526 proves the fixes correct observed race condition
11# between a commiting transaction and FLUSH-LOGS.
12# The plot.
13# Trx_1 (con1) transaction binlogs first
14# to yield its turn acquiring LOCK_commit_ordered to Trx_2 and stand
15# still waiting of a signal that will never arrive.
16# Trx_2 can't acquire it in the fixed version even though
17# Trx_3 makes sure Trx_2 has reached a post-rotation execution point
18# to signal it to proceed.
19# Then the server gets crashed and Trx_1 must recover unlike
20# in the OLD buggy version.
21#
22SET GLOBAL innodb_flush_log_at_trx_commit= 1;
23RESET MASTER;
24
25CREATE TABLE t1 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Innodb;
26
27--echo *** Test that FLUSH LOGS waits if a transaction ordered commit is in progress.
28
29connect(con1,localhost,root,,);  # Trx_1
30# hang before doing acquiring Commit Ordered mutex
31SET DEBUG_SYNC= "commit_before_get_LOCK_commit_ordered SIGNAL con1_ready WAIT_FOR con1_go";
32
33--send INSERT INTO t1 VALUES (1, REPEAT("x", 1))
34
35connection default;              # Trx_2
36
37SET DEBUG_SYNC= "now WAIT_FOR con1_ready";
38SET DEBUG_SYNC= "rotate_after_rotate SIGNAL con_flush_ready WAIT_FOR default_go";
39--send FLUSH LOGS
40
41connect(con2,localhost,root,,);  # Trx_3
42--echo Trx_1 is not yet committed:
43SELECT count(*) as 'ZERO' from t1;
44
45--echo Wait for Trx_2 has rotated binlog:
46SET DEBUG_SYNC= "now WAIT_FOR con_flush_ready";
47# Useless signal to prove Trx_2 cannot race Trx_1's commit
48# even though Trx_1 never received the being waited 'con1_go'.
49SET DEBUG_SYNC= "now SIGNAL default_go";
50
51--let $shutdown_timeout=0
52--source include/restart_mysqld.inc
53
54connection default;
55--enable_reconnect
56--error 0,2013
57--reap
58
59--echo Must be tree logs in the list:
60--source include/show_binary_logs.inc
61--let $binlog_file= master-bin.000001
62--let $binlog_start= 4
63--source include/show_binlog_events.inc
64
65--echo Only one Binlog checkpoint must exist and point to master-bin.000001
66--let $binlog_file= master-bin.000002
67--let $binlog_start= 4
68--source include/show_binlog_events.inc
69
70
71# In the buggy server version the following select may have
72# resulted with ZERO:
73SELECT count(*) as 'ONE' from t1;
74
75# Clean up.
76connection default;
77
78DROP TABLE t1;
79SET debug_sync = 'reset';
80