MDEV-9544 FLUSH [RELAY] LOGS does not rotate logs for a named slave

Problem:- In the case of multisource replication/named slave
when we run "FLUSH LOGS" , it does not flush logs.

Solution:- A new function Master_info_index->flush_all_relay_logs()
is created which will rotate relay logs for all named slave.
This will be called in reload_acl_and_cache function when
connection_name.length == 0
This commit is contained in:
Sachin Setiya 2017-06-05 13:10:24 +05:30
parent 112b21da37
commit da61107fc8
6 changed files with 274 additions and 3 deletions

View file

@ -0,0 +1,22 @@
!include my.cnf
[mysqld.1]
log-bin
log-slave-updates
[mysqld.2]
log-bin
log-slave-updates
[mysqld.3]
log-bin
log-slave-updates
[mysqld.4]
server-id=4
log-bin=server4-bin
log-slave-updates
[ENV]
SERVER_MYPORT_4= @mysqld.4.port
SERVER_MYSOCK_4= @mysqld.4.socket

View file

@ -0,0 +1,78 @@
create database a;
use a;
create table t1(a int);
insert into t1 values(1);
create table t2(a int);
insert into t2 values(1);
create database b;
use b;
create table t1(a int);
insert into t1 values(1);
create table t2(a int);
insert into t2 values(1);
create database c;
use c;
create table t1(a int);
insert into t1 values(1);
create table t2(a int);
insert into t2 values(1);
change master 'm1' to master_port=MYPORT_1 , master_host='127.0.0.1', master_user='root';
change master 'm2' to master_port=MYPORT_2 , master_host='127.0.0.1', master_user='root';
change master to master_port=MYPORT_3 , master_host='127.0.0.1', master_user='root';
start all slaves;
set default_master_connection = 'm1';
include/wait_for_slave_to_start.inc
set default_master_connection = 'm2';
include/wait_for_slave_to_start.inc
set default_master_connection = '';
include/wait_for_slave_to_start.inc
use a;
show tables;
Tables_in_a
t1
t2
use b;
show tables;
Tables_in_b
t1
t2
use c;
show tables;
Tables_in_c
t1
t2
#TEST
SET default_master_connection = "m1";
SET default_master_connection = "m2";
SET default_master_connection = "";
flush logs;
SET default_master_connection = "m1";
#log Rotated
mysqld-relay-bin.000002
mysqld-relay-bin.000003
mysqld-relay-bin.index
SET default_master_connection = "m2";
#log Rotated
mysqld-relay-bin-m1.000002
mysqld-relay-bin-m1.000003
mysqld-relay-bin-m1.index
SET default_master_connection = "";
#log Rotated
mysqld-relay-bin-m2.000002
mysqld-relay-bin-m2.000003
mysqld-relay-bin-m2.index
#CleanUp
drop database a;
drop database b;
drop database c;
stop all slaves;
Warnings:
Note 1938 SLAVE 'm2' stopped
Note 1938 SLAVE '' stopped
Note 1938 SLAVE 'm1' stopped
SET default_master_connection = "m1";
include/wait_for_slave_to_stop.inc
SET default_master_connection = "m2";
include/wait_for_slave_to_stop.inc
SET default_master_connection = "";
include/wait_for_slave_to_stop.inc

View file

