Logo
Read/write splitting

Read/write splitting #

Description of configuration items #

Static read/write splitting #

rules:
  - !READWRITE_SPLITTING
    dataSources:
      <data-source-name> (+): # Logical data source name for read-write separation
        writeDataSourceName: write_ds # Write database data source name
        readDataSourceNames: # Read database data source names, multiple read data sources are separated by commas
          - read_ds_0
          - read_ds_1
        transactionalReadQueryStrategy (?): # Routing strategy for read requests within a transaction. Optional values: PRIMARY (routed to the primary database), FIXED (routed to a fixed data source within the same transaction), DYNAMIC (routed to a non-fixed data source within the same transaction). Default: DYNAMIC
        loadBalancerName:  # Load balancing algorithm name
    
    # Load balancing algorithm configuration
    loadBalancers:
      <load-balancer-name> (+): # Load balancing algorithm name
        type: # Load balancing algorithm type
        props: # Load balancing algorithm property configuration
        # ...

Dynamic read/write splitting #

rules:
  - !READWRITE_SPLITTING
    dataSources:
      <data-source-name> (+): # Logical data source name for read-write separation
        autoAwareDataSourceName: replica_ds # Database discovery data source name
        writeDataSourceQueryEnabled: # When all replica data sources are offline, whether the primary data source should handle read traffic
        transactionalReadQueryStrategy (?): # Routing strategy for read requests within a transaction. Optional values: PRIMARY (routed to the primary database), FIXED (routed to a fixed data source within the same transaction), DYNAMIC (routed to a non-fixed data source within the same transaction). Default: DYNAMIC
        loadBalancerName:  # Load balancing algorithm name
    
    # Load balancing algorithm configuration
    loadBalancers:
      <load-balancer-name> (+): # Load balancing algorithm name
        type: # Load balancing algorithm type
        props: # Load balancing algorithm property configuration
        # ...

For details of the algorithm types, see the list of built-in load balancing algorithms.