Skip to content

Commit 262e997

Browse files
author
Srikanth B R
committed
Bug#31005815 MTR: ALLOCATE PORTS FOR THE MYSQLD ADMIN INTERFACE
The mysql server allows a separate administrative connection channel to privileged administrators( having SERVICE_CONNECTION_ADMIN) where in the max_connections limit doesn't apply. In MTR, there is no port reserved for the admin interface. For tests which use the admin channel, a workaround to use the very next port which mysqld uses is currently being employed. This works for tests which use a single mysqld server but is not ideal and there is a need to support this mechanism within MTR itself. The patch adds a dedicated port for each mysqld server which can be used for the admin interface and updates tests which have the workaround to use the allocated port. Please note that this change only sets --admin-port but not --admin-address so that the admin channel is not setup by default and doesn't affect the test suite. Any test which requires the admin interface can set the option --admin-address to enable the admin interface. Change-Id: I1b9ece250d2fd28531c61f69dbb889d9fe14447f
1 parent 68bd0ab commit 262e997

11 files changed

+104
-110
lines changed

mysql-test/include/default_my.cnf

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ disable-force-if-open
1515

1616
[ENV]
1717
MASTER_MYPORT= @mysqld.1.port
18+
MASTER_ADMINPORT= @mysqld.1.admin-port
1819
MASTER_MYSOCK= @mysqld.1.socket
1920
MASTER_X_MYPORT= @mysqld.1.loose-mysqlx-port
2021
MASTER_X_MYSOCK= @mysqld.1.loose-mysqlx-socket

mysql-test/lib/My/ConfigFactory.pm

+7
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ sub fix_port {
105105
return $self->{HOSTS}->{$hostname}++;
106106
}
107107

