vitessio / vitess

Vitess is a database clustering system for horizontal scaling of MySQL.
http://vitess.io
Apache License 2.0
18.45k stars 2.09k forks source link

Feature Request: Bind vitess mysqld and GRPC server to other interfaces than not 0.0.0.0 #16798

Open gmpify opened 6 days ago

gmpify commented 6 days ago

Feature Description

We'd like to run vttestserver bound on a specific IP interface. When we run vttestserver, it correctly binds vtcombo and vtgate to the specified interface. But the underlying mysqld and GRPC server would still bind to 0.0.0.0.

How to reproduce:

$ /opt/vitess-19/bin/vttestserver --alsologtostderr --persistent_mode --mysql_bind_host=127.231.106.94 --grpc_bind_address=127.231.106.94 --vschema_ddl_authorized_users=% --enable_system_settings=false --mysql_server_version=8.0.34 --planner-version=gen4 --data_dir=<redacted>/data --log_dir=<redacted>/logs --port=15991 --tablet_hostname=127.231.106.94 --tablet_refresh_interval=10s --vtcombo-bind-host=127.231.106.94 --num_shards=1,1 --keyspaces=core_general_1_dev,core_general_1_test

// notice command with port 15991

$ netstat -an | grep 1599 | grep LISTEN
tcp4       0      0  127.231.106.94.15991   *.*                    LISTEN
tcp46      0      0  *.15992                *.*                    LISTEN
tcp4       0      0  127.231.106.94.15994   *.*                    LISTEN
tcp46      0      0  *.15993                *.*                    LISTEN

$ lsof -i :15991-15994
COMMAND   PID             USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
mysqld  30509 gabrielparreiras   20u  IPv6 0x843d5de06a4e62a0      0t0  TCP *:15993 (LISTEN)
vtcombo 30513 gabrielparreiras   34u  IPv4 0x83b4c31e34aa900c      0t0  TCP localhost:15994 (LISTEN)
vtcombo 30513 gabrielparreiras   36u  IPv6 0x38b3535bf6c700cf      0t0  TCP *:15992 (LISTEN)
vtcombo 30513 gabrielparreiras   37u  IPv4 0x93e314ab7e1f052a      0t0  TCP localhost:15991 (LISTEN)

Use Case(s)

With this feature we could also run multiple instances of vttestserver on the same machine, each of them bound to a separate IP interface.

GuptaManan100 commented 5 days ago

I took a look at the code in depth today. And yes there are some problems in the code. I'll describe both the grpc and mysqld problems separately.

For the grpc port, vttestserver is accepting the grpc related flags like grpc_port, grpc_bind_address, grpc_max_connection_age and so on, but it doesn't pass them onto the vtcombo binary. It only sets the grpc_port and that too with a value of the baseport + 1. This is causing vtcombo to start the grpc on all addresses and not on just the one you specified. The fix for this would be to pass the arguments forward from vttestserver to vtcombo when it initializes it.

For the MySQL port, it doesn't look like mysqlctl and mysqlctld even support starting a MySQL on a non-default hostname. It only accepts the mysql_port flag, that vttestserver is passing on. It uses this value to put into the my.cnf file as port=<value> before starting MySQL. However it doesn't yet populate the host field. So, if this is required, then we'd have to augment both of those commands first, and then make vttestserver pass in the newly created flag.

In the command mysql_bind_host, is the hostname that vtcombo is going to be using to start listening for MySQL queries and not the MySQL hostname to start MySQL on. We don't have a flag for that at all.