Commit 9e048a6b authored by Manish Kumar's avatar Manish Kumar

BUG#13333431 - INCORRECT DEFAULT PORT IN 'SHOW SLAVE HOSTS' OUTPUT

Problem - The default port number shown in SHOW SLAVE HOSTS is always 3306 
          though the slave is actually listening on a different port number.
          This is a problem as the user can not be sure whether this port 
          value can be trusted and so client trying to read replication 
          topology can get confused.

Fix - 3306 ceases to be the default value of report-port. Moreover report-port
      does not have a static default any longer.
      Instead we initialize report-port to 0 as the new default value and change
      it based on two checks :

      1) If report_port is not set, the slave reports the port number its listening 
         on. (i.e. if report-port is not set we get the actual value of the slave's 
         port number).

      2) If report-port is set, we show the value report-port is set to, as the slave's
         port number.

mysql-test/include/show_slave_hosts.inc:
  A .inc file is added to use show slave hosts in the new test added.
mysql-test/r/mysqld--help-notwin.result:
  Updated the result file to show the default value passed for report-port.
mysql-test/suite/rpl/r/rpl_report_port.result:
  The result file for the new test that is added.
mysql-test/suite/rpl/r/rpl_show_slave_hosts.result:
  Updated the result file to show the default value passed for report-port.
mysql-test/suite/rpl/t/rpl_report_port-slave.opt:
  Option file for the new test added.
mysql-test/suite/rpl/t/rpl_report_port.test:
  Added a test to check the correct functionality of report-port. 
  We check this by running the replication twice. 
          
  In the first run we do not set the value of report-port through the opt file 
  and get the actual port number of the slave's port.
          
  We then restart the server with report-port set to some value (in this case 9000)
  and check the value reported for the slave's port number.
mysql-test/suite/sys_vars/t/report_port_basic.test:
  Update the test file to show the value for report-port. It is replaced with
  SLAVE_PORT as the actual value of the report-port will change with each run.
sql/mysqld.cc:
  Changed the value reported by report port :
          
  1. If the value for report-port is not set we assign report-port to be the 
     actual port number of the slave (mysqld_port).
  
  2. If report-port is set we get the value set for the report-port.
sql/sys_vars.cc:
  Passed 0 as the default value of the report-port.