108+
sub fix_admin_port {
109+
my ($self, $config, $group_name, $group) = @_;
110+
my $hostname = $group->value('#host');
111+
return $self->{HOSTS}->{$hostname}++;
112+
}
113+
108114
sub fix_x_port {
109115
my ($self, $config, $group_name, $group) = @_;
110116
return $self->{ARGS}->{mysqlxbaseport}++;
@@ -268,6 +274,7 @@ my @mysqld_rules = (
268274
{ 'character-sets-dir' => \&fix_charset_dir },
269275
{ 'datadir' => \&fix_datadir },
270276
{ 'port' => \&fix_port },
277+
{ 'admin-port' => \&fix_admin_port },
271278
{ 'general_log' => 1 },
272279
{ 'general_log_file' => \&fix_log },
273280
{ 'loose-mysqlx-port' => \&fix_x_port },

mysql-test/mysql-test-run.pl

+12-16
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
my $daemonize_mysqld = 0;
168168
my $debug_d = "d";
169169
my $exe_ndbmtd_counter = 0;
170-
my $ports_per_thread = 20;
170+
my $ports_per_thread = 30;
171171
my $source_dist = 0;
172172
my $valgrind_reports = 0;
173173

@@ -2204,31 +2204,27 @@ ($)
22042204
$baseport = $build_thread * 10 + 10000;
22052205

22062206
if (lc($opt_mysqlx_baseport) eq "auto") {
2207-
if ($ports_per_thread > 10) {
2208-
# Reserving last 10 ports in the current port range for X plugin.
2209-
$mysqlx_baseport = $baseport + $ports_per_thread - 10;
2210-
} else {
2211-
# Reserving the last port in the range for X plugin
2212-
$mysqlx_baseport = $baseport + 9;
2213-
}
2207+
# Reserving last 10 ports in the current port range for X plugin.
2208+
$mysqlx_baseport = $baseport + $ports_per_thread - 10;
22142209
} else {
22152210
$mysqlx_baseport = $opt_mysqlx_baseport;
22162211
}
22172212

22182213
if ($secondary_engine_support) {
22192214
# Reserve a port for secondary engine server
2220-
if ($group_replication and $ports_per_thread == 40) {
2215+
if ($group_replication and $ports_per_thread == 50) {
22212216
# When both group replication and secondary engine are enabled,
2222-
# ports_per_thread value should be 40.
2223-
# - First set of 10 ports are reserved for mysqld servers
2217+
# ports_per_thread value should be 50.
2218+
# - First set of 20 ports are reserved for mysqld servers (10 each for
2219+
# standard and admin connections)
22242220
# - Second set of 10 ports are reserver for Group replication
22252221
# - Third set of 10 ports are reserved for secondary engine server
2226-
# - Fourth and last set of 10 porst are reserved for X plugin
2227-
$::secondary_engine_port = $baseport + 20;
2222+
# - Fourth and last set of 10 ports are reserved for X plugin
2223+
$::secondary_engine_port = $baseport + 30;
22282224
} else {
2229-
# ports_per_thread value should be 30, reserve second set of
2225+
# ports_per_thread value should be 40, reserve second set of
22302226
# 10 ports for secondary engine server.
2231-
$::secondary_engine_port = $baseport + 10;
2227+
$::secondary_engine_port = $baseport + 20;
22322228
}
22332229
}
22342230

@@ -6476,7 +6472,7 @@ ($)
64766472
# enough for allocating extra Group replication ports.
64776473
$ENV{$xcom_server} = -1;
64786474
} else {
6479-
my $xcom_port = $baseport + 9 + $server_id;
6475+
my $xcom_port = $baseport + 19 + $server_id;
64806476
$ENV{$xcom_server} = $xcom_port;
64816477
}
64826478

mysql-test/r/admin_interface.result

+11-11
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ root@localhost
5050
disconnect ordinary_con;
5151
# Test case 7
5252
# Check that admin connection using tcp protocol can be established
53-
connect admin_tcp_con,127.0.0.1,root,,,$ADMIN_PORT,,TCP;
53+
connect admin_tcp_con,127.0.0.1,root,,,$MASTER_ADMINPORT,,TCP;
5454
SELECT CURRENT_USER();
5555
CURRENT_USER()
5656
root@localhost
@@ -61,7 +61,7 @@ disconnect admin_tcp_con;
6161
# Test case 8
6262
# Check that the user u1 can establish connection to admin interface since
6363
# this user has the privilege SERVICE_CONNECTION_ADMIN
64-
connect admin_tcp_con_u1,127.0.0.1,u1,,,$ADMIN_PORT,,TCP;
64+
connect admin_tcp_con_u1,127.0.0.1,u1,,,$MASTER_ADMINPORT,,TCP;
6565
SELECT CURRENT_USER();
6666
CURRENT_USER()
6767
u1@%
@@ -71,12 +71,12 @@ disconnect admin_tcp_con_u1;
7171
# this user doesn't have the privilege SERVICE_CONNECTION_ADMIN
7272
connection default;
7373
connect(127.0.0.1,u2,,test,ADMIN_PORT,MASTER_SOCKET);
74-
connect admin_tcp_con_u2,127.0.0.1,u2,,,$ADMIN_PORT,,TCP;
74+
connect admin_tcp_con_u2,127.0.0.1,u2,,,$MASTER_ADMINPORT,,TCP;
7575
ERROR 42000: Access denied; you need (at least one of) the SERVICE_CONNECTION_ADMIN privilege(s) for this operation
7676
# Check that the user u3 can't establish connection to admin interface since
7777
# this user doesn't have the privilege SERVICE_CONNECTION_ADMIN
7878
connect(127.0.0.1,u3,,test,ADMIN_PORT,MASTER_SOCKET);
79-
connect admin_tcp_con_u3,127.0.0.1,u3,,,$ADMIN_PORT,,TCP;
79+
connect admin_tcp_con_u3,127.0.0.1,u3,,,$MASTER_ADMINPORT,,TCP;
8080
ERROR 42000: Access denied; you need (at least one of) the SERVICE_CONNECTION_ADMIN privilege(s) for this operation
8181
connection default;
8282
# Wait until the failed connections are gone.
@@ -99,10 +99,10 @@ connect ordinary_con_2,localhost,u2,,,,,;
9999
ERROR 08004: Too many connections
100100
# Check that attempt to establish the third connection to admin interface
101101
# doesn't result in error
102-
connect admin_con_3,localhost,u1,,,$ADMIN_PORT,,TCP;
102+
connect admin_con_3,localhost,u1,,,$MASTER_ADMINPORT,,TCP;
103103
# Check that total number of concurrent connection made to admin interface
104104
# is not limited by the value max-connections + 1
105-
connect admin_con_4,localhost,u1,,,$ADMIN_PORT,,TCP;
105+
connect admin_con_4,localhost,u1,,,$MASTER_ADMINPORT,,TCP;
106106
connection ordinary_con_1;
107107
disconnect ordinary_con_1;
108108
connection admin_con_3;
@@ -130,7 +130,7 @@ thread/sql/admin_interface BACKGROUND
130130
# Test case 13
131131
# Check that admin connection using tcp protocol can be established
132132
# when a server is started with option --create-admin-listener-thread=true
133-
connect admin_tcp_con,127.0.0.1,root,,,$ADMIN_PORT,,TCP;
133+
connect admin_tcp_con,127.0.0.1,root,,,$MASTER_ADMINPORT,,TCP;
134134
SELECT CURRENT_USER();
135135
CURRENT_USER()
136136
root@localhost
@@ -143,7 +143,7 @@ connection default;
143143
# Starting up server with --admin-address=127.0.0.1 --skip-networking
144144
# restart: --admin-address=127.0.0.1 --admin-port=ADMIN_PORT --skip-networking
145145
connect(127.0.0.1,root,,test,ADMIN_PORT,MASTER_SOCKET);
146-
connect admin_tcp_con,127.0.0.1,root,,,$ADMIN_PORT,,TCP;
146+
connect admin_tcp_con,127.0.0.1,root,,,$MASTER_ADMINPORT,,TCP;
147147
# Test case 15
148148
# Check that admin interface is turned off in case a server started
149149
# with the --skip-grant-tables option. If the server is started with
@@ -155,7 +155,7 @@ connection default;
155155
# Starting up server with --admin-address=127.0.0.1 --skip-grant-tables
156156
# restart: --admin-address=127.0.0.1 --admin-port=ADMIN_PORT --skip-grant-tables
157157
connect(127.0.0.1,root,,test,ADMIN_PORT,MASTER_SOCKET);
158-
connect admin_tcp_con,127.0.0.1,root,,,$ADMIN_PORT,,TCP;
158+
connect admin_tcp_con,127.0.0.1,root,,,$MASTER_ADMINPORT,,TCP;
159159
connection default;
160160
# Stop DB server
161161
# Test case 16
@@ -171,13 +171,13 @@ SELECT @@admin_address, @@admin_port;
171171
NULL ADMIN_PORT
172172
disconnect ordinary_tcp_con;
173173
connect(127.0.0.1,root,,test,ADMIN_PORT,MASTER_SOCKET);
174-
connect admin_tcp_con,127.0.0.1,root,,,$ADMIN_PORT,,TCP;
174+
connect admin_tcp_con,127.0.0.1,root,,,$MASTER_ADMINPORT,,TCP;
175175
# Test case 17
176176
# Check that we can connect to the server if admin
177177
# interface is set up on loopback IPV6 address
178178
connection default;
179179
# restart: --skip-name-resolve --admin-address=::1 --admin-port=ADMIN_PORT
180-
connect admin_tcp_con_ipv6,::1,u1,,,$ADMIN_PORT,,TCP;
180+
connect admin_tcp_con_ipv6,::1,u1,,,$MASTER_ADMINPORT,,TCP;
181181
SELECT @@admin_address, @@admin_port;
182182
@@admin_address @@admin_port
183183
::1 ADMIN_PORT

mysql-test/suite/network_namespace/r/rpl_network_namespace.result

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ INSERT INTO t1 VALUES (1, 'abc');
2222
SHOW CREATE TABLE t1;
2323
Table Create Table
2424
t1 CREATE TABLE `t1` (
25-
`a` int(11) NOT NULL,
25+
`a` int NOT NULL,
2626
`b` varchar(10) DEFAULT NULL,
2727
PRIMARY KEY (`a`)
2828
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
@@ -31,7 +31,7 @@ include/sync_slave_sql_with_master.inc
3131
SHOW CREATE TABLE t1;
3232
Table Create Table
3333
t1 CREATE TABLE `t1` (
34-
`a` int(11) NOT NULL,
34+
`a` int NOT NULL,
3535
`b` varchar(10) DEFAULT NULL,
3636
PRIMARY KEY (`a`)
3737
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

mysql-test/suite/network_namespace/t/network_namespace.test

+6-10
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,20 @@ CREATE USER root@10.0.1.1;
5757

5858
--exec # Use network namespaces with admin port
5959

60-
# Calculate value for admin port
61-
--let $PORT_OFFSET = 1
62-
--expr $ADMIN_PORT = $MASTER_MYPORT + $PORT_OFFSET
63-
64-
--let $restart_parameters=restart: --skip-name-resolve --bind-address=127.0.0.1 --admin-address=10.0.2.1/red --admin-port=$ADMIN_PORT
65-
--replace_result $ADMIN_PORT ADMIN_PORT
60+
--let $restart_parameters=restart: --skip-name-resolve --bind-address=127.0.0.1 --admin-address=10.0.2.1/red --admin-port=$MASTER_ADMINPORT
61+
--replace_result $MASTER_ADMINPORT ADMIN_PORT
6662
--source include/restart_mysqld.inc
6763

6864
GRANT SERVICE_CONNECTION_ADMIN ON *.* TO root@10.0.2.1;
6965

70-
--exec $EXE_MYSQL --no-defaults -u root --host 10.0.2.1 --port $ADMIN_PORT --network-namespace=red -e "SELECT USER()"
66+
--exec $EXE_MYSQL --no-defaults -u root --host 10.0.2.1 --port $MASTER_ADMINPORT --network-namespace=red -e "SELECT USER()"
7167

7268
# Restart with a dedicated listener thread for admin connections
73-
--let $restart_parameters=restart: --skip-name-resolve --bind-address=127.0.0.1 --admin-address=10.0.2.1/red --admin-port=$ADMIN_PORT --create-admin-listener-thread=true
74-
--replace_result $ADMIN_PORT ADMIN_PORT
69+
--let $restart_parameters=restart: --skip-name-resolve --bind-address=127.0.0.1 --admin-address=10.0.2.1/red --admin-port=$MASTER_ADMINPORT --create-admin-listener-thread=true
70+
--replace_result $MASTER_ADMINPORT ADMIN_PORT
7571
--source include/restart_mysqld.inc
7672

77-
--exec $EXE_MYSQL --no-defaults -u root --host 10.0.2.1 --port $ADMIN_PORT --network-namespace=red -e "SELECT USER()"
73+
--exec $EXE_MYSQL --no-defaults -u root --host 10.0.2.1 --port $MASTER_ADMINPORT --network-namespace=red -e "SELECT USER()"
7874

7975
REVOKE SERVICE_CONNECTION_ADMIN ON *.* FROM root@10.0.2.1;
8076

mysql-test/suite/network_namespace/t/network_namespace_ipv6.test

+9-13
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,29 @@ CREATE USER root@'10.0.1.1';
4141

4242
--exec # Use network namespaces with an IPv6 admin address and admin port
4343

44-
# Calculate value for admin port
45-
--let $PORT_OFFSET = 1
46-
--expr $ADMIN_PORT = $MASTER_MYPORT + $PORT_OFFSET
47-
4844
# Restart with an IPv6 address from the 'red' namespace
49-
--let $restart_parameters=restart: --skip-name-resolve --admin-address=::1/red --admin-port=$ADMIN_PORT
50-
--replace_result $ADMIN_PORT ADMIN_PORT
45+
--let $restart_parameters=restart: --skip-name-resolve --admin-address=::1/red --admin-port=$MASTER_ADMINPORT
46+
--replace_result $MASTER_ADMINPORT ADMIN_PORT
5147
--source include/restart_mysqld.inc
5248

5349
GRANT SERVICE_CONNECTION_ADMIN ON *.* TO root@'::1';
5450
GRANT SERVICE_CONNECTION_ADMIN ON *.* TO root@'10.0.1.1';
5551

56-
--exec $EXE_MYSQL --no-defaults -u root --host ::1 --port $ADMIN_PORT --network-namespace=red -e "SELECT USER()"
52+
--exec $EXE_MYSQL --no-defaults -u root --host ::1 --port $MASTER_ADMINPORT --network-namespace=red -e "SELECT USER()"
5753

5854
# Restart with an IPv4 mapped IPv6 address
59-
--let $restart_parameters=restart: --skip-name-resolve --admin-address=::ffff:10.0.1.1/blue --admin-port=$ADMIN_PORT --create-admin-listener-thread=true
60-
--replace_result $ADMIN_PORT ADMIN_PORT
55+
--let $restart_parameters=restart: --skip-name-resolve --admin-address=::ffff:10.0.1.1/blue --admin-port=$MASTER_ADMINPORT --create-admin-listener-thread=true
56+
--replace_result $MASTER_ADMINPORT ADMIN_PORT
6157
--source include/restart_mysqld.inc
6258

63-
--exec $EXE_MYSQL --no-defaults -u root --host ::ffff:10.0.1.1 --port $ADMIN_PORT --network-namespace=blue -e "SELECT USER()"
59+
--exec $EXE_MYSQL --no-defaults -u root --host ::ffff:10.0.1.1 --port $MASTER_ADMINPORT --network-namespace=blue -e "SELECT USER()"
6460

6561
# Restart with an IPv6 admin address in the 'red' namespace with a dedicated listener thread for admin connections
66-
--let $restart_parameters=restart: --skip-name-resolve --admin-address=::1/red --admin-port=$ADMIN_PORT --create-admin-listener-thread=true
67-
--replace_result $ADMIN_PORT ADMIN_PORT
62+
--let $restart_parameters=restart: --skip-name-resolve --admin-address=::1/red --admin-port=$MASTER_ADMINPORT --create-admin-listener-thread=true
63+
--replace_result $MASTER_ADMINPORT ADMIN_PORT
6864
--source include/restart_mysqld.inc
6965

70-
--exec $EXE_MYSQL --no-defaults -u root --host ::1 --port $ADMIN_PORT --network-namespace=red -e "SELECT USER()"
66+
--exec $EXE_MYSQL --no-defaults -u root --host ::1 --port $MASTER_ADMINPORT --network-namespace=red -e "SELECT USER()"
7167

7268
REVOKE SERVICE_CONNECTION_ADMIN ON *.* FROM root@'::1';
7369
REVOKE SERVICE_CONNECTION_ADMIN ON *.* FROM root@'10.0.1.1';

mysql-test/suite/sys_vars/r/admin_port_basic.result

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
select @@global.admin_port;
22
@@global.admin_port
3-
33062
3+
ADMIN_PORT
44
select @@session.admin_port;
55
ERROR HY000: Variable 'admin_port' is a GLOBAL variable
66
show global variables like 'admin_port';
77
Variable_name Value
8-
admin_port 33062
8+
admin_port ADMIN_PORT
99
show session variables like 'admin_port';
1010
Variable_name Value
11-
admin_port 33062
11+
admin_port ADMIN_PORT
1212
select * from performance_schema.global_variables where variable_name='admin_port';
1313
VARIABLE_NAME VARIABLE_VALUE
14-
admin_port 33062
14+
admin_port ADMIN_PORT
1515
select * from performance_schema.session_variables where variable_name='admin_port';
1616
VARIABLE_NAME VARIABLE_VALUE
17-
admin_port 33062
18-
select * from performance_schema.variables_info where variable_name='admin_port';
19-
VARIABLE_NAME VARIABLE_SOURCE VARIABLE_PATH MIN_VALUE MAX_VALUE SET_TIME SET_USER SET_HOST
20-
admin_port COMPILED 0 65535 NULL NULL NULL
17+
admin_port ADMIN_PORT
18+
select variable_name, min_value, max_value from performance_schema.variables_info where variable_name='admin_port';
19+
variable_name min_value max_value
20+
admin_port 0 65535
2121
set global admin_port=1000;
2222
ERROR HY000: Variable 'admin_port' is a read only variable
2323
set session admin_port=1000;

mysql-test/suite/sys_vars/t/admin_port_basic.test

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
#
22
# only global
33
#
4+
--replace_result $MASTER_ADMINPORT ADMIN_PORT
45
select @@global.admin_port;
56
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
67
select @@session.admin_port;
8+
--replace_result $MASTER_ADMINPORT ADMIN_PORT
79
show global variables like 'admin_port';
10+
--replace_result $MASTER_ADMINPORT ADMIN_PORT
811
show session variables like 'admin_port';
912
--disable_warnings
13+
--replace_result $MASTER_ADMINPORT ADMIN_PORT
1014
select * from performance_schema.global_variables where variable_name='admin_port';
15+
--replace_result $MASTER_ADMINPORT ADMIN_PORT
1116
select * from performance_schema.session_variables where variable_name='admin_port';
12-
select * from performance_schema.variables_info where variable_name='admin_port';
17+
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
18+
select variable_name, min_value, max_value from performance_schema.variables_info where variable_name='admin_port';
1319
--enable_warnings
1420

1521
#
@@ -25,16 +31,14 @@ set persist admin_port=1000;
2531
#
2632
# Set the option and verify that it is reflected
2733
#
28-
--let $PORT_OFFSET = 1
29-
--expr $ADMIN_PORT = $MASTER_MYPORT + $PORT_OFFSET
30-
--let $restart_parameters=restart: --skip-name-resolve --admin-address=127.0.0.1 --admin_port=$ADMIN_PORT
31-
--replace_result $ADMIN_PORT ADMIN_PORT
34+
--let $restart_parameters=restart: --skip-name-resolve --admin-address=127.0.0.1 --admin_port=$MASTER_ADMINPORT
35+
--replace_result $MASTER_ADMINPORT ADMIN_PORT
3236
--source include/restart_mysqld.inc
3337

3438
--disable_warnings
35-
--replace_result $ADMIN_PORT ADMIN_PORT
39+
--replace_result $MASTER_ADMINPORT ADMIN_PORT
3640
select * from performance_schema.global_variables where variable_name='admin_port';
37-
--replace_result $ADMIN_PORT ADMIN_PORT
41+
--replace_result $MASTER_ADMINPORT ADMIN_PORT
3842
select * from performance_schema.session_variables where variable_name='admin_port';
3943
--enable_warnings
4044

0 commit comments

Comments
 (0)