MySQL Shell 9.2  /  ...  /  Visualize Routing Guidelines

7.8.5 Visualize Routing Guidelines

Routing Guideline associated with the Cluster

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:

Press CTRL+C to copy
+-----------+--------+--------+-------------------------------+ | 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.

Show Detailed Information

To view a detailed summary of the Routing Guideline, use the following:

Press CTRL+C to copy
rg.show()

rg.show() returns the following:

  • 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", "routeIdentifier" option is defined, that router is used to evaluate the guideline.

    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:

Press CTRL+C to copy
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

Visualize As JSON

To view the Routing Guideline as a JSON document, use the following:

Press CTRL+C to copy
rg.as_json()

For example:

Press CTRL+C to copy
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.0" }

Destinations

To view the destinations defined in the Routing Guideline, use the following:

Press CTRL+C to copy
rg.destinations()

For example:

Press CTRL+C to copy
Py > rg.destinations() +-------------+------------------------------------+ | destination | match | +-------------+------------------------------------+ | Primary | $.server.memberRole = PRIMARY | | Secondary | $.server.memberRole = SECONDARY | | ReadReplica | $.server.memberRole = READ_REPLICA | +-------------+------------------------------------+

Routes

To view the destinations defined in the Routing Guideline, use the following:

Press CTRL+C to copy
rg.routes()

For example:

Press CTRL+C to copy
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.