SlideShare a Scribd company logo
MySQL Router
Explore The Secrets
Miguel Araújo
Senior Principal Software Engineer
MySQL, Oracle
February 2, 2024
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.
Safe Harbor Statement
Copyright © 2023, Oracle and/or its affiliates. All rights reserved.
2
$ whoami
miguel_araujo
$ whoami && history
Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
3
~/belgian_days_24
$ whoami
miguel_araujo
$ history –E
20.09.2015 MySQL Router 1st labs release
$ whoami && history
Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
4
~/belgian_days_24
$ whoami
miguel_araujo
$ history –E
20.09.2015 MySQL Router 1st labs release
06.09.2016 2.1.0 labs: InnoDB Cluster integration
$ whoami && history
Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
5
~/belgian_days_24
$ whoami
miguel_araujo
$ history –E
20.09.2015 MySQL Router 1st labs release
06.09.2016 2.1.0 labs: InnoDB Cluster integration
12.04.2017 2.1.3 GA: 1st GA release
$ whoami && history
Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
6
~/belgian_days_24
$ whoami
miguel_araujo
$ history –E
20.09.2015 MySQL Router 1st labs release
06.09.2016 2.1.0 labs: InnoDB Cluster integration
12.04.2017 2.1.3 GA: 1st GA release
22.07.2019 8.0.17 GA: Support for GR notifications, REST API
$ whoami && history
Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
7
~/belgian_days_24
$ whoami
miguel_araujo
$ history –E
20.09.2015 MySQL Router 1st labs release
06.09.2016 2.1.0 labs: InnoDB Cluster integration
12.04.2017 2.1.3 GA: 1st GA release
22.07.2019 8.0.17 GA: Support for GR notifications, REST API
19.10.2021 8.0.27 GA: Support for InnoDB ClusterSet
$ whoami && history
Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
8
~/belgian_days_24
$ whoami
miguel_araujo
$ history –E
20.09.2015 MySQL Router 1st labs release
06.09.2016 2.1.0 labs: InnoDB Cluster integration
12.04.2017 2.1.3 GA: 1st GA release
22.07.2019 8.0.17 GA: Support for GR notifications, REST API
19.10.2021 8.0.27 GA: Support for InnoDB ClusterSet
18.07.2023 8.1.0: Support for InnoDB Cluster Read Replicas, Statement tracing
$ whoami && history
Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
9
~/belgian_days_24
$ whoami
miguel_araujo
$ history –E
20.09.2015 MySQL Router 1st labs release
06.09.2016 2.1.0 labs: InnoDB Cluster integration
12.04.2017 2.1.3 GA: 1st GA release
22.07.2019 8.0.17 GA: Support for GR notifications, REST API
19.10.2021 8.0.27 GA: Support for InnoDB ClusterSet
18.07.2023 8.1.0: Support for InnoDB Cluster Read Replicas, Statement tracing
25.10.2023 8.2.0: R/W Splitting
$ whoami && history
Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
10
~/belgian_days_24
Copyright © 2023, Oracle and/or its affiliates. All rights reserved.
11
Technicalities
12 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
Architecture
Harness
Loader
routing
connection
_pool
Util Libs
metadata_cache http_server F
r
o
n
t
e
n
d
MySQL Shell
...
MySQL
MySQL MySQL
13 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
Built-in plugins
routing Routing endpoints logic
destination_status Keep track of the state of the routing destinations
connection_pool Connection pool
metadata_cache Keep track of the MySQL Architectures state / metadata changes
logger Logging utility
syslog Unix based OSes logging: syslog
eventlog Windows OSes logging: eventlog
http_server HTTP server to handle REST API request
http_auth_realm Authentication realm for the http_server
http_auth_backend Authentication backend for the http_server
~/mysql-server/router/src/
14 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
Built-in plugins
io Abstraction for IO OS layer
rest_api General REST API handler
rest_metadata_cache Metadata cache REST API handler
rest_router Global Router REST API handler
rest_routing Routing endpoint REST API handler
router_openssl OpenSSL library integration
router_protobuf Protobuf library integration
~/mysql-server/router/src/
Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
15
Router and MySQL Architectures
16 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
Core component of MySQL Architectures
Transparent access to Database Architecture
• Transparent client connection routing
• Load balancing
• Application connection failover
• Little to no configuration needed
• Stateless design
• Part of the application stack
• Full integration into MySQL Architectures
• InnoDB Cluster
• InnoDB ReplicaSet
• InnoDB ClusterSet
• InnoDB Cluster Read Replicas
• 3 TCP Ports:
• PRIMARY traffic
• SECONDARY traffic
• RW splitting
!
New in 8.1.0
!
New in 8.2.0
Auto-configuration for the MySQL Architecture
• Fetches the topology Metadata information from one of the servers
• Stores it in a dynamic file (data/state.json)
• Registers itself in the Metadata schema
• Creates a configuration file ready to be used
• Creates daemon start/stop scripts
17 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
Bootstrapping
MySQL Router
It’s possible to use Router without bootstrapping, however…
18 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
Manual configuration
[DEFAULT]
...
[routing:primary]
bind_address = localhost
bind_port = 3331
destinations = myserver_xyz:3306
routing_strategy = first-available
[routing:secondaries]
bind_address = localhost
bind_port = 3332
destinations = myserver_foo:3306, myserver_bar:3306
routing_strategy = round-robin-with-fallback
~/testbase/router/my.conf
• Needed to route queries to the appropriate backend of the
topology
• Refreshed each [metadata_cache::ttl]
• Default: 0.5 sec
• ClusterSet: 5 sec
19 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
Metadata Cache
mysql_innodb_cluster_metadata
metadata_cache
MySQL Shell
GR
MySQL
MySQL Router
• Push notifications sent via X protocol:
• group_replication/membership/quorum_loss
• group_replication/membership/view
• group_replication_status/role_change
• group_replication/status/state_change
• Router keeps an open connection to the X Plugin port waiting
for push notifications
• For every change, if needed, the metadata cache is updated
• Allows reducing drastically the TTL
20 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
GR Notifications
mysql_innodb_cluster_metadata
metadata_cache
MySQL Shell
GR
MySQL
MySQL Router
21 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
Deploying MySQL Router
1. Install MySQL Router
2. Bootstrap
3. Start it!
$ mysqlrouter --bootstrap clusteradmin@brussels:3306 
--directory my_router 
--account router_admin 
--conf-use-gr-notifications
$ my_router/start.sh
~/testbase/router
22 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
Deploying MySQL Router
It’s recommended to deploy Router on the same host as the application and enable GR
notifications. That allows:
• Using sockets instead of TCP/IP
• Decreasing network latency
• Fine-grained account access
• Scaling-out!
23 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
Deploying MySQL Router
It’s recommended to deploy Router on the same host as the application and enable GR
notifications. That allows:
• Using sockets instead of TCP/IP
• Decreasing network latency
• Fine-grained account access
• Scaling-out!
Alternatively, it’s possible to deploy multiple
Routers in multiple machines under a VIP.
Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
24
Connection Sharing and Reuse
• Based on a Connection Pool
• Re-use server-side connections that the client wanted to close,
saving the setup costs of establishing new ones
• Share server-side connections where the client is idling on an
active connection, to reduce the number of open server-side
connections freeing up resources bound to those idle
connections
25 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
Connection Sharing and Reuse
MySQL Router
• Configurable with
• connection_sharing (disabled by default)
• connection_sharing_delay (1 by default)
• Seconds to wait before moving an idle connection to the pool
• idle_timeout (5 by default)
• How many seconds to keep a connection in the pool after the client
disconnects
• max_idle_server_connections (disabled by default)
• How many open connections can be kept in the pool after the client
disconnects
26 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
Connection Sharing and Reuse
MySQL Router
Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
27
TLS Session Caching
• TLS handshakes are slow
• Cache and resume TLS sessions from:
• Client to Router
• Router to Server
• Saves time and resources by reducing the connection handshake
• Enabled by default
• Client and Server side caches, configurable with:
• _ssl_session_cache_mode: enable/disable
• _ssl_session_cache_size: max number of cached sessions
• _ssl_session_cache_timeout: cache timeout
28 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
TLS Session Caching !
New in 8.1.0
MySQL Router
Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
29
REST API
• Built on top of the HTTP Server plugin
• Follows the OPENAPI 2.0 spec
• Exposes a Swagger file to describe the REST API:
ü Metadata cache config
ü Metadata cache status
ü Metadata cache instances list
ü Router status
ü Routing plugin status
ü Routes config / status / health / destination / connections
ü Routes list
ü Blocked hosts
30 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
REST API
31 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
$ curl -k -s -u miguel: https://localhost:8443/api/20190715/metadata/bootstrap/config | jq
{
"clusterName": "myCluster",
"timeRefreshInMs": 500,
"groupReplicationId": "1e6598b4-baab-11ee-adc4-d08e7912e4ee",
"nodes": [
{
"hostname": "127.0.0.1",
"port": 3310
},
{
"hostname": "127.0.0.1",
"port": 3320
},
{ "hostname": "127.0.0.1
~
32 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
$ curl -k -s -u miguel: https://localhost:8443/api/20190715/routes | jq
{
"items": [
{
"name": "bootstrap_ro”
},
{ "name": "bootstrap_rw”
},
{
"name": "bootstrap_rw_split”
},
{
"name": "bootstrap_x_ro”
},
~
33 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
34 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
35
MySQL Rest Service (MRS)
MySQL REST Service
• Fast and powerful way to serve data to client applications via a
HTTPS REST interface
• Implemented as a MySQL Router feature
• Built on the concepts of ORDS, focusing on the strengths of
MySQL
• Not as powerful as ORDS (PL/SQL based)
• Focus on MySQL performance
• Focus on MySQL scalability
• Using MySQL/HeatWave as metadata storage, not depending on an
OracleDB instance
• Auto REST for tables, views, and procedures
• GUI Frontend with MySQL Shell for VSCode
36 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
Key takeaways
37 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
Key takeaways
RESTful Web Services
• Auto REST for tables, views, procedures
and functions
• {JSON} responses with paged results
• Developer support (GUI, CLI, API)
• Support for popular OAuth2 services
JSON/Relational Duality
• Full support SQL support for
JSON/Relational REST endpoints
• Visual Duality Editor - Build complex JSON
structures with a few clicks
• SQL & SDK interface preview
Full SQL Support & SDK API
• Fully manageable through SQL
• CREATE REST DUALITY VIEW statements
• Tailored SDK for all RESTful Endpoints
• Popular, Prisma-like API, live prototyping
sql> CREATE OR REPLACE REST DUALITY VIEW /country
ON SERVICE /myService SCHEMA /sakila
AS sakila.country {
countryId: country_id @SORTABLE,
country: country,
lastUpdate: last_update,
cities: sakila.city @INSERT @UPDATE @DELETE {
city: city
}
};
sql> CONFIGURE REST METADATA;
sql> CREATE REST SERVICE /myService;
sql> CREATE REST SCHEMA /sakila FROM `sakila`;
TypeScript SDK API
with live prototyping
of REST queries Full JSON/Relational Duality
Support via SQL and GUI
38 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
MySQL REST Service
Architecture
...
MySQL Router
MySQL Router
MySQL Router
MySQL Router
…
MySQL Shell
OAuth2 Service
MySQL / MDS
Client App
Client App
Client App
…
Client App
Client App
Client App
Client App
Client App
Client App
…
Client App
Client App
Client App
MRS Plugin
Auth
HTTPS Server
Load Balancer
Load Balancer
MRS Metadata
Schema
MySQL Shell
for VS Code
...
Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
39
R/W Splitting
• Motivation:
• 1 port to rule them all
• Up to now, the application had to be aware of the type of
transaction to use either the RW or the RO port
• It’s performant, but limits the usage of Router
• Work it works:
• Router classifies each query as read or write automatically
and forwards to the appropriate backend
• It’s also possible to manually or programmatically to specify
the type of query using
• ROUTER SET
• query_attributes
40 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
R/W Splitting
!
New in 8.2.0
41 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
R/W Splitting
!
New in 8.2.0
mysqlsh-sql> SELECT 1; // SECONDARY
mysqlsh-sql> INSERT INTO tlb VALUES (1) // PRIMARY
mysqlsh-sql> START TRANSACTION READ_ONLY; // SECONDARY
mysqlsh-sql> CREATE TEMPORARY TABLE tbl (id int); // SECONDARY
mysqlsh-sql> SELECT * FROM tbl; // SECONDARY
mysqlsh-sql> COMMIT; // SECONDARY
mysqlsh-sql> query_attributes router.access_mode read_write;
mysqlsh-sql> select @@port; // PRIMARY
~
42 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
R/W Splitting
• The query is sent to the PRIMARY if the
access_mode is read_write
• The query is sent to the SECONDARY if the
access_mode is read_only
• If the access_mode is auto, a query is sent to
a SECONDARY if:
• Inside a READ_ONLY transaction, or
• Router attribute for access mode set
(router.access_mode), or
• Outside a transaction, the connection allows
sharing and the statement is a “read-only”
statement
• If none of the above is met, the query is sent
to the PRIMARY
Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
43
Thank you!
Questions?
MySQL Router - Explore The Secrets (MySQL Belgian Days 2024)

More Related Content

What's hot (20)

PDF
InnoDb Vs NDB Cluster
Mark Swarbrick
 
PDF
Mcb c60 h dc
Strato Varius
 
PDF
MySQL InnoDB Cluster - Group Replication
Frederic Descamps
 
PDF
State of the Dolphin - May 2022
Frederic Descamps
 
PDF
Deep Dive into MySQL InnoDB Cluster Read Scale-out Capabilities.pdf
Miguel Araújo
 
PPTX
Airheads Meetups: 8400 Presentation
Aruba, a Hewlett Packard Enterprise company
 
PDF
Analyzing and Interpreting AWR
pasalapudi
 
PDF
Percona XtraDB Cluster
Kenny Gryp
 
PDF
MySQL Enterprise Backup - BnR Scenarios
Keith Hollman
 
PDF
Open Source 101 2022 - MySQL Indexes and Histograms
Frederic Descamps
 
PDF
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
Kenny Gryp
 
PPT
ORACLE PL SQL
Srinath Maharana
 
PDF
Percona Live 2022 - MySQL Architectures
Frederic Descamps
 
PDF
MySQL Fabricでぼっこぼこにされたはなし
yoku0825
 
PDF
MySQL InnoDB Cluster - Advanced Configuration & Operations
Frederic Descamps
 
PPTX
Part1 of SQL Tuning Workshop - Understanding the Optimizer
Maria Colgan
 
PDF
ProxySQL High Avalability and Configuration Management Overview
René Cannaò
 
PDF
TFA Collector - what can one do with it
Sandesh Rao
 
PPT
障害とオペミスに備える! ~Oracle Databaseのバックアップを考えよう~
Shinnosuke Akita
 
PDF
Linux tuning to improve PostgreSQL performance
PostgreSQL-Consulting
 
InnoDb Vs NDB Cluster
Mark Swarbrick
 
Mcb c60 h dc
Strato Varius
 
MySQL InnoDB Cluster - Group Replication
Frederic Descamps
 
State of the Dolphin - May 2022
Frederic Descamps
 
Deep Dive into MySQL InnoDB Cluster Read Scale-out Capabilities.pdf
Miguel Araújo
 
Airheads Meetups: 8400 Presentation
Aruba, a Hewlett Packard Enterprise company
 
Analyzing and Interpreting AWR
pasalapudi
 
Percona XtraDB Cluster
Kenny Gryp
 
MySQL Enterprise Backup - BnR Scenarios
Keith Hollman
 
Open Source 101 2022 - MySQL Indexes and Histograms
Frederic Descamps
 
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
Kenny Gryp
 
ORACLE PL SQL
Srinath Maharana
 
Percona Live 2022 - MySQL Architectures
Frederic Descamps
 
MySQL Fabricでぼっこぼこにされたはなし
yoku0825
 
MySQL InnoDB Cluster - Advanced Configuration & Operations
Frederic Descamps
 
Part1 of SQL Tuning Workshop - Understanding the Optimizer
Maria Colgan
 
ProxySQL High Avalability and Configuration Management Overview
René Cannaò
 
TFA Collector - what can one do with it
Sandesh Rao
 
障害とオペミスに備える! ~Oracle Databaseのバックアップを考えよう~
Shinnosuke Akita
 
Linux tuning to improve PostgreSQL performance
PostgreSQL-Consulting
 

Similar to MySQL Router - Explore The Secrets (MySQL Belgian Days 2024) (20)

PDF
My sql5.7 whatsnew_presentedatgids2015
Sanjay Manwani
 
PPTX
My sql8 innodb_cluster
Mysql User Camp
 
PDF
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
GeneXus
 
PDF
MySQL The State of the Dolphin - jun15
MySQL Brasil
 
PDF
MySQL Manchester TT - Performance Tuning
Mark Swarbrick
 
PDF
Sunshine php my sql 8.0 v2
Kathy Forte (Hassard)
 
PDF
1 my sql20151219-kaji_ivan
Ivan Tu
 
PDF
How to operate MySQL InnoDB Cluster with MySQL Shell
Frederic Descamps
 
PDF
Introduction to MySQL
Ted Wennmark
 
PDF
MySQL en el mundo real. Evolución desde la compra por Oracle
LibreCon
 
PDF
State of The Dolphin - May 2021
Frederic Descamps
 
PDF
MySQL Day Paris 2018 - Upgrade from MySQL 5.7 to MySQL 8.0
Olivier DASINI
 
PDF
20190915_MySQL開発最新動向
Machiko Ikoma
 
PDF
MySQL Shell - The Best MySQL DBA Tool
Miguel Araújo
 
PDF
5 razões estratégicas para usar MySQL
MySQL Brasil
 
PDF
MySQL & Oracle Linux Keynote at Open Source India 2014
Sanjay Manwani
 
PDF
MySQL Cluster
Mario Beck
 
PPTX
MySQL London Tech Tour March 2015 - MySQL Fabric
Mark Swarbrick
 
PDF
MySQL 8 High Availability with InnoDB Clusters
Miguel Araújo
 
PDF
Oracle OpenWorld - Getting started with MySQL Cluster
Benedita Paúl Vasconcelos
 
My sql5.7 whatsnew_presentedatgids2015
Sanjay Manwani
 
My sql8 innodb_cluster
Mysql User Camp
 
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
GeneXus
 
MySQL The State of the Dolphin - jun15
MySQL Brasil
 
MySQL Manchester TT - Performance Tuning
Mark Swarbrick
 
Sunshine php my sql 8.0 v2
Kathy Forte (Hassard)
 
1 my sql20151219-kaji_ivan
Ivan Tu
 
How to operate MySQL InnoDB Cluster with MySQL Shell
Frederic Descamps
 
Introduction to MySQL
Ted Wennmark
 
MySQL en el mundo real. Evolución desde la compra por Oracle
LibreCon
 
State of The Dolphin - May 2021
Frederic Descamps
 
MySQL Day Paris 2018 - Upgrade from MySQL 5.7 to MySQL 8.0
Olivier DASINI
 
20190915_MySQL開発最新動向
Machiko Ikoma
 
MySQL Shell - The Best MySQL DBA Tool
Miguel Araújo
 
5 razões estratégicas para usar MySQL
MySQL Brasil
 
MySQL & Oracle Linux Keynote at Open Source India 2014
Sanjay Manwani
 
MySQL Cluster
Mario Beck
 
MySQL London Tech Tour March 2015 - MySQL Fabric
Mark Swarbrick
 
MySQL 8 High Availability with InnoDB Clusters
Miguel Araújo
 
Oracle OpenWorld - Getting started with MySQL Cluster
Benedita Paúl Vasconcelos
 
Ad

More from Miguel Araújo (14)

PDF
Routing Guidelines: Unlocking Smarter Query Routing in MySQL Architectures
Miguel Araújo
 
PDF
MySQL Database Architectures - High Availability and Disaster Recovery Solution
Miguel Araújo
 
PDF
Disaster Recovery with MySQL InnoDB ClusterSet - What is it and how do I use it?
Miguel Araújo
 
PDF
MySQL InnoDB Cluster / ReplicaSet - Making Provisioning & Troubleshooting as ...
Miguel Araújo
 
PDF
MySQL InnoDB Cluster / ReplicaSet - Tutorial
Miguel Araújo
 
PDF
MySQL InnoDB Cluster: Management and Troubleshooting with MySQL Shell
Miguel Araújo
 
PDF
MySQL Shell - A DevOps-engineer day with MySQL’s development and administrati...
Miguel Araújo
 
PDF
MySQL Shell: The DevOps Tool for MySQL
Miguel Araújo
 
PDF
FOSDEM'18: MySQL InnoDB Cluster - MySQL HA Made Easy!
Miguel Araújo
 
PDF
MySQL Shell - The DevOps Tool for MySQL
Miguel Araújo
 
PDF
MySQL Proxy. A powerful, flexible MySQL toolbox.
Miguel Araújo
 
PDF
SLQ vs NOSQL - friends or foes
Miguel Araújo
 
PDF
Asynchronous Replication of Databases
Miguel Araújo
 
PDF
Evaluating Data Freshness in Large Scale Replicated Databases
Miguel Araújo
 
Routing Guidelines: Unlocking Smarter Query Routing in MySQL Architectures
Miguel Araújo
 
MySQL Database Architectures - High Availability and Disaster Recovery Solution
Miguel Araújo
 
Disaster Recovery with MySQL InnoDB ClusterSet - What is it and how do I use it?
Miguel Araújo
 
MySQL InnoDB Cluster / ReplicaSet - Making Provisioning & Troubleshooting as ...
Miguel Araújo
 
MySQL InnoDB Cluster / ReplicaSet - Tutorial
Miguel Araújo
 
MySQL InnoDB Cluster: Management and Troubleshooting with MySQL Shell
Miguel Araújo
 
MySQL Shell - A DevOps-engineer day with MySQL’s development and administrati...
Miguel Araújo
 
MySQL Shell: The DevOps Tool for MySQL
Miguel Araújo
 
FOSDEM'18: MySQL InnoDB Cluster - MySQL HA Made Easy!
Miguel Araújo
 
MySQL Shell - The DevOps Tool for MySQL
Miguel Araújo
 
MySQL Proxy. A powerful, flexible MySQL toolbox.
Miguel Araújo
 
SLQ vs NOSQL - friends or foes
Miguel Araújo
 
Asynchronous Replication of Databases
Miguel Araújo
 
Evaluating Data Freshness in Large Scale Replicated Databases
Miguel Araújo
 
Ad

Recently uploaded (20)

PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 

MySQL Router - Explore The Secrets (MySQL Belgian Days 2024)

  • 1. MySQL Router Explore The Secrets Miguel Araújo Senior Principal Software Engineer MySQL, Oracle February 2, 2024
  • 2. 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. Safe Harbor Statement Copyright © 2023, Oracle and/or its affiliates. All rights reserved. 2
  • 3. $ whoami miguel_araujo $ whoami && history Copyright © 2024, Oracle and/or its affiliates. All rights reserved. 3 ~/belgian_days_24
  • 4. $ whoami miguel_araujo $ history –E 20.09.2015 MySQL Router 1st labs release $ whoami && history Copyright © 2024, Oracle and/or its affiliates. All rights reserved. 4 ~/belgian_days_24
  • 5. $ whoami miguel_araujo $ history –E 20.09.2015 MySQL Router 1st labs release 06.09.2016 2.1.0 labs: InnoDB Cluster integration $ whoami && history Copyright © 2024, Oracle and/or its affiliates. All rights reserved. 5 ~/belgian_days_24
  • 6. $ whoami miguel_araujo $ history –E 20.09.2015 MySQL Router 1st labs release 06.09.2016 2.1.0 labs: InnoDB Cluster integration 12.04.2017 2.1.3 GA: 1st GA release $ whoami && history Copyright © 2024, Oracle and/or its affiliates. All rights reserved. 6 ~/belgian_days_24
  • 7. $ whoami miguel_araujo $ history –E 20.09.2015 MySQL Router 1st labs release 06.09.2016 2.1.0 labs: InnoDB Cluster integration 12.04.2017 2.1.3 GA: 1st GA release 22.07.2019 8.0.17 GA: Support for GR notifications, REST API $ whoami && history Copyright © 2024, Oracle and/or its affiliates. All rights reserved. 7 ~/belgian_days_24
  • 8. $ whoami miguel_araujo $ history –E 20.09.2015 MySQL Router 1st labs release 06.09.2016 2.1.0 labs: InnoDB Cluster integration 12.04.2017 2.1.3 GA: 1st GA release 22.07.2019 8.0.17 GA: Support for GR notifications, REST API 19.10.2021 8.0.27 GA: Support for InnoDB ClusterSet $ whoami && history Copyright © 2024, Oracle and/or its affiliates. All rights reserved. 8 ~/belgian_days_24
  • 9. $ whoami miguel_araujo $ history –E 20.09.2015 MySQL Router 1st labs release 06.09.2016 2.1.0 labs: InnoDB Cluster integration 12.04.2017 2.1.3 GA: 1st GA release 22.07.2019 8.0.17 GA: Support for GR notifications, REST API 19.10.2021 8.0.27 GA: Support for InnoDB ClusterSet 18.07.2023 8.1.0: Support for InnoDB Cluster Read Replicas, Statement tracing $ whoami && history Copyright © 2024, Oracle and/or its affiliates. All rights reserved. 9 ~/belgian_days_24
  • 10. $ whoami miguel_araujo $ history –E 20.09.2015 MySQL Router 1st labs release 06.09.2016 2.1.0 labs: InnoDB Cluster integration 12.04.2017 2.1.3 GA: 1st GA release 22.07.2019 8.0.17 GA: Support for GR notifications, REST API 19.10.2021 8.0.27 GA: Support for InnoDB ClusterSet 18.07.2023 8.1.0: Support for InnoDB Cluster Read Replicas, Statement tracing 25.10.2023 8.2.0: R/W Splitting $ whoami && history Copyright © 2024, Oracle and/or its affiliates. All rights reserved. 10 ~/belgian_days_24
  • 11. Copyright © 2023, Oracle and/or its affiliates. All rights reserved. 11 Technicalities
  • 12. 12 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. Architecture Harness Loader routing connection _pool Util Libs metadata_cache http_server F r o n t e n d MySQL Shell ... MySQL MySQL MySQL
  • 13. 13 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. Built-in plugins routing Routing endpoints logic destination_status Keep track of the state of the routing destinations connection_pool Connection pool metadata_cache Keep track of the MySQL Architectures state / metadata changes logger Logging utility syslog Unix based OSes logging: syslog eventlog Windows OSes logging: eventlog http_server HTTP server to handle REST API request http_auth_realm Authentication realm for the http_server http_auth_backend Authentication backend for the http_server ~/mysql-server/router/src/
  • 14. 14 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. Built-in plugins io Abstraction for IO OS layer rest_api General REST API handler rest_metadata_cache Metadata cache REST API handler rest_router Global Router REST API handler rest_routing Routing endpoint REST API handler router_openssl OpenSSL library integration router_protobuf Protobuf library integration ~/mysql-server/router/src/
  • 15. Copyright © 2024, Oracle and/or its affiliates. All rights reserved. 15 Router and MySQL Architectures
  • 16. 16 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. Core component of MySQL Architectures Transparent access to Database Architecture • Transparent client connection routing • Load balancing • Application connection failover • Little to no configuration needed • Stateless design • Part of the application stack • Full integration into MySQL Architectures • InnoDB Cluster • InnoDB ReplicaSet • InnoDB ClusterSet • InnoDB Cluster Read Replicas • 3 TCP Ports: • PRIMARY traffic • SECONDARY traffic • RW splitting ! New in 8.1.0 ! New in 8.2.0
  • 17. Auto-configuration for the MySQL Architecture • Fetches the topology Metadata information from one of the servers • Stores it in a dynamic file (data/state.json) • Registers itself in the Metadata schema • Creates a configuration file ready to be used • Creates daemon start/stop scripts 17 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. Bootstrapping MySQL Router
  • 18. It’s possible to use Router without bootstrapping, however… 18 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. Manual configuration [DEFAULT] ... [routing:primary] bind_address = localhost bind_port = 3331 destinations = myserver_xyz:3306 routing_strategy = first-available [routing:secondaries] bind_address = localhost bind_port = 3332 destinations = myserver_foo:3306, myserver_bar:3306 routing_strategy = round-robin-with-fallback ~/testbase/router/my.conf
  • 19. • Needed to route queries to the appropriate backend of the topology • Refreshed each [metadata_cache::ttl] • Default: 0.5 sec • ClusterSet: 5 sec 19 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. Metadata Cache mysql_innodb_cluster_metadata metadata_cache MySQL Shell GR MySQL MySQL Router
  • 20. • Push notifications sent via X protocol: • group_replication/membership/quorum_loss • group_replication/membership/view • group_replication_status/role_change • group_replication/status/state_change • Router keeps an open connection to the X Plugin port waiting for push notifications • For every change, if needed, the metadata cache is updated • Allows reducing drastically the TTL 20 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. GR Notifications mysql_innodb_cluster_metadata metadata_cache MySQL Shell GR MySQL MySQL Router
  • 21. 21 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. Deploying MySQL Router 1. Install MySQL Router 2. Bootstrap 3. Start it! $ mysqlrouter --bootstrap clusteradmin@brussels:3306 --directory my_router --account router_admin --conf-use-gr-notifications $ my_router/start.sh ~/testbase/router
  • 22. 22 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. Deploying MySQL Router It’s recommended to deploy Router on the same host as the application and enable GR notifications. That allows: • Using sockets instead of TCP/IP • Decreasing network latency • Fine-grained account access • Scaling-out!
  • 23. 23 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. Deploying MySQL Router It’s recommended to deploy Router on the same host as the application and enable GR notifications. That allows: • Using sockets instead of TCP/IP • Decreasing network latency • Fine-grained account access • Scaling-out! Alternatively, it’s possible to deploy multiple Routers in multiple machines under a VIP.
  • 24. Copyright © 2024, Oracle and/or its affiliates. All rights reserved. 24 Connection Sharing and Reuse
  • 25. • Based on a Connection Pool • Re-use server-side connections that the client wanted to close, saving the setup costs of establishing new ones • Share server-side connections where the client is idling on an active connection, to reduce the number of open server-side connections freeing up resources bound to those idle connections 25 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. Connection Sharing and Reuse MySQL Router
  • 26. • Configurable with • connection_sharing (disabled by default) • connection_sharing_delay (1 by default) • Seconds to wait before moving an idle connection to the pool • idle_timeout (5 by default) • How many seconds to keep a connection in the pool after the client disconnects • max_idle_server_connections (disabled by default) • How many open connections can be kept in the pool after the client disconnects 26 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. Connection Sharing and Reuse MySQL Router
  • 27. Copyright © 2024, Oracle and/or its affiliates. All rights reserved. 27 TLS Session Caching
  • 28. • TLS handshakes are slow • Cache and resume TLS sessions from: • Client to Router • Router to Server • Saves time and resources by reducing the connection handshake • Enabled by default • Client and Server side caches, configurable with: • _ssl_session_cache_mode: enable/disable • _ssl_session_cache_size: max number of cached sessions • _ssl_session_cache_timeout: cache timeout 28 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. TLS Session Caching ! New in 8.1.0 MySQL Router
  • 29. Copyright © 2024, Oracle and/or its affiliates. All rights reserved. 29 REST API
  • 30. • Built on top of the HTTP Server plugin • Follows the OPENAPI 2.0 spec • Exposes a Swagger file to describe the REST API: ü Metadata cache config ü Metadata cache status ü Metadata cache instances list ü Router status ü Routing plugin status ü Routes config / status / health / destination / connections ü Routes list ü Blocked hosts 30 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. REST API
  • 31. 31 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. $ curl -k -s -u miguel: https://localhost:8443/api/20190715/metadata/bootstrap/config | jq { "clusterName": "myCluster", "timeRefreshInMs": 500, "groupReplicationId": "1e6598b4-baab-11ee-adc4-d08e7912e4ee", "nodes": [ { "hostname": "127.0.0.1", "port": 3310 }, { "hostname": "127.0.0.1", "port": 3320 }, { "hostname": "127.0.0.1 ~
  • 32. 32 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. $ curl -k -s -u miguel: https://localhost:8443/api/20190715/routes | jq { "items": [ { "name": "bootstrap_ro” }, { "name": "bootstrap_rw” }, { "name": "bootstrap_rw_split” }, { "name": "bootstrap_x_ro” }, ~
  • 33. 33 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
  • 34. 34 Copyright © 2024, Oracle and/or its affiliates. All rights reserved.
  • 35. Copyright © 2024, Oracle and/or its affiliates. All rights reserved. 35 MySQL Rest Service (MRS)
  • 36. MySQL REST Service • Fast and powerful way to serve data to client applications via a HTTPS REST interface • Implemented as a MySQL Router feature • Built on the concepts of ORDS, focusing on the strengths of MySQL • Not as powerful as ORDS (PL/SQL based) • Focus on MySQL performance • Focus on MySQL scalability • Using MySQL/HeatWave as metadata storage, not depending on an OracleDB instance • Auto REST for tables, views, and procedures • GUI Frontend with MySQL Shell for VSCode 36 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. Key takeaways
  • 37. 37 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. Key takeaways RESTful Web Services • Auto REST for tables, views, procedures and functions • {JSON} responses with paged results • Developer support (GUI, CLI, API) • Support for popular OAuth2 services JSON/Relational Duality • Full support SQL support for JSON/Relational REST endpoints • Visual Duality Editor - Build complex JSON structures with a few clicks • SQL & SDK interface preview Full SQL Support & SDK API • Fully manageable through SQL • CREATE REST DUALITY VIEW statements • Tailored SDK for all RESTful Endpoints • Popular, Prisma-like API, live prototyping sql> CREATE OR REPLACE REST DUALITY VIEW /country ON SERVICE /myService SCHEMA /sakila AS sakila.country { countryId: country_id @SORTABLE, country: country, lastUpdate: last_update, cities: sakila.city @INSERT @UPDATE @DELETE { city: city } }; sql> CONFIGURE REST METADATA; sql> CREATE REST SERVICE /myService; sql> CREATE REST SCHEMA /sakila FROM `sakila`; TypeScript SDK API with live prototyping of REST queries Full JSON/Relational Duality Support via SQL and GUI
  • 38. 38 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. MySQL REST Service Architecture ... MySQL Router MySQL Router MySQL Router MySQL Router … MySQL Shell OAuth2 Service MySQL / MDS Client App Client App Client App … Client App Client App Client App Client App Client App Client App … Client App Client App Client App MRS Plugin Auth HTTPS Server Load Balancer Load Balancer MRS Metadata Schema MySQL Shell for VS Code ...
  • 39. Copyright © 2024, Oracle and/or its affiliates. All rights reserved. 39 R/W Splitting
  • 40. • Motivation: • 1 port to rule them all • Up to now, the application had to be aware of the type of transaction to use either the RW or the RO port • It’s performant, but limits the usage of Router • Work it works: • Router classifies each query as read or write automatically and forwards to the appropriate backend • It’s also possible to manually or programmatically to specify the type of query using • ROUTER SET • query_attributes 40 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. R/W Splitting ! New in 8.2.0
  • 41. 41 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. R/W Splitting ! New in 8.2.0 mysqlsh-sql> SELECT 1; // SECONDARY mysqlsh-sql> INSERT INTO tlb VALUES (1) // PRIMARY mysqlsh-sql> START TRANSACTION READ_ONLY; // SECONDARY mysqlsh-sql> CREATE TEMPORARY TABLE tbl (id int); // SECONDARY mysqlsh-sql> SELECT * FROM tbl; // SECONDARY mysqlsh-sql> COMMIT; // SECONDARY mysqlsh-sql> query_attributes router.access_mode read_write; mysqlsh-sql> select @@port; // PRIMARY ~
  • 42. 42 Copyright © 2024, Oracle and/or its affiliates. All rights reserved. R/W Splitting • The query is sent to the PRIMARY if the access_mode is read_write • The query is sent to the SECONDARY if the access_mode is read_only • If the access_mode is auto, a query is sent to a SECONDARY if: • Inside a READ_ONLY transaction, or • Router attribute for access mode set (router.access_mode), or • Outside a transaction, the connection allows sharing and the statement is a “read-only” statement • If none of the above is met, the query is sent to the PRIMARY
  • 43. Copyright © 2024, Oracle and/or its affiliates. All rights reserved. 43 Thank you! Questions?