WL#13905: libmysql support for DNS SRV
In high availability scenarios, data is often mirrored into a cluster of servers. Presently, developers can share the query load across these servers but they must list every server in the connection string. This is cumbersome since changing any of the server hostnames or adding/dropping servers can involve changing the code or configuration file across the entire app farm. DNS SRV records allows a DNS admin to map a single DNS domain to multiple servers and the DNS admin can update this in a central location.
This work is based entirely on RFC 2782. DNS SRV records are widely used and are the standard mechanism used to enumerate a list of implementing servers for a given host,domain.
- L1 - mysql_real_connect_dns_srv() will work on top of mysql_real_connect(). No non-blocking version
- L2 - The re-connect attempts in libmysql will be kept as they are. If one wants to do reconnects differently they must disable auto-reconnect and do an app level reconnect.
- L3 - There will be no caching of the DNS SRV results in libmysql. Every time a new call to mysql_real_connect_dns_srv() is attempted a new DNS SRV request will be made and the results will be used locally within the function until a successful connection or failure. Once mysql_real_connect_dns_srv() returns the results are lost.
- L4 - mysql command line (and the rest of command line tools like e.g. mysqladmin, mysqldump etc) will not be altered by this worklog to use mysql_real_connect_dns_srv().
- L4.1 - the only exception is mysql command line tool that will have a new option called --dns-srv-host. This takes a string.
- L4.2 - when --dns-srv-host is specified it takes precedence over any --host option specified and causes mysql_real_connect_dns_srv() to be called instead of mysql_real_connect(), regardless of the command line parameter order
- L4.3 - if the host attribute is specified with the connect mysql command this takes precedence over the --dns-srv-host specified on the command line.
- L4.4 - --dns-srv-host doesn't have any effect on selecting a connection protocol. If you need to make sure a certain protocol is used (e.g. TCP) you will need to also specify --protocol( e.g. =tcp) on the command line.
- L5 - mysql_real_connect_dns_srv() will be TCP-only ! No shared memory, no named pipes or unix sockets. This will not be enforced, but it's expected that if this is not the case it will fail. And no unix socket etc will be passed down.
- L6 - the replication slave client (or any other of the server's built in clients, like e.g. the federated etc) will not be made to use the new API with this worklog.
- L7 - if the DNS SRV request returns multiple entries mysql_real_connect_dns_srv() will attempt to connect to them in the order described in RFC2782 according to their priority and weight.
- L8 - if connection to all of the entries returned by DNS SRV fails mysql_real_connect_dns_srv() will fail with an appropriate error.
- MYSQL *mysql
- const char *dns_srv_name,
- const char *user,
- const char *passwd,
- const char *db, *unsigned long client_flag
This will work with TCP connections only ! It will:
- resolve the dns_srv_name to a (series of) host/port pairs.
- set the save MYSQL options flag temporarily (if not set) and record the prior state
- pick the next host to try according to the algorithm described in RFC2782, remove it from the list and try to connect.
- Iterate 3 until a successful connection is made or the list is empty.
- Restore the save MySQL options flag to its prior state
- Return a connect error or success
This will add dependencies to the following libraries to libmysql:
- dnsapi.dll on windows
- libresolv.so on others