diff options
author | Manish Kumar <manish.4.kumar@oracle.com> | 2012-02-28 14:02:27 +0530 |
---|---|---|
committer | Manish Kumar <manish.4.kumar@oracle.com> | 2012-02-28 14:02:27 +0530 |
commit | 9e048a6bc556f909613cca1fa9b9007ec3546092 (patch) | |
tree | 9774748c4ef8ccbaec37ddc401f9721cc4bc77e3 | |
parent | 2367e79e4c531c74a8f1da8107f955c4cae48f49 (diff) | |
parent | 26c9f1da82906532d5f132b5fa9f4ab9425d687e (diff) | |
download | mariadb-git-9e048a6bc556f909613cca1fa9b9007ec3546092.tar.gz |
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.
-rw-r--r-- | mysql-test/include/show_slave_hosts.inc | 3 | ||||
-rw-r--r-- | mysql-test/r/mysqld--help-notwin.result | 2 | ||||
-rw-r--r-- | mysql-test/suite/rpl/r/rpl_report_port.result | 15 | ||||
-rw-r--r-- | mysql-test/suite/rpl/r/rpl_show_slave_hosts.result | 2 | ||||
-rw-r--r-- | mysql-test/suite/rpl/t/rpl_report_port-slave.opt | 1 | ||||
-rw-r--r-- | mysql-test/suite/rpl/t/rpl_report_port.test | 59 | ||||
-rw-r--r-- | mysql-test/suite/rpl/t/rpl_show_slave_hosts.test | 1 | ||||
-rw-r--r-- | mysql-test/suite/sys_vars/t/report_port_basic.test | 11 | ||||
-rw-r--r-- | sql/mysqld.cc | 7 | ||||
-rw-r--r-- | sql/sys_vars.cc | 2 |
10 files changed, 94 insertions, 9 deletions
diff --git a/mysql-test/include/show_slave_hosts.inc b/mysql-test/include/show_slave_hosts.inc new file mode 100644 index 00000000000..e27c1bfb09c --- /dev/null +++ b/mysql-test/include/show_slave_hosts.inc @@ -0,0 +1,3 @@ +--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; diff --git a/mysql-test/r/mysqld--help-notwin.result b/mysql-test/r/mysqld--help-notwin.result index 3df31eeebd5..36649cf761d 100644 --- a/mysql-test/r/mysqld--help-notwin.result +++ b/mysql-test/r/mysqld--help-notwin.result @@ -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 diff --git a/mysql-test/suite/rpl/r/rpl_report_port.result b/mysql-test/suite/rpl/r/rpl_report_port.result new file mode 100644 index 00000000000..d5a684241bc --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_report_port.result @@ -0,0 +1,15 @@ +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 diff --git a/mysql-test/suite/rpl/r/rpl_show_slave_hosts.result b/mysql-test/suite/rpl/r/rpl_show_slave_hosts.result index 2ada5670e04..16d71e125ab 100644 --- a/mysql-test/suite/rpl/r/rpl_show_slave_hosts.result +++ b/mysql-test/suite/rpl/r/rpl_show_slave_hosts.result @@ -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; diff --git a/mysql-test/suite/rpl/t/rpl_report_port-slave.opt b/mysql-test/suite/rpl/t/rpl_report_port-slave.opt new file mode 100644 index 00000000000..ffe2b2e7016 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_report_port-slave.opt @@ -0,0 +1 @@ +--report-port= diff --git a/mysql-test/suite/rpl/t/rpl_report_port.test b/mysql-test/suite/rpl/t/rpl_report_port.test new file mode 100644 index 00000000000..11cb9684090 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_report_port.test @@ -0,0 +1,59 @@ +# +#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 diff --git a/mysql-test/suite/rpl/t/rpl_show_slave_hosts.test b/mysql-test/suite/rpl/t/rpl_show_slave_hosts.test index 105f1873659..7ba5e90b96d 100644 --- a/mysql-test/suite/rpl/t/rpl_show_slave_hosts.test +++ b/mysql-test/suite/rpl/t/rpl_show_slave_hosts.test @@ -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; diff --git a/mysql-test/suite/sys_vars/t/report_port_basic.test b/mysql-test/suite/sys_vars/t/report_port_basic.test index 122c92c5446..903289230bd 100644 --- a/mysql-test/suite/sys_vars/t/report_port_basic.test +++ b/mysql-test/suite/sys_vars/t/report_port_basic.test @@ -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 diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 23992e8db41..6cf173266ca 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -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; diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 693beb87b8a..f15664bca10 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -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( |