Skip to content

Commit

Permalink
FB8-201: Add semi sync and replication status to SHOW SLAVE HOSTS (fa…
Browse files Browse the repository at this point in the history
…cebook#1096) (facebook#1096)

Summary:
Jira issue: https://jira.percona.com/browse/FB8-201

Reference Patch: facebook@b5ad812f53e
Reference Patch: facebook@cc1081494bf

Add two additional columns to "show slave hosts": Is_semi_sync_slave and Replication_status.

Pull Request resolved: facebook#1096

Reviewed By: lloyd

Differential Revision: D19525150

Pulled By: hui80
  • Loading branch information
Hui Liu authored and inikep committed Jan 17, 2022
1 parent 257643a commit 85e8cd1
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 28 deletions.
11 changes: 10 additions & 1 deletion mysql-test/include/show_slave_hosts.inc
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
--replace_result $SLAVE_MYPORT SLAVE_PORT $DEFAULT_MASTER_PORT DEFAULT_PORT
let $repl_status_semisync=`SELECT info FROM information_schema.processlist WHERE info like 'Semisync%' limit 1`;
if (!$repl_status_semisync) {
let $repl_status_semisync=CANNOTFIND;
}
let $repl_status_async=`SELECT info FROM information_schema.processlist WHERE info like 'Async%' limit 1`;
if (!$repl_status_async) {
let $repl_status_async=CANNOTFIND;
}

--replace_result $SLAVE_MYPORT SLAVE_PORT $DEFAULT_MASTER_PORT DEFAULT_PORT $repl_status_semisync REPL_STATUS_SEMISYNC $repl_status_async REPL_STATUS_ASYNC
--replace_regex /[0-9, a-f]{8}-[0-9, a-f]{4}-[0-9, a-f]{4}-[0-9, a-f]{4}-[0-9, a-f]{12}/SLAVE_UUID/
SHOW SLAVE HOSTS;
2 changes: 1 addition & 1 deletion mysql-test/r/disabled_replication.result
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ERROR HY000: You are not using binary logging
SHOW MASTER STATUS;
File Position Binlog_Do_DB Binlog_Ignore_DB Executed_Gtid_Set
SHOW SLAVE HOSTS;
Server_id Host Port Master_id Slave_UUID
Server_id Host Port Master_id Slave_UUID Is_semi_sync_slave Replication_status
Warnings:
Warning 1287 'SHOW SLAVE HOSTS' is deprecated and will be removed in a future release. Please use SHOW REPLICAS instead
RESET MASTER;
Expand Down
18 changes: 13 additions & 5 deletions mysql-test/suite/rpl/r/rpl_show_slave_hosts.result
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Warnings:
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
Note #### Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
[connection master]
call mtr.add_suppression("A message intended for a client cannot be sent there as no client-session is attached");
[connection slave2]
RESET SLAVE;
Warnings:
Warning 1287 'RESET SLAVE' is deprecated and will be removed in a future release. Please use RESET REPLICA instead
Expand All @@ -14,18 +16,24 @@ START SLAVE IO_THREAD;
Warnings:
Warning 1287 'START SLAVE' is deprecated and will be removed in a future release. Please use START REPLICA instead
include/wait_for_slave_io_to_start.inc
[connection master]
CREATE TABLE t1 (data LONGBLOB);
INSERT INTO t1 (data) VALUES (repeat('a',1024*1024));
DROP TABLE t1;
SHOW SLAVE HOSTS;
Server_id Host Port Master_id Slave_UUID
2 SLAVE_PORT 1 SLAVE_UUID
3 slave2 SLAVE_PORT 1 SLAVE_UUID
Server_id Host Port Master_id Slave_UUID Is_semi_sync_slave Replication_status
2 SLAVE_PORT 1 SLAVE_UUID 1 REPL_STATUS_SEMISYNC
3 slave2 SLAVE_PORT 1 SLAVE_UUID 0 REPL_STATUS_ASYNC
Warning 1287 SLAVE_PORT
Warnings:
[connection slave2]
include/stop_slave_io.inc
[connection master]
CREATE TABLE t1(a int);
DROP TABLE t1;
SHOW SLAVE HOSTS;
Server_id Host Port Master_id Slave_UUID
2 SLAVE_PORT 1 SLAVE_UUID
Server_id Host Port Master_id Slave_UUID Is_semi_sync_slave Replication_status
2 SLAVE_PORT 1 SLAVE_UUID 1 REPL_STATUS_SEMISYNC
Warnings:
Warning 1287 'SHOW SLAVE HOSTS' is deprecated and will be removed in a future release. Please use SHOW REPLICAS instead
include/rpl_end.inc
1 change: 1 addition & 0 deletions mysql-test/suite/rpl/t/rpl_show_slave_hosts-master.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$SEMISYNC_MASTER_PLUGIN_OPT $SEMISYNC_MASTER_PLUGIN_LOAD
1 change: 1 addition & 0 deletions mysql-test/suite/rpl/t/rpl_show_slave_hosts-slave.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$SEMISYNC_SLAVE_PLUGIN_OPT $SEMISYNC_SLAVE_PLUGIN_LOAD
2 changes: 2 additions & 0 deletions mysql-test/suite/rpl/t/rpl_show_slave_hosts.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
# instances when MTR runs rpl tests with parallel 4 or more.

[mysqld.1]
rpl_semi_sync_master_enabled=1
server_id=1

[mysqld.2]
rpl_semi_sync_slave_enabled=1
server_id=2
report-host=
report-user=
Expand Down
45 changes: 27 additions & 18 deletions mysql-test/suite/rpl/t/rpl_show_slave_hosts.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,54 @@
# implemented.
#######################################################################
--source include/not_group_replication_plugin.inc
source include/master-slave.inc;
connect (slave2,127.0.0.1,root,,test,$SLAVE_MYPORT2,);
--source include/have_debug_sync.inc
--source include/master-slave.inc

connection slave2;
call mtr.add_suppression("A message intended for a client cannot be sent there as no client-session is attached");

--connect (slave2,127.0.0.1,root,,test,$SLAVE_MYPORT2,)

--source include/rpl_connection_slave2.inc
RESET SLAVE;
--replace_result $MASTER_MYPORT MASTER_PORT
--replace_column 2 ####
--eval CHANGE REPLICATION SOURCE TO SOURCE_HOST='127.0.0.1',SOURCE_PORT=$MASTER_MYPORT,SOURCE_USER='root'
START SLAVE IO_THREAD;
source include/wait_for_slave_io_to_start.inc;

connection master;
let $show_statement= SHOW SLAVE HOSTS;
let $field= Server_id;
--source include/rpl_connection_master.inc

CREATE TABLE t1 (data LONGBLOB);
INSERT INTO t1 (data) VALUES (repeat('a',1024*1024));
DROP TABLE t1;

--let $show_statement= SHOW SLAVE HOSTS
--let $field= Server_id
# 3 is server_id of slave2.
let $condition= ='3';
source include/wait_show_condition.inc;
--let $condition= ='3'
--source include/wait_show_condition.inc
--replace_column 3 'SLAVE_PORT'
--replace_result $SLAVE_MYPORT SLAVE_PORT $DEFAULT_MASTER_PORT DEFAULT_PORT
--sorted_result
source include/show_slave_hosts.inc;
--source include/show_slave_hosts.inc

connection slave2;
--source include/rpl_connection_slave2.inc
--source include/stop_slave_io.inc

connection master;
--source include/rpl_connection_master.inc

# Run dummy DDL to wake up dump thread and detect the disconnected slave
CREATE TABLE t1(a int);
DROP TABLE t1;

let $show_statement= SHOW SLAVE HOSTS;
let $field= Server_id;
--let $show_statement= SHOW SLAVE HOSTS
--let $field= Server_id
# 3 is server_id of slave2.
let $condition= <> '3';
--let $condition= <> '3'
# All rows of 'SHOW SLAVE HOSTS' are not equal to 3. It mean that master has
# knew the leave of slave2 and has unregistered it.
let $wait_for_all= 1;
source include/wait_show_condition.inc;
source include/show_slave_hosts.inc;
--let $wait_for_all= 1
--source include/wait_show_condition.inc
--source include/show_slave_hosts.inc

--disconnect slave2
--source include/rpl_end.inc
4 changes: 2 additions & 2 deletions mysql-test/suite/rpl_nogtid/r/rpl_mixed_ddl_dml.result
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ n
2001
2002
SHOW SLAVE HOSTS;
Server_id Host Port Master_id Slave_UUID
2 127.0.0.1 SLAVE_PORT 1 SLAVE_UUID
Server_id Host Port Master_id Slave_UUID Is_semi_sync_slave Replication_status
2 127.0.0.1 SLAVE_PORT 1 SLAVE_UUID 0 REPL_STATUS_ASYNC
Warnings:
Warning 1287 'SHOW SLAVE HOSTS' is deprecated and will be removed in a future release. Please use SHOW REPLICAS instead
drop table t1;
Expand Down
2 changes: 1 addition & 1 deletion sql/rpl_binlog_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void Binlog_sender::cleanup() {
my_eof(thd);
}

static bool is_semi_sync_slave() {
bool is_semi_sync_slave() {
long long val = 0;
get_user_var_int("rpl_semi_sync_slave", &val, nullptr);
return val;
Expand Down
11 changes: 11 additions & 0 deletions sql/rpl_master.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ bool show_slave_hosts(THD *thd) {
field_list.push_back(new Item_return_int("Port", 7, MYSQL_TYPE_LONG));
field_list.push_back(new Item_return_int("Source_Id", 10, MYSQL_TYPE_LONG));
field_list.push_back(new Item_empty_string("Replica_UUID", UUID_LENGTH));
field_list.push_back(
new Item_return_int("Is_semi_sync_slave", 7, MYSQL_TYPE_LONG));
field_list.push_back(new Item_empty_string("Replication_status", 20));

// TODO: once the old syntax is removed, remove this as well.
if (thd->lex->is_replication_deprecated_syntax_used())
Expand Down Expand Up @@ -259,6 +262,14 @@ bool show_slave_hosts(THD *thd) {
String slave_uuid;
if (get_slave_uuid(si->thd, &slave_uuid))
protocol->store(slave_uuid.c_ptr_safe(), &my_charset_bin);
protocol->store(is_semi_sync_slave(si->thd, /*need_lock*/ true));
mysql_mutex_lock(&si->thd->LOCK_thd_query);
LEX_CSTRING replication_status = si->thd->query();
if (replication_status.length)
protocol->store(replication_status.str, &my_charset_bin);
else
protocol->store("", &my_charset_bin);
mysql_mutex_unlock(&si->thd->LOCK_thd_query);
if (protocol->end_row()) {
mysql_mutex_unlock(&LOCK_slave_list);
return true;
Expand Down

0 comments on commit 85e8cd1

Please sign in to comment.