Skip to content

Commit 473bdfa

Browse files
committed
MDEV-37541 Race of rolling back and committing transaction to binlog
This is the 1st of two commits to demonstrate the failure which is that a rolling back transaction while serializes its completion in Engine before a contender transaction the two are logged into binary log in reverse order.
1 parent 6058e02 commit 473bdfa

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
create table t1 (a int primary key, b text) engine=innodb;
2+
connect trx1_rollback,localhost,root,,;
3+
CREATE TABLE t_x (a int) engine=MEMORY;
4+
SET binlog_format=row;
5+
CREATE TEMPORARY TABLE tt_tmp ( id INT ) ENGINE = Memory;
6+
BEGIN;
7+
insert into t_x values (1);
8+
drop temporary table tt_tmp;
9+
insert into t1 values (99, "gotta log first");
10+
SET DEBUG_SYNC= 'reset';
11+
SET DEBUG_SYNC= "before_group_commit_queue WAIT_FOR trx1_go";
12+
ROLLBACK;
13+
connection default;
14+
insert into t1 values (99, "second best in binlog");
15+
select * from t1;
16+
a b
17+
99 second best in binlog
18+
SET DEBUG_SYNC= "now SIGNAL trx1_go";
19+
# Prove the logging order is Trx1, Trx2
20+
include/show_binlog_events.inc
21+
Log_name Pos Event_type Server_id End_log_pos Info
22+
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
23+
master-bin.000001 # Annotate_rows # # insert into t_x values (1)
24+
master-bin.000001 # Table_map # # table_id: # (test.t_x)
25+
master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
26+
master-bin.000001 # Query # # COMMIT
27+
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
28+
master-bin.000001 # Query # # use `test`; insert into t1 values (99, "second best in binlog")
29+
master-bin.000001 # Xid # # COMMIT /* XID */
30+
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
31+
master-bin.000001 # Annotate_rows # # insert into t1 values (99, "gotta log first")
32+
master-bin.000001 # Table_map # # table_id: # (test.t1)
33+
master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
34+
master-bin.000001 # Query # # ROLLBACK
35+
drop table t_x, t1;
36+
disconnect trx1_rollback;
37+
# end of the tests
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--source include/have_innodb.inc
2+
--source include/have_binlog_format_mixed.inc
3+
4+
create table t1 (a int primary key, b text) engine=innodb;
5+
6+
connect(trx1_rollback,localhost,root,,);
7+
CREATE TABLE t_x (a int) engine=MEMORY;
8+
9+
--let $master_file= query_get_value(SHOW MASTER STATUS, File, 1)
10+
--let $binlog_start=query_get_value(SHOW MASTER STATUS, Position, 1)
11+
SET binlog_format=row;
12+
CREATE TEMPORARY TABLE tt_tmp ( id INT ) ENGINE = Memory;
13+
BEGIN;
14+
insert into t_x values (1);
15+
drop temporary table tt_tmp;
16+
insert into t1 values (99, "gotta log first");
17+
18+
SET DEBUG_SYNC= 'reset';
19+
SET DEBUG_SYNC= "before_group_commit_queue WAIT_FOR trx1_go";
20+
21+
--send ROLLBACK
22+
23+
# trx2_commit
24+
connection default;
25+
insert into t1 values (99, "second best in binlog");
26+
select * from t1;
27+
28+
SET DEBUG_SYNC= "now SIGNAL trx1_go";
29+
30+
--echo # Prove the logging order is Trx1, Trx2
31+
--source include/show_binlog_events.inc
32+
33+
drop table t_x, t1;
34+
disconnect trx1_rollback;
35+
36+
--echo # end of the tests

sql/log.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8235,6 +8235,7 @@ MYSQL_BIN_LOG::queue_for_group_commit(group_commit_entry *orig_entry)
82358235
bool
82368236
MYSQL_BIN_LOG::write_transaction_to_binlog_events(group_commit_entry *entry)
82378237
{
8238+
DEBUG_SYNC(entry->thd, "before_group_commit_queue");
82388239
int is_leader= queue_for_group_commit(entry);
82398240
#ifdef WITH_WSREP
82408241
/* commit order was released in queue_for_group_commit() call,

0 commit comments

Comments
 (0)