Skip to content

Commit f5a07d0

Browse files
author
Maitrayi Sabaratnam
committed
Cherrypick from 5.6 : Bug#20009154 - FIX REGRESSION AFTER HA_FLUSH_LOGS() HOOK FOR NDB IS REMOVED.
1 parent f0c0859 commit f5a07d0

File tree

6 files changed

+106
-4
lines changed

6 files changed

+106
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
SET @default_max_binlog_size = @@global.max_binlog_size;
2+
set global max_binlog_size=1048576;
3+
create table test.tn (b varchar(1000)) engine=ndb;
4+
create procedure create_load(loops int)
5+
begin
6+
set @x = 0;
7+
repeat
8+
insert into tn values (repeat('C', 100));
9+
insert into tn values (repeat('C', 100));
10+
insert into tn values (repeat('C', 100));
11+
insert into tn values (repeat('C', 100));
12+
insert into tn values (repeat('C', 100));
13+
insert into tn values (repeat('C', 100));
14+
insert into tn values (repeat('C', 100));
15+
insert into tn values (repeat('C', 100));
16+
insert into tn values (repeat('C', 100));
17+
insert into tn values (repeat('C', 100));
18+
delete from tn;
19+
set @x = @x + 1;
20+
until @x = loops
21+
end repeat;
22+
end%
23+
call create_load(20);
24+
FLUSH LOGS;
25+
drop procedure create_load;
26+
drop table tn;
27+
set global max_binlog_size= @default_max_binlog_size;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
-- source include/have_ndb.inc
2+
-- source include/have_binlog_format_mixed_or_row.inc
3+
4+
#
5+
# Test whether FLUSH LOGS flushes upto
6+
# session_last_committed_epoch to Binlog.
7+
#
8+
9+
# Set Binlog size large enough to avoid size-based rotate
10+
SET @default_max_binlog_size = @@global.max_binlog_size;
11+
set global max_binlog_size=1048576; #1MB
12+
13+
create table test.tn (b varchar(1000)) engine=ndb;
14+
15+
# Method to generate load on NDB
16+
delimiter %;
17+
create procedure create_load(loops int)
18+
begin
19+
set @x = 0;
20+
repeat
21+
insert into tn values (repeat('C', 100));
22+
insert into tn values (repeat('C', 100));
23+
insert into tn values (repeat('C', 100));
24+
insert into tn values (repeat('C', 100));
25+
insert into tn values (repeat('C', 100));
26+
insert into tn values (repeat('C', 100));
27+
insert into tn values (repeat('C', 100));
28+
insert into tn values (repeat('C', 100));
29+
insert into tn values (repeat('C', 100));
30+
insert into tn values (repeat('C', 100));
31+
delete from tn;
32+
set @x = @x + 1;
33+
until @x = loops
34+
end repeat;
35+
end%
36+
delimiter ;%
37+
38+
# Generate much load on NDB in order to make Binlog to lag behind
39+
--disable_result_log
40+
call create_load(20);
41+
--enable_result_log
42+
43+
# Get the last committed epoch of the session
44+
--source ndb_binlog_init_epoch_vals.inc
45+
let $session_epoch= query_get_value(select @init_session_epoch as e, e, 1);
46+
47+
# Flush Binlog
48+
FLUSH LOGS;
49+
50+
# Get the maximum epoch written to Binlog
51+
let $max_epoch_after_flush = `select max(epoch) as epoch from
52+
mysql.ndb_binlog_index`;
53+
54+
if ($max_epoch_after_flush < $session_epoch)
55+
{
56+
--echo
57+
--echo Max epoch found in Binlog after FLUSH LOGS ($max_epoch_after_flush)
58+
--echo is less than the last committed epoch of the session
59+
($session_epoch)
60+
--echo
61+
die "FLUSH LOGS failed to flush upto the last committed epoch of the
62+
session";
63+
}
64+
65+
drop procedure create_load;
66+
drop table tn;
67+
68+
set global max_binlog_size= @default_max_binlog_size;

sql/binlog.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -5484,12 +5484,19 @@ void MYSQL_BIN_LOG::purge()
54845484
@retval
54855485
nonzero - error in rotating routine.
54865486
*/
5487-
int MYSQL_BIN_LOG::rotate_and_purge(bool force_rotate)
5487+
int MYSQL_BIN_LOG::rotate_and_purge(THD* thd, bool force_rotate)
54885488
{
54895489
int error= 0;
54905490
DBUG_ENTER("MYSQL_BIN_LOG::rotate_and_purge");
54915491
bool check_purge= false;
54925492

5493+
/*
5494+
Wait for handlerton to insert any pending information into the binlog.
5495+
For e.g. ha_ndbcluster which updates the binlog asynchronously this is
5496+
needed so that the user see its own commands in the binlog.
5497+
*/
5498+
ha_binlog_wait(thd);
5499+
54935500
DBUG_ASSERT(!is_relay_log);
54945501
mysql_mutex_lock(&LOCK_log);
54955502
error= rotate(force_rotate, &check_purge);

sql/binlog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
619619
int remove_logs_from_index(LOG_INFO* linfo, bool need_update_threads);
620620
int rotate(bool force_rotate, bool* check_purge);
621621
void purge();
622-
int rotate_and_purge(bool force_rotate);
622+
int rotate_and_purge(THD* thd, bool force_rotate);
623623
/**
624624
Flush binlog cache and synchronize to disk.
625625

sql/sql_reload.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ bool reload_acl_and_cache(THD *thd, unsigned long options,
163163
tmp_write_to_binlog= 0;
164164
if (mysql_bin_log.is_open())
165165
{
166-
if (mysql_bin_log.rotate_and_purge(true))
166+
if (mysql_bin_log.rotate_and_purge(thd, true))
167167
*write_to_binlog= -1;
168168
}
169169
}

sql/sys_vars.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,7 @@ class Sys_var_gtid_purged : public sys_var
21982198
previous_gtid_logged, current_gtid_logged);
21992199

22002200
// Rotate logs to have Previous_gtid_event on last binlog.
2201-
rotate_res= mysql_bin_log.rotate_and_purge(true);
2201+
rotate_res= mysql_bin_log.rotate_and_purge(thd, true);
22022202
if (rotate_res)
22032203
{
22042204
error= true;

0 commit comments

Comments
 (0)