MySQL Shell 9.2  /  ...  /  Edit Routing Guidelines

7.8.4 Edit Routing Guidelines

This section describes how to edit Routing Guidelines. The following topics are described:

Adding Routes and Destinations

Routes and destinations can be added using the following:

  • RoutingGuideline.add_route(name, match, destinations[, options])

    • name: the name of the route.

    • match: the match expression for incoming client sessions.

    • destinations: array of destination selectors in the form of "strategy( destination, ...)"

    • options:

      • enabled: whether the route is active. Default value is true.

      • connectionSharingAllowed : whether the route allows connection sharing. Default value is true.

      • dryRun : if set to true, validates the rule without applying it to the Routing Guideline. Default value is false.

      • order: position of a route within the Routing Guideline. Lower values indicate higher priority.

    The following example adds a route, RG1, to the Routing Guideline, specifying that client connections targeting ports 6446 or 6448 are redirected to the Cluster's Primary instance, using the first-available MySQL Router strategy:

    Press CTRL+C to copy
    rg.add_route("RG1", "$.session.targetPort in (6446, 6448)", ["first-available(Primary)"])

  • RoutingGuideline.add_destination(name, match[, options])

    • name: name of the destination class.

    • match: matching expression for MySQL instances.

    • options: optional dictionary with additional options. Currently, only dryRun is supported.

The following example adds a destination class named US_Instances and defines the server pool as those servers in the us-east-1.example.com and us-west-2.example.com domains.

Press CTRL+C to copy
rg.add_destination("US_Instances", "$.server.address in ['us-east-1.example.com', 'us-west-2.example.com']")

Removing Routes and Destinations

Routes and destinations can be removed using the following:

  • RoutingGuideline.remove_route(name)

  • RoutingGuideline.remove_destination(name)

The following examples show how to remove a route, Route1, and a destination, Destination1, from the selected Routing Guideline:

Press CTRL+C to copy
RoutingGuideline.remove_route("Route1")
Press CTRL+C to copy
RoutingGuideline.remove_destination("Destination1")

Modifying Route and Destination Options

Routes and destinations can be modified using the following:

  • RoutingGuideline.set_destination_option(destinationName, option, value)

    • destinationName: name of the destination to update.

    • option: name of the option to update.

      • match: matching expression defining the server pool for this destination.

    • value: the new value for the specified option.

  • RoutingGuideline.set_route_option(routeName, option, value)

    • routeName: name of the route to update.

    • option: name of the option to update.

      • match: matching expression for the incoming client session.

      • destinations: list of destinations using routing strategies in the format strategy(destination1, destination2, ...), ordered by priority, highest to lowest .

      • enabled: whether the route is active. Default value is true.

      • connectionSharingAllowed : whether the route allows connection sharing. Default value is true.

      • order: position of a route within the Routing Guideline. Lower values indicate higher priority.

    • value: the new value for the specified option.

The following example updates a destination named EU_Regions to include a candidate server pool from the eu-central-1.example.com and eu-west-1.example.com domains.

Press CTRL+C to copy
rg.set_destination_option("EU_Regions", "match", "$.server.address in ['eu-central-1.example.com', 'eu-west-1.example.com']");

The following example updates a route named read_traffic to match only read only session users.

Press CTRL+C to copy
rg.set_route_option("read_traffic", "match", "$.session.user = 'readonly_user'");

Copying a Routing Guideline

Copy a Routing Guideline using the following:

  • RoutingGuideline.copy("Name")

    • Name: is the name of the new Routing Guideline.

The following example retrieves a Cluster's Routing Guideline, default, and copies its definition to a new Routing Guideline named default_copied:

Press CTRL+C to copy
rg = cluster.get_routing_guideline("default") rg_copy = rg.copy("default_copied") Routing Guideline 'default' successfully duplicated with new name 'default_copied'.

Renaming a Routing Guideline

Rename a Routing Guideline using the following:

  • RoutingGuideline.rename("Name")

    • Name: is the new name of the Routing Guideline.

The following example retrieves a Cluster's Routing Guideline, default_copied, and renames it to default_copied_renamed:

Press CTRL+C to copy
rg = cluster.get_routing_guideline("default_copied") rg_rename = rg.rename("default_copied_renamed") Successfully renamed Routing Guideline 'default_copied' to 'default_copied_renamed'