@ -0,0 +1,116 @@
--source include/not_embedded.inc
--source include/have_innodb.inc
--source include/have_debug.inc
--connect (server_1,127.0.0.1,root,,,$SERVER_MYPORT_1)
--connect (server_2,127.0.0.1,root,,,$SERVER_MYPORT_2)
--connect (server_3,127.0.0.1,root,,,$SERVER_MYPORT_3)
--connect (server_4,127.0.0.1,root,,,$SERVER_MYPORT_4)
--connection server_1
create database a;
use a;
create table t1(a int);
insert into t1 values(1);
create table t2(a int);
insert into t2 values(1);
--save_master_pos
--connection server_2
create database b;
use b;
create table t1(a int);
insert into t1 values(1);
create table t2(a int);
insert into t2 values(1);
--save_master_pos
--connection server_3
create database c;
use c;
create table t1(a int);
insert into t1 values(1);
create table t2(a int);
insert into t2 values(1);
--save_master_pos
--connection server_4
--disable_warnings
--replace_result $SERVER_MYPORT_1 MYPORT_1
eval change master 'm1' to master_port=$SERVER_MYPORT_1 , master_host='127.0.0.1', master_user='root';
--replace_result $SERVER_MYPORT_2 MYPORT_2
eval change master 'm2' to master_port=$SERVER_MYPORT_2 , master_host='127.0.0.1', master_user='root';
--replace_result $SERVER_MYPORT_3 MYPORT_3
eval change master to master_port=$SERVER_MYPORT_3 , master_host='127.0.0.1', master_user='root';
start all slaves;
set default_master_connection = 'm1';
--source include/wait_for_slave_to_start.inc
set default_master_connection = 'm2';
--source include/wait_for_slave_to_start.inc
set default_master_connection = '';
--source include/wait_for_slave_to_start.inc
--enable_warnings
--sync_with_master 0,'m1'
--sync_with_master 0,'m2'
--sync_with_master 0,''
use a;
show tables;
use b;
show tables;
use c;
show tables;
--echo #TEST
SET default_master_connection = "m1";
--let $old_m1 = query_get_value("show relaylog events;", "Log_name",1)
SET default_master_connection = "m2";
--let $old_m2 = query_get_value("show relaylog events;", "Log_name",1)
SET default_master_connection = "";
--let $old__ = query_get_value("show relaylog events;", "Log_name",1)
flush logs;
--sleep 2
--let $MYSQLD_DATADIR = `select @@datadir`
SET default_master_connection = "m1";
--let $new_m1 = query_get_value("show relaylog events;", "Log_name",1)
--if ($new_m1 != $old_m1) {
--echo #log Rotated
--exec ls $MYSQLD_DATADIR | grep "mysqld-relay-bin\."
}
SET default_master_connection = "m2";
--let $new_m2 = query_get_value("show relaylog events;", "Log_name",1)
--if ($new_m2 != $old_m2) {
--echo #log Rotated
--exec ls $MYSQLD_DATADIR | grep "mysqld-relay-bin-m1"
}
SET default_master_connection = "";
--let $new__ = query_get_value("show relaylog events;", "Log_name",1)
--if ($new__ != $old__) {
--echo #log Rotated
--exec ls $MYSQLD_DATADIR | grep "mysqld-relay-bin-m2"
}
--echo #CleanUp
--connection server_1
drop database a;
--save_master_pos
--connection server_2
drop database b;
--save_master_pos
--connection server_3
drop database c;
--save_master_pos
--connection server_4
--sync_with_master 0,'m1'
--sync_with_master 0,'m2'
--sync_with_master 0,''
stop all slaves;
SET default_master_connection = "m1";
--source include/wait_for_slave_to_stop.inc
SET default_master_connection = "m2";
--source include/wait_for_slave_to_stop.inc
SET default_master_connection = "";
--source include/wait_for_slave_to_stop.inc

View file

@ -41,7 +41,7 @@ Master_info::Master_info(LEX_STRING *connection_name_arg,
master_id(0), prev_master_id(0),
using_gtid(USE_GTID_NO), events_queued_since_last_gtid(0),
gtid_reconnect_event_skip_count(0), gtid_event_seen(false),
in_start_all_slaves(0), in_stop_all_slaves(0),
in_start_all_slaves(0), in_stop_all_slaves(0), in_flush_all_relay_logs(0),
users(0), killed(0)
{
host[0] = 0; user[0] = 0; password[0] = 0;
@ -1980,4 +1980,53 @@ void prot_store_ids(THD *thd, DYNAMIC_ARRAY *ids)
return;
}
bool Master_info_index::flush_all_relay_logs()
{
DBUG_ENTER("flush_all_relay_logs");
bool result= false;
int error= 0;
mysql_mutex_lock(&LOCK_active_mi);
for (uint i= 0; i< master_info_hash.records; i++)
{
Master_info *mi;
mi= (Master_info *) my_hash_element(&master_info_hash, i);
mi->in_flush_all_relay_logs= 0;
}
for (uint i=0; i < master_info_hash.records;)
{
Master_info *mi;
mi= (Master_info *)my_hash_element(&master_info_hash, i);
DBUG_ASSERT(mi);
if (mi->in_flush_all_relay_logs)
{
i++;
continue;
}
mi->in_flush_all_relay_logs= 1;
mysql_mutex_lock(&mi->sleep_lock);
mi->users++; // Mark used
mysql_mutex_unlock(&mi->sleep_lock);
mysql_mutex_unlock(&LOCK_active_mi);
mysql_mutex_lock(&mi->data_lock);
error= rotate_relay_log(mi);
mysql_mutex_unlock(&mi->data_lock);
mi->release();
mysql_mutex_lock(&LOCK_active_mi);
if (error)
{
result= true;
break;
}
/* Restart from first element as master_info_hash may have changed */
i= 0;
continue;
}
mysql_mutex_unlock(&LOCK_active_mi);
DBUG_RETURN(result);
}
#endif /* HAVE_REPLICATION */

View file

@ -302,6 +302,7 @@ class Master_info : public Slave_reporting_capability
/* gtid_event_seen is false until we receive first GTID event from master. */
bool gtid_event_seen;
bool in_start_all_slaves, in_stop_all_slaves;
bool in_flush_all_relay_logs;
uint users; /* Active user for object */
uint killed;
@ -354,6 +355,7 @@ public:
bool start_all_slaves(THD *thd);
bool stop_all_slaves(THD *thd);
void free_connections();
bool flush_all_relay_logs();
};

View file

@ -181,8 +181,12 @@ bool reload_acl_and_cache(THD *thd, unsigned long long options,
slave is not likely to have the same connection names.
*/
tmp_write_to_binlog= 0;
if (!(mi= (get_master_info(&connection_name,
if (connection_name.length == 0)
{
if (master_info_index->flush_all_relay_logs())
*write_to_binlog= -1;
}
else if (!(mi= (get_master_info(&connection_name,
Sql_condition::WARN_LEVEL_ERROR))))
{
result= 1;