SlideShare a Scribd company logo
MySQL Connectors 8.0.19
& DNS SRV
with examples using docker & consul
Kenny Gryp
MySQL Product Manager
1 / 19
2 / 192 / 19
 
Safe Harbor Statement
The following is intended to outline our general product direction. It is intended for information purpose only, and may not be
incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied up
in making purchasing decisions. The development, release and timing of any features or functionality described for Oracle´s
product remains at the sole discretion of Oracle.
3 / 19
DNS-SRV
DNS Service record - RFC 2782
"defining the location, i.e., the hostname and port number, of servers for specified services"
Example
_service._proto.name. TTL class SRV priority weight port target.
_mysql._tcp.domain. 0 IN SRV 0 5 3306 mysql_server_1.domain.
_mysql._tcp.domain. 0 IN SRV 0 5 3306 mysql_server_2.domain.
_mysql._tcp.domain. 0 IN SRV 0 5 3306 mysql_server_3.domain.
...
4 / 19
What is DNS-SRV
# dig database-router-ro.service.consul SRV
; <<>> DiG 9.11.5-P4-5.1-Debian <<>> database-router-ro.service.consul SRV
...
;; QUESTION SECTION:
;database-router-ro.service.consul. IN SRV
;; ANSWER SECTION:
database-router-ro.service.consul. 0 IN SRV 1 1 6447 ac14000a.addr.dc1.consul.
database-router-ro.service.consul. 0 IN SRV 1 1 6447 ac140007.addr.dc1.consul.
database-router-ro.service.consul. 0 IN SRV 1 1 6447 ac14000b.addr.dc1.consul.
;; ADDITIONAL SECTION:
ac14000a.addr.dc1.consul. 0 IN A 172.20.0.10
ac140007.addr.dc1.consul. 0 IN A 172.20.0.7
ac14000b.addr.dc1.consul. 0 IN A 172.20.0.11
;; Query time: 6 msec
;; SERVER: 172.20.0.2#53(172.20.0.2)
;; WHEN: Mon Jan 27 19:43:07 UTC 2020
;; MSG SIZE rcvd: 560
5 / 19
How do I configure DNS-SRV?
Do I need to configure BIND and list the Database Servers manually?
6 / 19
How do I configure DNS-SRV?
Do I need to configure BIND and list the Database Servers manually? NO!
Use Service Discovery Tools!
6 / 19
How do I configure DNS-SRV?
Do I need to configure BIND and list the Database Servers manually? NO!
Use Service Discovery Tools!
Service Discovery Tools
   
   
 
6 / 19
How do I configure DNS-SRV?
Do I need to configure BIND and list the Database Servers manually? NO!
Use Service Discovery Tools!
Service Discovery Tools
   
   
 
