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
rules:
- !READWRITE_SPLITTING
dataSources:
<data_source_name> (+): # Logic data source name of readwrite-splitting
write_data_source_name: # Write data source name
read_data_source_names: # Read data source names, multiple data source names separated with comma
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
loadBalancerName: # Load balance algorithm name
# Load balance algorithm configuration
loadBalancers:
<load_balancer_name> (+): # Load balance algorithm name
type: # Load balance algorithm type
props: # Load balance algorithm properties
# ...
Please refer to Built-in Load Balance Algorithm List for more details about type of algorithm.
Procedure
- Add read/write splitting data source.
- Set the load balancer algorithm.
- Use read/write data source.
Sample
rules:
- !READWRITE_SPLITTING
dataSources:
readwrite_ds:
writeDataSourceName: write_ds
readDataSourceNames:
- read_ds_0
- read_ds_1
transactionalReadQueryStrategy: PRIMARY
loadBalancerName: random
loadBalancers:
random:
type: RANDOM
Related References
当前内容版权归 ShardingSphere 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 ShardingSphere .