场景:
一个数据库,在做分库分表的同时,使用读写分离策略,同时分库1和分库2都配置了主从发现;
问题:
因为分库1和2 都分别配置了主从发现,导致master节点数量=2,报错
More than one primary data source for schemaName
我的配置文件
schemaName: sharding_db_01
dataSources:
ds_01:
url: jdbc:mysql://172.16.154.131:6066/sharding_db?serverTimezone=UTC&useSSL=false
username: sharding_proxy_user
password: 1A2B3C4D@
connectionTimeoutMilliseconds: 3000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
ds_02:
url: jdbc:mysql://172.16.154.132:6066/sharding_db?serverTimezone=UTC&useSSL=false
username: sharding_proxy_user
password: 1A2B3C4D@
connectionTimeoutMilliseconds: 3000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
ds_11:
url: jdbc:mysql://172.16.154.131:6067/sharding_db?serverTimezone=UTC&useSSL=false
username: sharding_proxy_user
password: 1A2B3C4D@
connectionTimeoutMilliseconds: 3000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
ds_12:
url: jdbc:mysql://172.16.154.132:6067/sharding_db?serverTimezone=UTC&useSSL=false
username: sharding_proxy_user
password: 1A2B3C4D@
connectionTimeoutMilliseconds: 3000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
rules:
- !DB_DISCOVERY
dataSources:
db_disc_0:
dataSourceNames:
- ds_01
- ds_02
discoveryHeartbeatName: ShowSlave-heartbeat
discoveryTypeName: dt_0
db_disc_1:
dataSourceNames:
- ds_11
- ds_12
discoveryHeartbeatName: ShowSlave-heartbeat
discoveryTypeName: dt_1
discoveryHeartbeats:
ShowSlave-heartbeat:
props:
keep-alive-cron: '0/5 * * * * ?'
discoveryTypes:
dt_0:
type: SHOW_SLAVE_STATUS
props:
watchPath: /orch/master/mysql_172.16.154.131_6066
dt_1:
type: SHOW_SLAVE_STATUS
props:
watchPath: /orch/master/mysql_172.16.154.131_6067
- !READWRITE_SPLITTING
dataSources:
ds_0:
type: Dynamic
props:
auto-aware-data-source-name: db_disc_0
write-data-source-query-enabled: false
loadBalancerName: wright_ds
ds_1:
type: Dynamic
props:
auto-aware-data-source-name: db_disc_2
write-data-source-query-enabled: false
loadBalancerName: wright_ds
loadBalancers:
wright_ds:
type: WEIGHT
props:
ds_01: 100
ds_02: 100
ds_11: 100
ds_12: 100
- !SHARDING
tables:
t_order:
actualDataNodes: ds_${0..1}.t_order_${0..1}
databaseStrategy:
standard:
shardingColumn: user_id
shardingAlgorithmName: user_inline
tableStrategy:
standard:
shardingColumn: order_id
shardingAlgorithmName: order_inline
shardingAlgorithms:
user_inline:
type: INLINE
props:
algorithm-expression: ds_${user_id % 2}
order_inline:
type: INLINE
props:
algorithm-expression: t_order_${order_id % 2}
请问应该如何正确配置来达到分库分表+读写分离的目的?