Logo
Traffic Dual Routing

Traffic Dual Routing #

Instruction for Use #

The traffic dual routing function needs to use the hybrid deployment architecture, deploy DBPlusEngine-Driver and DBPlusEngine-Proxy at the same time, and uniformly manage the functional such as sharding, encryption and decryption or read-write splitting through the registry

Because the Traffic Dual Routing must be configured with DBPlusEngine-Proxy, traffic rules can only be added through YAML configuration or DistSQL at the access end of DBPlusEngine-Proxy. In addition, in order to cooperate with the traffic function, the DBPlusEngine-Proxy access terminal needs to configure the labels tag for the configuration of traffic forwarding.

Configuration Item Description #

rules:
- !TRAFFIC
  trafficStrategies:
    sql_match_traffic:
      labels: 
        - OLTP
      algorithmName: sql_match_algorithm
      loadBalancerName: random_load_balancer
    sql_regex_traffic:
      labels: 
        - OLTP
      algorithmName: sql_regex_algorithm
      loadBalancerName: random_load_balancer
    sql_hint_traffic:
      labels: 
        - OLAP
      algorithmName: sql_hint_algorithm
      loadBalancerName: round_robin_load_balancer
    transaction_traffic:
      # Optional configuration. The algorithms are JDBC and FIRST_SQL does not need to be configured.
      labels: 
        - OLAP
        - OLTP
      algorithmName: transaction_algorithm
      # Optional configuration. The algorithms are JDBC and FIRST_SQL does not need to be configured.
      loadBalancerName: round_robin_load_balancer
  trafficAlgorithms:
    sql_match_algorithm:
      type: SQL_MATCH
      props:
        sql: SELECT * FROM t_order WHERE content IN (?, ?); UPDATE t_order SET creation_date = NOW() WHERE user_id = 1;
    sql_regex_algorithm:
      type: SQL_REGEX
      props:
        regex: (?i)^(UPDATE|SELECT).*WHERE user_id.*
    sql_hint_algorithm:
      type: SQL_HINT
    transaction_algorithm:
      # Support FIRST_SQL, JDBC and proxy
      # FIRST_ SQL will determine the forwarding result of the transaction unit according to the forwarding result of the first SQL
      # JDBC will execute the transaction unit on JDBC without forwarding
      # Proxy will forward the transaction unit to the proxy instance. In order to ensure the consistency of data, the transaction unit will execute on the same instance.
      type: PROXY
  loadBalancers:
    random_load_balancer:
      type: RANDOM
    round_robin_load_balancer:
      type: ROUND_ROBIN
      
labels: 
  - OLTP

YamlTrafficRuleConfiguration configuration item description:

NameData TypeDescription
trafficStrategiesMap<String, YamlTrafficStrategyConfiguration>Forwarding policy, required. By default, they are matched in the order of configured policies. The first matching policy is the target policy. If the user has configured the transaction forwarding policy, the transaction forwarding policy will be matched first.
trafficAlgorithmsMap<String, YamlShardingSphereAlgorithmConfiguration>Forwarding matching algorithm, required.
loadBalancersMap<String, YamlShardingSphereAlgorithmConfiguration>Forwarding load balancing policy, required.

YamlTrafficStrategyConfiguration configuration item description:

NameData TypeDescription
nameStringForwarding policy name, required.
labelsCollectionForward the Proxy instance tag when algorithmName is configured as JDBC or FIRST_SQL, no configuration is required, and other algorithms are required.
algorithmNameStringForwarding matching algorithm, required.
loadBalancerNameStringForwarding load balancing algorithm, when algorithmname is configured as JDBC or FIRST_SQL, no configuration is required, and other algorithms are required.

Built-in Forwarding Matching Algorithm #

Hint Based Forwarding Matching Algorithm #

Hint Forwarding Matching Algorithm Based on SQL #

Type: SQL_HINT Configurable properties:

The SQL Hint function requires the user to turn on the configuration of parsing comments in advance, set sqlCommentParseEnabled to true, and the comment format only supports /* */ temporarily. The content needs to start with ShardingSphere hint:. The user can turn on and off the SQL hint forwarding matching algorithm by setting the useTraffic=true or useTraffic=false.

Forwarding Matching Algorithm Based on Segment (SegmentTrafficAlgorithm) #

String Forwarding Matching Algorithm Based on SQL #

String forwarding matching algorithm based on SQL

Type: SQL_MATCH

Configurable properties:

Attribute NameData TypeDescription
sqlStringIt is used to configure SQL strings. Multiple SQL strings are separated by semicolons. The SQL string matching algorithm ignores case and blank characters.

Regular Forwarding Matching Algorithm Based on SQL String #

Type: SQL_REGEX

Configurable properties:

NameData TypeDescription
regexStringUsed to configure regular expressions.

TransactionTrafficAlgorithm #

Forwarding Matching Algorithm Based on the First SQL #

Type: FIRST_SQL

Configurable attribute: None

Unified Forwarding JDBC Matching Algorithm #

Type: JDBC

Configurable attribute: None

Unified Forwarding Proxy Matching Algorithm #

Type: PROXY

Configurable attribute: None

Built-in Forwarding Load Balancing Algorithm #

TrafficLoadBalanceAlgorithm #

Load balancing Algorithm for Random Proxy Instances #

Type: RANDOM

Configurable attribute: None

Load Balancing Algorithm for Polling Proxy Instances #

Type: ROUND_ROBIN

Configurable attribute: None

Feature Description of Traffic Rule