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.
rules:
- !READWRITE_SPLITTING
dataSources:
<data_source_name> (+): # Logic data source name of readwrite-splitting
static_strategy: # Readwrite-splitting type
write_data_source_name: # Write data source name
read_data_source_names: # Read data source names, multiple data source names separated with comma
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
# ...
rules:
- !READWRITE_SPLITTING
dataSources:
<data_source_name> (+): # Logic data source name of readwrite-splitting
dynamic_strategy: # Readwrite-splitting type
auto_aware_data_source_name: # Database discovery logic data source name
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. Please refer to Read-write splitting-Core features for more details about query consistent routing.
rules:
- !READWRITE_SPLITTING
dataSources:
readwrite_ds:
staticStrategy:
writeDataSourceName: write_ds
readDataSourceNames:
- read_ds_0
- read_ds_1
loadBalancerName: random
loadBalancers:
random:
type: RANDOM