MySQL Shell 9.3
To retrieve all the Routing Guidelines associated with the Cluster, use the following:
cluster
.routing_guidelines()
For example, the cluster has two Routing Guidelines,
default
and rg1
:
+-----------+--------+--------+-------------------------------+ | guideline | active | routes | destinations | +-----------+--------+--------+-------------------------------+ | default | 0 | rw,ro | Primary,Secondary,ReadReplica | | rg1 | 0 | rw,ro | Primary,Secondary,ReadReplica | +-----------+--------+--------+-------------------------------+
To retrieve a specific Routing Guideline associated with the cluster, use the following:
cluster
.get_routing_guideline("name")
If you do not provide a name, the active Routing Guideline is retrieved.
To view a detailed summary of the Routing Guideline, use the following:
rg
.show()
returns the following:
rg
.show()
The name of the Routing Guideline and the connected topology.
The routes, including the match expression and resolved
destinations of the topology. If the "router",
"
option is defined, that router is used to evaluate the
guideline.
routeIdentifier
"
If no destinations are matched, None
is
returned.
All destination classes defined by the Routing Guideline, including the match expression and the topology members which match the expression.
Unreferenced servers
lists topology
members not referenced by a route or destination class.
For example:
Py > rg.show() Routing Guideline: 'default' Cluster: 'mycluster' Routes ------ - rw + Match: "$.session.targetPort = $.router.port.rw" + Destinations: * 127.0.0.1:4000 (Primary) - ro + Match: "$.session.targetPort = $.router.port.ro" + Destinations: * 127.0.0.1:4001, 127.0.0.1:4002 (Secondary) * 127.0.0.1:4000 (Primary) Destination Classes ------------------- - Primary: + Match: "$.server.memberRole = PRIMARY" + Instances: * 127.0.0.1:4000 - Secondary: + Match: "$.server.memberRole = SECONDARY" + Instances: * 127.0.0.1:4001 * 127.0.0.1:4002 - ReadReplica: + Match: "$.server.memberRole = READ_REPLICA" + Instances: * None Unreferenced servers -------------------- - None
To view the Routing Guideline as a JSON document, use the following:
rg
.as_json()
For example:
Py > rg.as_json() { "destinations": [ { "match": "$.server.memberRole = PRIMARY", "name": "Primary" }, { "match": "$.server.memberRole = SECONDARY", "name": "Secondary" }, { "match": "$.server.memberRole = READ_REPLICA", "name": "ReadReplica" } ], "name": "default", "routes": [ { "connectionSharingAllowed": true, "destinations": [ { "classes": [ "Primary" ], "priority": 0, "strategy": "round-robin" } ], "enabled": true, "match": "$.session.targetPort = $.router.port.rw", "name": "rw" }, { "connectionSharingAllowed": true, "destinations": [ { "classes": [ "Secondary" ], "priority": 0, "strategy": "round-robin" }, { "classes": [ "Primary" ], "priority": 1, "strategy": "round-robin" } ], "enabled": true, "match": "$.session.targetPort = $.router.port.ro", "name": "ro" } ], "version": "1.1" }
To view the destinations defined in the Routing Guideline, use the following:
rg
.destinations()
For example:
Py > rg.destinations() +-------------+------------------------------------+ | destination | match | +-------------+------------------------------------+ | Primary | $.server.memberRole = PRIMARY | | Secondary | $.server.memberRole = SECONDARY | | ReadReplica | $.server.memberRole = READ_REPLICA | +-------------+------------------------------------+
To view the destinations defined in the Routing Guideline, use the following:
rg
.routes()
For example:
rg.routes() +------+---------+-----------+-----------------------------------------+----------------------------------------------+-------+ | name | enabled | shareable | match | destinations | order | +------+---------+-----------+-----------------------------------------+----------------------------------------------+-------+ | rw | 1 | 1 | $.session.targetPort = $.router.port.rw | round-robin(Primary) | 0 | | ro | 1 | 1 | $.session.targetPort = $.router.port.ro | round-robin(Secondary), round-robin(Primary) | 1 | +------+---------+-----------+-----------------------------------------+----------------------------------------------+-------+
The table returned contains the following columns:
name
: the name of the route.
enabled
: (boolean) whether the route is
enabled.
shareable
: (boolean) whether the
connection is shareable.
match
: the matching rule for the client
connection.
destinations
: comma-separated list of
destinations, ordered by priority.
order
: the position of the route
withing the Routing Guideline.