Skip to content

Commit 9f7c25e

Browse files
author
Venkatesh Duggirala
committed
Bug#21420180 BINLOG_GROUP_COMMIT_SYNC_DELAY SHOULD BE CONSIDERED
ONLY WHEN SYNCING BINLOG Problem: binlog_group_commit_sync_delay is getting applied to every binary log commit group. Analysis: binlog_group_commit_sync_delay variable is introduced to control how many microseconds the binary log commit waits before synchronizing the binary log file to disk. sync_binlog variable is introduced to control the number of binary log commit groups to collect before synchronizing the binary log to disk In the current code, server is waiting for binlog_group_commit_sync_delay microseconds after entering into the sync stage of every group i.e., every leader of BGC group is waiting the specified time. In case of sync_binlog > 1 case or sync_binlog=0 case that every leader will not be doing 'sync' and users expectation will be that those groups that are doing sync will *only* hit the waiting period. Fix: wait_count_or_timeout logic should be protected in such a way that it will enter only if the sync stage is going to do the sync i.e., check if sync_counter reaches sync_binlog value, only then call the wait_count_or_timeout function.
1 parent e7b4849 commit 9f7c25e

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
SET GLOBAL binlog_group_commit_sync_delay=1000000;
2+
SET GLOBAL sync_binlog = 1;
23
SET @clock_in = SYSDATE();
34
CREATE TABLE t1 (c1 INT) Engine=InnoDB;
45
SET @elapsed = TIMESTAMPDIFF(MICROSECOND, @clock_in, SYSDATE());
56
include/assert.inc ["Assert that the statement never takes less than the delay set."]
7+
SET GLOBAL sync_binlog=1000;
8+
SET @clock_in = SYSDATE();
9+
SET @elapsed = TIMESTAMPDIFF(MICROSECOND, @clock_in, SYSDATE());
10+
include/assert.inc ["Assert that the above statements should not take more than 1000 seconds"]
611
SET GLOBAL binlog_group_commit_sync_delay=0;
12+
SET GLOBAL sync_binlog=1;
713
DROP TABLE t1;

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
--source include/have_binlog_format_mixed.inc
66

7-
--let $delay=1000000
8-
--let $delay_as_secs= `SELECT $delay / 1000000.0`
9-
107
--let $bgcd_saved=`SELECT @@GLOBAL.binlog_group_commit_sync_delay`
8+
--let $sync_binlog_saved=`SELECT @@GLOBAL.sync_binlog`
9+
10+
--let $delay=1000000
1111
--eval SET GLOBAL binlog_group_commit_sync_delay=$delay
12+
SET GLOBAL sync_binlog = 1;
1213

1314
SET @clock_in = SYSDATE();
1415
CREATE TABLE t1 (c1 INT) Engine=InnoDB;
@@ -18,6 +19,37 @@ SET @elapsed = TIMESTAMPDIFF(MICROSECOND, @clock_in, SYSDATE());
1819
--let $assert_cond= [SELECT @elapsed >= @@GLOBAL.binlog_group_commit_sync_delay]
1920
--source include/assert.inc
2021

22+
#
23+
# Bug#21420180 BINLOG_GROUP_COMMIT_SYNC_DELAY SHOULD BE CONSIDERED ONLY WHEN
24+
# SYNCING BINLOG
25+
#
26+
# Execute 1000 insertions (i.e., 1000 groups , one transaction per group).
27+
# Without the fix, it will take 1000 * binlog_group_commit_sync_delay which
28+
# is 1000 seconds (> 15 mints). Hence test script will be timed out.
29+
# But with fix, it should not take more than few seconds (that depends
30+
# on Pb2 machine speed and also depends on various build options too.
31+
#
32+
--let $group_count=1000
33+
--eval SET GLOBAL sync_binlog=$group_count
34+
--let $i=0
35+
36+
SET @clock_in = SYSDATE();
37+
--disable_query_log
38+
while ($i <= $group_count)
39+
{
40+
--eval INSERT INTO t1 VALUES ($i)
41+
--inc $i
42+
}
43+
--enable_query_log
44+
SET @elapsed = TIMESTAMPDIFF(MICROSECOND, @clock_in, SYSDATE());
45+
--let $assert_text="Assert that the above statements should not take more than 1000 seconds"
46+
--let $assert_cond= [SELECT @elapsed < 1000 * @@GLOBAL.binlog_group_commit_sync_delay]
47+
--source include/assert.inc
48+
49+
# End of Bug#21420180 test
50+
51+
# Cleanup
2152
--eval SET GLOBAL binlog_group_commit_sync_delay=$bgcd_saved
53+
--eval SET GLOBAL sync_binlog=$sync_binlog_saved
2254

2355
DROP TABLE t1;

sql/binlog.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -9047,10 +9047,15 @@ int MYSQL_BIN_LOG::ordered_commit(THD *thd, bool all, bool skip_commit)
90479047
DBUG_RETURN(finish_commit(thd));
90489048
}
90499049

9050-
/* Shall introduce a delay. */
9051-
stage_manager.wait_count_or_timeout(opt_binlog_group_commit_sync_no_delay_count,
9052-
opt_binlog_group_commit_sync_delay,
9053-
Stage_manager::SYNC_STAGE);
9050+
/*
9051+
Shall introduce a delay only if it is going to do sync
9052+
in this ongoing SYNC stage. The "+1" used below in the
9053+
if condition is to count the ongoing sync stage.
9054+
*/
9055+
if (!flush_error && (sync_counter + 1 >= get_sync_period()))
9056+
stage_manager.wait_count_or_timeout(opt_binlog_group_commit_sync_no_delay_count,
9057+
opt_binlog_group_commit_sync_delay,
9058+
Stage_manager::SYNC_STAGE);
90549059

90559060
final_queue= stage_manager.fetch_queue_for(Stage_manager::SYNC_STAGE);
90569061

0 commit comments

Comments
 (0)