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

Readwrite-splitting

  1. rules:
  2. - !READWRITE_SPLITTING
  3. dataSources:
  4. <data_source_name> (+): # Logic data source name of readwrite-splitting
  5. write_data_source_name: # Write data source name
  6. read_data_source_names: # Read data source names, multiple data source names separated with comma
  7. transactionalReadQueryStrategy (?): # Routing strategy for read query within a transaction, values include: PRIMARY (to primary), FIXED (to fixed data source), DYNAMIC (to any data source), default value: DYNAMIC
  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. # ...

Please refer to Built-in Load Balance Algorithm List for more details about type of algorithm.

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. writeDataSourceName: write_ds
  6. readDataSourceNames:
  7. - read_ds_0
  8. - read_ds_1
  9. transactionalReadQueryStrategy: PRIMARY
  10. loadBalancerName: random
  11. loadBalancers:
  12. random:
  13. type: RANDOM