Skip to content

Commit 366f4f2

Browse files
committed
Fix that BACKUP STAGE BLOCK_COMMIT flushes binary log
1 parent fcd65b0 commit 366f4f2

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Test BACKUP STAGES BLOCK_COMMIT with binary logging on
3+
#
4+
SET BINLOG_FORMAT=MIXED;
5+
RESET MASTER;
6+
create table t1 (a int) engine=aria;
7+
insert into t1 values (1);
8+
BACKUP STAGE START;
9+
BACKUP STAGE BLOCK_COMMIT;
10+
SELECT @@gtid_binlog_pos;
11+
@@gtid_binlog_pos
12+
0-1-2
13+
BACKUP STAGE END;
14+
include/show_binlog_events.inc
15+
Log_name Pos Event_type Server_id End_log_pos Info
16+
master-bin.000001 # Gtid # # GTID #-#-#
17+
master-bin.000001 # Query # # use `test`; create table t1 (a int) engine=aria
18+
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
19+
master-bin.000001 # Query # # use `test`; insert into t1 values (1)
20+
master-bin.000001 # Query # # COMMIT
21+
drop table t1;

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--source include/have_log_bin.inc
2+
--source include/have_binlog_format_mixed.inc
3+
4+
--echo #
5+
--echo # Test BACKUP STAGES BLOCK_COMMIT with binary logging on
6+
--echo #
7+
8+
SET BINLOG_FORMAT=MIXED;
9+
RESET MASTER;
10+
11+
create table t1 (a int) engine=aria;
12+
insert into t1 values (1);
13+
14+
BACKUP STAGE START;
15+
BACKUP STAGE BLOCK_COMMIT;
16+
SELECT @@gtid_binlog_pos;
17+
BACKUP STAGE END;
18+
source include/show_binlog_events.inc;
19+
drop table t1;

sql/backup.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,14 @@ static bool backup_block_commit(THD *thd)
290290

291291
/* We can ignore errors from flush_tables () */
292292
(void) flush_tables(thd, FLUSH_SYS_TABLES);
293+
294+
if (mysql_bin_log.is_open())
295+
{
296+
mysql_mutex_lock(mysql_bin_log.get_log_lock());
297+
mysql_file_sync(mysql_bin_log.get_log_file()->file,
298+
MYF(MY_WME|MY_SYNC_FILESIZE));
299+
mysql_mutex_unlock(mysql_bin_log.get_log_lock());
300+
}
293301
thd->clear_error();
294302

295303
DBUG_RETURN(0);

0 commit comments

Comments
 (0)