Container Orchestration
6 / 19
Released for native protocol connectors
Connector/NET
Connector/ODBC
Connector/J
Connector/Node.js
Connector/Python
Connector/C++
Both X & Classic Protocol
MySQL 8.0.19 Supports DNS-SRV
7 / 19
Released for native protocol connectors
Connector/NET
Connector/ODBC
Connector/J
Connector/Node.js
Connector/Python
Connector/C++
Both X & Classic Protocol
In progress for...
Connector/C / libmysqlclient
& dependent community connectors:
Perl
MySQL/Ruby
mysql-python
PHP Plugin
Awaiting PHP release
Not started...
native community drivers:
go-sql-driver
MySQL 8.0.19 Supports DNS-SRV
7 / 19
MySQL InnoDB Cluster MySQL InnoDB ReplicaSet
Use Cases - MySQL InnoDB Cluster / ReplicaSet
When MySQL Router cannot be installed on Application servers!
8 / 19
MySQL InnoDB Cluster MySQL InnoDB ReplicaSet
Use Cases - MySQL InnoDB Cluster / ReplicaSet
When MySQL Router cannot be installed on Application servers!
9 / 19
Use Cases
Ease of Use
Changes in database architecture does not require handling/changing:
virtual IPs
Load Balancers
change connector configuration
consul-template
Elasticity
New endpoints can register/deregister, adding/removing them from service discovery
Customization
Ability to customize & automate integration from application to data
10 / 19
MySQL InnoDB Cluster Steps
1. Router Starts
2. consul-agent register with consul cluster
3. consul-agent performs health checks
4. connectors do DNS SRV request to find MySQL Router
servers
How to Use -- 1. Registration & Health Checking
11 / 19
DNS Server Level: Local Forwarders
dnsmasq
How to Use -- 2. DNS Forwarding
1. Connectors do not do any form of caching or forwarding.
Every new connection does a new DNS SRV request.
2. Service Discovery is usually different from other DNS infrastructure, which then requires DNS Forwarding
Excellent implementation guide:
HashiCorp - Consul - Forward DNS
12 / 19
How to Use -- 3. Example Connector/Python Configuration
Example:
cnx = mysql.connector.connect(
user='root', password='mysql',
host='database-router-rw.service',
dns_srv=True)
13 / 19
How to Use -- 3. Example Connector/Python Configuration
Example:
cnx = mysql.connector.connect(
user='root', password='mysql',
host='database-router-rw.service',
dns_srv=True)
Wait... not according to RFC 2782? (expecting _mysql._tcp.service)
13 / 19
How to Use -- 3. Example Connector/Python Configuration
Example:
cnx = mysql.connector.connect(
user='root', password='mysql',
host='database-router-rw.service',
dns_srv=True)
Wait... not according to RFC 2782? (expecting _mysql._tcp.service)
Nope
13 / 19
How to Use -- 3. Example Connector/Python Configuration
Example:
cnx = mysql.connector.connect(
user='root', password='mysql',
host='database-router-rw.service',
dns_srv=True)
Wait... not according to RFC 2782? (expecting _mysql._tcp.service)
Nope
Consul does not fully adhere to RFC, allowing:
# all
database-router-rw.service
_database-router-rw._tcp.service
# tag ghent
ghent.database-router-rw.service
_database-router-rw._ghent.service
13 / 19
Priority
Servers with lower priority MUST be attempted
(Not supported by Consul)
Weight
Larger weights SHOULD be given a proportionately higher
probability of being selected.
(Supported by Consul)
DNS SRV Priority & Weights -- According to RFC 2782
Connectors implement RFC:
Calculation
For each Priority (lowest first)
calculated SUM(weights), assign each number to a Server
choose random number BETWEEN 0 AND SUM(weights)
find server that is greater than or equal the random number
14 / 19
TTL
TTL can be configured to allow caching on DNS Level, but be wary of impact:
TTL of 0 means no caching:
service discovery that is down will result in database connection issues
TTL that is too high reduces flexibility:
takes time before a broken server is taken out of the pool, causing connection issues
(Supported by Consul)
DNS Servers/Caching/Forwarders configuration might not respect TTL, doublecheck!
15 / 19
MySQL InnoDB Cluster MySQL InnoDB Cluster
Endless Possibilities
16 / 19
Docker as Environment
Consul as Service Discovery
Registrator as Service Registry
MySQL InnoDB Cluster as Database Backend
MySQL Router as Proxy
Python Application to demonstrate
Demo
17 / 19
Demo time!
18 / 19
MySQL Connectors 8.0.19
& DNS SRV
with examples using docker & consul
Kenny Gryp
MySQL Product Manager
19 / 19

More Related Content