parents 2367e79e 26c9f1da
--replace_result $SLAVE_MYPORT SLAVE_PORT $DEFAULT_MASTER_PORT DEFAULT_PORT
--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;
......@@ -915,7 +915,7 @@ relay-log-space-limit 0
replicate-same-server-id FALSE
report-host (No default value)
report-password (No default value)
report-port 3306
report-port 0
report-user (No default value)
rpl-recovery-rank 0
safe-user-create FALSE
......
include/master-slave.inc
[connection master]
[The default value shown for the slave's port number is the actual port number of the slave]
SHOW SLAVE HOSTS;
Server_id Host Port Master_id
2 127.0.0.1 SLAVE_PORT 1
[The default value shown for the slave's port number is the actual port number of the slave]
include/rpl_restart_server.inc [server_number=2 parameters: --report-port=9000]
include/start_slave.inc
[Slave restarted with the report-port set to some value]
[The value shown for the slave's port number is 9000 which is the value set for report-port]
SHOW SLAVE HOSTS;
Server_id Host Port Master_id
2 127.0.0.1 9000 1
include/rpl_end.inc
......@@ -6,7 +6,7 @@ START SLAVE IO_THREAD;
include/wait_for_slave_io_to_start.inc
SHOW SLAVE HOSTS;
Server_id Host Port Master_id
3 slave2 DEFAULT_PORT 1
3 slave2 SLAVE_PORT 1
2 SLAVE_PORT 1
include/stop_slave_io.inc
SHOW SLAVE HOSTS;
......
#
#BUG#13333431 : INCORRECT DEFAULT PORT IN 'SHOW SLAVE HOSTS' OUTPUT
#
# ==== Purpose ====
#
# The test show the default value printed for the slave's port number if the
# --report-port= <some value> is not set on the slave. This is different from
# the present scenario which show 3306 as the default value if the report-port
# is not set on the slave.
#
#====Method====
#
# Start replication with report port not set.This will give the actual port
# number of the slave (ie. SLAVE_PORT) for the on doing SHOW SLAVE HOSTS on
# the master.
# Restart the slave server with report port set to 9000 and start the slave.
# In this case on doing SHOW SLAVE HOSTS on the master, we get the port number
# of the slave to be 9000.
source include/master-slave.inc;
connection master;
--echo [The default value shown for the slave's port number is the actual port number of the slave]
source include/show_slave_hosts.inc;
# SLAVE_PORT is the value of the port we should get.
let $show_statement= SHOW SLAVE HOSTS;
let $field= Port;
let $condition= 'SLAVE_PORT';
source include/wait_show_condition.inc;
--echo [The default value shown for the slave's port number is the actual port number of the slave]
# Start the server with some value being passed to the report_port= <option>
# this will be used incase we have to mask the value of the slave's port
# number in certain situations.
--let $rpl_server_number= 2
--let $rpl_server_parameters= --report-port=9000
--source include/rpl_restart_server.inc
connection slave;
--source include/start_slave.inc
--echo [Slave restarted with the report-port set to some value]
connection master;
--echo [The value shown for the slave's port number is 9000 which is the value set for report-port]
--source include/show_slave_hosts.inc
# 9000 is the value of the port we should get.
let $show_statement= SHOW SLAVE HOSTS;
let $field= Port;
let $condition= '9000';
source include/wait_show_condition.inc;
--source include/rpl_end.inc
......@@ -25,6 +25,7 @@ let $field= Server_id;
# 3 is server_id of slave2.
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
SHOW SLAVE HOSTS;
......
......@@ -2,18 +2,19 @@
#
# only global
#
--replace_result $DEFAULT_MASTER_PORT DEFAULT_MASTER_PORT
--replace_regex s/[0-9]+/DEFAULT_MASTER_PORT/
select @@global.report_port;
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
select @@session.report_port;
--replace_result $DEFAULT_MASTER_PORT DEFAULT_MASTER_PORT
--replace_column 2 'DEFAULT_MASTER_PORT'
show global variables like 'report_port';
--replace_result $DEFAULT_MASTER_PORT DEFAULT_MASTER_PORT
--replace_column 2 'DEFAULT_MASTER_PORT'
show session variables like 'report_port';
--replace_result $DEFAULT_MASTER_PORT DEFAULT_MASTER_PORT
--replace_column 2 'DEFAULT_MASTER_PORT'
select * from information_schema.global_variables where variable_name='report_port';
--replace_result $DEFAULT_MASTER_PORT DEFAULT_MASTER_PORT
--replace_column 2 'DEFAULT_MASTER_PORT'
select * from information_schema.session_variables where variable_name='report_port';
--replace_column 2 'DEFAULT_MASTER_PORT'
#
# show that it's read-only
......
......@@ -656,7 +656,7 @@ int mysqld_server_started= 0;
File_parser_dummy_hook file_parser_dummy_hook;
/* replication parameters, if master_host is not NULL, we are a slave */
uint report_port= MYSQL_PORT;
uint report_port= 0;
ulong master_retry_count=0;
char *master_info_file;
char *relay_log_info_file, *report_user, *report_password, *report_host;
......@@ -1784,6 +1784,11 @@ static void network_init(void)
set_ports();
if (report_port == 0)
{
report_port= mysqld_port;
}
DBUG_ASSERT(report_port != 0);
if (mysqld_port != 0 && !opt_disable_networking && !opt_bootstrap)
{
struct addrinfo *ai, *a;
......
......@@ -2768,7 +2768,7 @@ static Sys_var_uint Sys_repl_report_port(
"port or if you have a special tunnel from the master or other clients "
"to the slave. If not sure, leave this option unset",
READ_ONLY GLOBAL_VAR(report_port), CMD_LINE(REQUIRED_ARG),
VALID_RANGE(0, UINT_MAX), DEFAULT(MYSQL_PORT), BLOCK_SIZE(1));
VALID_RANGE(0, UINT_MAX), DEFAULT(0), BLOCK_SIZE(1));
#endif
static Sys_var_mybool Sys_keep_files_on_create(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment