Sending traffic through the routing layer
You can route an application through the routing endpoint of a database cluster group for Aurora one application at a time, when you choose. Other applications keep connecting directly to their member clusters. Both are supported ways to connect, and every member cluster stays directly reachable through its own endpoints. To go back, you point the application at its member cluster endpoint again. Nothing changes on the member clusters, because the routing layer reaches the same data.
You route an application by changing its connection settings or directory entries. First, check the statements that it sends and the routing and data. Then route retry-safe work, then reads, then writes.
Testing an existing application before you route it
To reach an existing cluster's databases through the routing endpoint, map them where they are. First, run a compatibility pass with the application's own workload on an Aurora clone of the cluster. Run it in a database cluster group for Aurora that you use for testing, never in the production group. For more information about clones, see Cloning a volume for an Amazon Aurora DB cluster.
In the compatibility pass, check the following through the routing endpoint:
-
The statements that the routing layer refuses or answers itself. For more information, see Statement compatibility.
-
Where DDL runs: on the member cluster, over a direct connection or a session pinned at the routing endpoint.
-
Whether the driver connects over TLS, and the session variables that it reads at connect time.
-
Pool lifetimes against the routing layer's idle close, and pool sizes against the member cluster's
max_connections. -
Reads that use the reader endpoint today. Routed statements run on the writer, so keep replica reads on direct connections to the reader endpoint.
Keep an application on its direct connection while the routing layer refuses a critical path or the driver can't connect. When the pass is clean, check each database as described in the "Before you map an existing database" checklist. Then map each database at database level, each in its own collocation, as described in Mapping a database, and route one application at a time.
To go back, point the application at the cluster endpoint again. Nothing changes on the cluster, because the routing layer reaches the same data. To decide later whether to place databases on other member clusters, record the size of each database and each table's share of statement time.
Checking a captured workload against a group
Before you map a database, run a move, or route an application through the routing layer, capture the statements and transactions that the application sends. Then find the ones that don't route to one member cluster. Each instance keeps its statement statistics in memory, so list every instance, writer and readers, that serves the application's traffic. Before a move, that is every instance of every member cluster.
You can capture from the engine's statement statistics and transaction history, the slow query log, the general log, the audit log, or the application's own SQL. The general log adds overhead, so keep its window short. The capture statements follow the procedure.
To check a captured workload against a group
-
On each instance, over a direct connection, record the current capture settings, then turn on statement and transaction history. The capture adds overhead while it's enabled.
-
On each instance (direct), over a representative window that includes batch jobs and reports, read the statement statistics and history, one instance at a time. Record each instance's capture window and statement count.
-
At the routing endpoint, map each table to its collocation from the current mapping rows and routing functions, or from the mappings that you plan to write. Translate cluster table names to router table names.
-
In your captured data, flag the statements that don't route to one member cluster, as listed after this procedure.
-
On each instance (direct), turn the capture off, and restore the settings that you recorded.
The capture uses performance_schema. It's a static parameter, so turning it on takes effect only after each instance reboots.
Step 1. Record the transaction instrument and history consumers, then turn them on.
SELECT NAME, ENABLED, TIMED FROM performance_schema.setup_instruments WHERE NAME = 'transaction'; UPDATE performance_schema.setup_instruments SET ENABLED = 'YES', TIMED = 'YES' WHERE NAME = 'transaction'; UPDATE performance_schema.setup_consumers SET ENABLED = 'YES' WHERE NAME IN ('events_transactions_history_long', 'events_statements_history_long');
Step 2. Read events_statements_summary_by_digest, events_transactions_history_long, and events_statements_history_long in performance_schema. Record the digest count.
Step 5. Turn the history consumers off, and restore the instrument setting that you recorded.
UPDATE performance_schema.setup_consumers SET ENABLED = 'NO' WHERE NAME IN ('events_transactions_history_long', 'events_statements_history_long');
In step 4, flag the following:
-
Statements on scaleout tables that omit the routing key, or don't constrain it with
=orIN. -
Multi-row writes whose keys can spread across collocations.
-
Every statement, join, and transaction that reaches two collocations. A transaction runs on the member cluster of its first routable statement, and the routing layer refuses a later statement for another member cluster.
-
Before a move, anything that reaches the moving collocation and another collocation, and, on Aurora MySQL, a source member cluster that runs with a
binlog_formatofSTATEMENTorMIXED. -
Statement shapes that the routing layer refuses or answers itself. For more information, see Statement compatibility.
The result is a report with each finding traced to an instance, a source, and the window. Before a move, give one verdict for each collocation: no statement reaches another collocation, or a list of statements to change first. The verdict covers only the sources, instances, and window that you captured.
To confirm the result, replay the workload on a database cluster group for Aurora that you use for testing, with each collocation on its own member cluster. The routing layer refuses each statement that crosses collocations, as it does after a move. For the error code, see Error codes for database cluster groups for Aurora. Then put a check in the application or your CI pipeline. Run it log-only in production first, with a known-violations list and an owner for each statement shape. Enforce it only when nothing remains outside the list.
Checking routing and data
Run these read-only checks after you map a database, before you route an application, after a move, and after a conversion. Export the mappings before and after each step, as described in Exporting the mappings before and after a change.
-
One routed read for each mapping. At the routing endpoint, read each router name. For a scaleout table, read one known key in each collocation. Compare the rows with the same read on the member cluster's own endpoint.
-
Routing with
EXPLAIN. On Aurora MySQL, run plainEXPLAINat the routing endpoint on the busiest statements. The first row comes from the routing layer and names the target member cluster, and the member cluster's plan follows. Use plainEXPLAIN, becauseEXPLAIN ANALYZEruns aSELECTin full on the member cluster. For a data change statement,EXPLAIN ANALYZEdoesn't change any rows. On Aurora MySQL, for a multi-tableUPDATEorDELETE, it runs the plan and shows timing. For a single-tableUPDATEorDELETE, it returns<not executable by iterator executor>, with no plan and no timing. For anINSERTwithVALUESor aREPLACE, it shows the plan with no timing, and for anINSERT ... SELECTit times theSELECT. For more information, see EXPLAIN. -
Counts and checksums. On each member cluster directly, compare row counts and checksums for each table between the source and the target of the step. Compare in bounded primary-key ranges on large tables. A move drops its source copy when it completes, so take the comparison values from the source before the move.
-
Collation and character set. Compare them for each table and column across every member cluster that holds a copy or a member table. A difference changes sort order.
Routing one application at a time
Before you begin, size the application's pools for each member cluster, and set them to retire connections before the routing layer's idle close. The routing endpoint requires TLS 1.2 or TLS 1.3 and refuses a connection without TLS, so configure the application's driver for TLS. For more information, see Connecting to the routing endpoint, Managing connections, and Encryption in transit (TLS) and at rest.
In query routing mode, the application names databases and tables by their router names, and each statement reaches the one member cluster that holds its data. On Aurora MySQL, a connection to the routing endpoint uses query routing mode by default. For the modes, see Sessions, transactions, and session pinning. In query routing mode, check that the application works with the following behaviors before you route it:
-
DDL runs on the member clusters. Query routing mode refuses
CREATE TABLE,ALTER TABLE, and other data definition statements. Run them on each member cluster through its own endpoint, or through a session pinned to it. TheSCALEOUTstatements, statements ondbclustergroup_systables, and router user management run through the routing endpoint. -
The member cluster checks privileges. A permission error arrives with the first statement that reaches a member cluster, not when the application signs in.
-
The member cluster checks session settings. The member cluster checks a
SETfor a parameter that it owns when the next statement reaches it. A bad value fails then, not at theSET. Set session parameters when the connection opens.
For the statements that route, see Statement compatibility.
To route an application through the routing endpoint
-
Rehearse routing the application, and pointing it back, on a group that you use for testing, with realistic data volume and load. Time each step.
-
Write a checklist from the rehearsal. For each step, name the application or lane that it routes, the check that confirms it, the go or no-go condition, and the exact setting to change back.
-
In the connection settings, route work that is safe to retry first, such as reports, read-only jobs, and idempotent queue consumers.
-
In the connection settings, route the application's reads, one application instance at a time. Routed reads run on each member cluster's writer, so reads that used Aurora Replicas now load the writer. Check the writer's headroom, or keep replica reads on direct connections to the member cluster's reader endpoint or instance endpoints.
-
Verify the reads, then route the application's writes, for each application or directory entry, never for each statement. Each workload then writes through one path at a time.
-
Hold each step for its observation window, then continue with the next application or stop. Keep the direct connection settings so that you can point the application back.
Before you continue from each step, confirm that one routed read for each member cluster returns the expected rows, the application's error rate is at its baseline, and its logs show no refused statement. Compare the member clusters' load side by side as each one takes routed traffic. For more information, see Monitoring database cluster groups for Aurora.
A data mapping change reaches the routing layer within a short time. A statement routed on the older mapping gets an error that the application retries, and the session stays open. Inside a transaction, a statement that needs a mapping changed after the transaction's first routed statement fails with error 63928, and the routing layer rolls back the transaction. Make the application retry on that error before you route it. For the error codes and the retry rule, see Applying data mapping changes.
Pointing an application back at its member cluster
To go back at any step, change the application's connection setting or directory entry back to its member cluster endpoint. No data needs to be copied, and nothing changes on the member clusters. The routing layer reaches the same data as direct connections, so writes made through it are already there. If a data movement job moved a collocation since you routed the application, read the mapping rows and connect directly to the member cluster that holds it now. Applications that use a scaleout table stay on the routing endpoint, because its rows are spread over several member clusters.
To stop routing a workload completely, do the following in order:
-
Point the application at its member cluster endpoints, with the cluster database names.
-
Export the mappings, then delete the data mappings that you stop routing, outside a transaction. The delete removes the routing entry, not the data.
-
When no application uses the routing endpoint, you can disable routing. With the AWS CLI, call
ModifyDBClusterGroup(aws rds modify-db-cluster-group) withEnableRoutingset to false (--no-enable-routing). Wait until the group readsavailablebefore the next group change. For more information, see Creating, modifying, and deleting a database cluster group for Aurora.
The member clusters stay in the group, and the group's coordinated operations, backup and restore, and monitoring keep covering them. To take a cluster out of the group as well, see Removing a member cluster.
For the parameters, see the Amazon RDS API Reference.
Related pages
The following pages cover related tasks and concepts.