MySQL Connectors 8.0.19 & DNS SRV

  • 1. MySQL Connectors 8.0.19 & DNS SRV with examples using docker & consul Kenny Gryp MySQL Product Manager 1 / 19
  • 2. 2 / 192 / 19
  • 3.   Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purpose only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied up in making purchasing decisions. The development, release and timing of any features or functionality described for Oracle´s product remains at the sole discretion of Oracle. 3 / 19
  • 4. DNS-SRV DNS Service record - RFC 2782 "defining the location, i.e., the hostname and port number, of servers for specified services" Example _service._proto.name. TTL class SRV priority weight port target. _mysql._tcp.domain. 0 IN SRV 0 5 3306 mysql_server_1.domain. _mysql._tcp.domain. 0 IN SRV 0 5 3306 mysql_server_2.domain. _mysql._tcp.domain. 0 IN SRV 0 5 3306 mysql_server_3.domain. ... 4 / 19
  • 5. What is DNS-SRV # dig database-router-ro.service.consul SRV ; <<>> DiG 9.11.5-P4-5.1-Debian <<>> database-router-ro.service.consul SRV ... ;; QUESTION SECTION: ;database-router-ro.service.consul. IN SRV ;; ANSWER SECTION: database-router-ro.service.consul. 0 IN SRV 1 1 6447 ac14000a.addr.dc1.consul. database-router-ro.service.consul. 0 IN SRV 1 1 6447 ac140007.addr.dc1.consul. database-router-ro.service.consul. 0 IN SRV 1 1 6447 ac14000b.addr.dc1.consul. ;; ADDITIONAL SECTION: ac14000a.addr.dc1.consul. 0 IN A 172.20.0.10 ac140007.addr.dc1.consul. 0 IN A 172.20.0.7 ac14000b.addr.dc1.consul. 0 IN A 172.20.0.11 ;; Query time: 6 msec ;; SERVER: 172.20.0.2#53(172.20.0.2) ;; WHEN: Mon Jan 27 19:43:07 UTC 2020 ;; MSG SIZE rcvd: 560 5 / 19
  • 6. How do I configure DNS-SRV? Do I need to configure BIND and list the Database Servers manually? 6 / 19
  • 7. How do I configure DNS-SRV? Do I need to configure BIND and list the Database Servers manually? NO! Use Service Discovery Tools! 6 / 19
  • 8. How do I configure DNS-SRV? Do I need to configure BIND and list the Database Servers manually? NO! Use Service Discovery Tools! Service Discovery Tools           6 / 19
  • 9. How do I configure DNS-SRV? Do I need to configure BIND and list the Database Servers manually? NO! Use Service Discovery Tools! Service Discovery Tools           Container Orchestration 6 / 19
  • 10. Released for native protocol connectors Connector/NET Connector/ODBC Connector/J Connector/Node.js Connector/Python Connector/C++ Both X & Classic Protocol MySQL 8.0.19 Supports DNS-SRV 7 / 19
  • 11. Released for native protocol connectors Connector/NET Connector/ODBC Connector/J Connector/Node.js Connector/Python Connector/C++ Both X & Classic Protocol In progress for... Connector/C / libmysqlclient & dependent community connectors: Perl MySQL/Ruby mysql-python PHP Plugin Awaiting PHP release Not started... native community drivers: go-sql-driver MySQL 8.0.19 Supports DNS-SRV 7 / 19
  • 12. MySQL InnoDB Cluster MySQL InnoDB ReplicaSet Use Cases - MySQL InnoDB Cluster / ReplicaSet When MySQL Router cannot be installed on Application servers! 8 / 19
  • 13. MySQL InnoDB Cluster MySQL InnoDB ReplicaSet Use Cases - MySQL InnoDB Cluster / ReplicaSet When MySQL Router cannot be installed on Application servers! 9 / 19
  • 14. Use Cases Ease of Use Changes in database architecture does not require handling/changing: virtual IPs Load Balancers change connector configuration consul-template Elasticity New endpoints can register/deregister, adding/removing them from service discovery Customization Ability to customize & automate integration from application to data 10 / 19
  • 15. MySQL InnoDB Cluster Steps 1. Router Starts 2. consul-agent register with consul cluster 3. consul-agent performs health checks 4. connectors do DNS SRV request to find MySQL Router servers How to Use -- 1. Registration & Health Checking 11 / 19
  • 16. DNS Server Level: Local Forwarders dnsmasq How to Use -- 2. DNS Forwarding 1. Connectors do not do any form of caching or forwarding. Every new connection does a new DNS SRV request. 2. Service Discovery is usually different from other DNS infrastructure, which then requires DNS Forwarding Excellent implementation guide: HashiCorp - Consul - Forward DNS 12 / 19
  • 17. How to Use -- 3. Example Connector/Python Configuration Example: cnx = mysql.connector.connect( user='root', password='mysql', host='database-router-rw.service', dns_srv=True) 13 / 19
  • 18. How to Use -- 3. Example Connector/Python Configuration Example: cnx = mysql.connector.connect( user='root', password='mysql', host='database-router-rw.service', dns_srv=True) Wait... not according to RFC 2782? (expecting _mysql._tcp.service) 13 / 19
  • 19. How to Use -- 3. Example Connector/Python Configuration Example: cnx = mysql.connector.connect( user='root', password='mysql', host='database-router-rw.service', dns_srv=True) Wait... not according to RFC 2782? (expecting _mysql._tcp.service) Nope 13 / 19
  • 20. How to Use -- 3. Example Connector/Python Configuration Example: cnx = mysql.connector.connect( user='root', password='mysql', host='database-router-rw.service', dns_srv=True) Wait... not according to RFC 2782? (expecting _mysql._tcp.service) Nope Consul does not fully adhere to RFC, allowing: # all database-router-rw.service _database-router-rw._tcp.service # tag ghent ghent.database-router-rw.service _database-router-rw._ghent.service 13 / 19
  • 21. Priority Servers with lower priority MUST be attempted (Not supported by Consul) Weight Larger weights SHOULD be given a proportionately higher probability of being selected. (Supported by Consul) DNS SRV Priority & Weights -- According to RFC 2782 Connectors implement RFC: Calculation For each Priority (lowest first) calculated SUM(weights), assign each number to a Server choose random number BETWEEN 0 AND SUM(weights) find server that is greater than or equal the random number 14 / 19
  • 22. TTL TTL can be configured to allow caching on DNS Level, but be wary of impact: TTL of 0 means no caching: service discovery that is down will result in database connection issues TTL that is too high reduces flexibility: takes time before a broken server is taken out of the pool, causing connection issues (Supported by Consul) DNS Servers/Caching/Forwarders configuration might not respect TTL, doublecheck! 15 / 19
  • 23. MySQL InnoDB Cluster MySQL InnoDB Cluster Endless Possibilities 16 / 19
  • 24. Docker as Environment Consul as Service Discovery Registrator as Service Registry MySQL InnoDB Cluster as Database Backend MySQL Router as Proxy Python Application to demonstrate Demo 17 / 19
  • 26. MySQL Connectors 8.0.19 & DNS SRV with examples using docker & consul Kenny Gryp MySQL Product Manager 19 / 19