Readwrite-splitting

Background

Read/write splitting YAML configuration is highly readable. The YAML format enables you to quickly understand the dependencies between read/write sharding rules. ShardingSphere automatically creates the ShardingSphereDataSource object according to the YAML configuration, which reduces unnecessary coding for users.

Parameters

Static Readwrite-splitting

  1. rules:
  2. - !READWRITE_SPLITTING
  3. dataSources:
  4. <data_source_name> (+): # Logic data source name of readwrite-splitting
  5. static_strategy: # Readwrite-splitting type
  6. write_data_source_name: # Write data source name
  7. read_data_source_names: # Read data source names, multiple data source names separated with comma
  8. loadBalancerName: # Load balance algorithm name
  9. # Load balance algorithm configuration
  10. loadBalancers:
  11. <load_balancer_name> (+): # Load balance algorithm name
  12. type: # Load balance algorithm type
  13. props: # Load balance algorithm properties
  14. # ...

Dynamic Readwrite-splitting

  1. rules:
  2. - !READWRITE_SPLITTING
  3. dataSources:
  4. <data_source_name> (+): # Logic data source name of readwrite-splitting
  5. dynamic_strategy: # Readwrite-splitting type
  6. auto_aware_data_source_name: # Database discovery logic data source name
  7. loadBalancerName: # Load balance algorithm name
  8. # Load balance algorithm configuration
  9. loadBalancers:
  10. <load_balancer_name> (+): # Load balance algorithm name
  11. type: # Load balance algorithm type
  12. props: # Load balance algorithm properties
  13. # ...

Please refer to Built-in Load Balance Algorithm List for more details about type of algorithm. Please refer to Read-write splitting-Core features for more details about query consistent routing.

Procedure

  1. Add read/write splitting data source.
  2. Set the load balancer algorithm.
  3. Use read/write data source.

Sample

  1. rules:
  2. - !READWRITE_SPLITTING
  3. dataSources:
  4. readwrite_ds:
  5. staticStrategy:
  6. writeDataSourceName: write_ds
  7. readDataSourceNames:
  8. - read_ds_0
  9. - read_ds_1
  10. loadBalancerName: random
  11. loadBalancers:
  12. random:
  13. type: RANDOM