shardingsphere-jdbc 操作多个mgr(分库分表+读写分离)

方便更快捷的说明问题,可以按需填写(可删除)

使用环境:

shardingsphere-jdbc master分支 mysql 数据库 springboot mybatis-plus

场景、问题:

写了一个demo,3台服务器上有2个mgr,各自有1个主库和2个从库,对2个mgr做数据分片,各个mgr自身做读写分离,但是插入数据时可能会出现启动失败或分库失败的情况

已进行操作:

  1. 如果2个mgr的group-name设置一样,则可以正常启动,但是插入数据时,只会插入其中1个mgr,application配置文件里配置的分库策略没有生效,根据user_id % 2 分库
  2. 如果2个mgr的group-name设置的不一样,启动时会报错,提示配置的group-name和数据库的group-name不一致(实际上2个mgr各自是一致的)

现状:

shardingsphere-jdbc 现在支持多个mgr么,是不是我哪里配置错了
配置如下:

#datasource
#sharding
spring.shardingsphere.mode.type=Memory
spring.shardingsphere.datasource.names=db_1_1,db_1_2,db_1_3,db_2_1,db_2_2,db_2_3
#mgr-1-1
spring.shardingsphere.datasource.db_1_1.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.db_1_1.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.db_1_1.jdbc-url=jdbc:mysql://xxx:3307/yyy
spring.shardingsphere.datasource.db_1_1.username=root
spring.shardingsphere.datasource.db_1_1.password=root
#mgr-1-2
spring.shardingsphere.datasource.db_1_2.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.db_1_2.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.db_1_2.jdbc-url=jdbc:mysql://xxx:3307/yyy
spring.shardingsphere.datasource.db_1_2.username=root
spring.shardingsphere.datasource.db_1_2.password=root
#mgr-1-3
spring.shardingsphere.datasource.db_1_3.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.db_1_3.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.db_1_3.jdbc-url=jdbc:mysql://xxx:3307/yyy
spring.shardingsphere.datasource.db_1_3.username=root
spring.shardingsphere.datasource.db_1_3.password=root
#mgr-2-1
spring.shardingsphere.datasource.db_2_1.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.db_2_1.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.db_2_1.jdbc-url=jdbc:mysql://xxx:3308/yyy
spring.shardingsphere.datasource.db_2_1.username=root
spring.shardingsphere.datasource.db_2_1.password=root
#mgr-2-2
spring.shardingsphere.datasource.db_2_2.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.db_2_2.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.db_2_2.jdbc-url=jdbc:mysql://xxx:3308/yyy
spring.shardingsphere.datasource.db_2_2.username=root
spring.shardingsphere.datasource.db_2_2.password=root
#mgr-2-3
spring.shardingsphere.datasource.db_2_3.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.db_2_3.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.db_2_3.jdbc-url=jdbc:mysql://xxx:3308/yyy
spring.shardingsphere.datasource.db_2_3.username=root
spring.shardingsphere.datasource.db_2_3.password=root
#sys props
spring.shardingsphere.props.sql-show=true
#loadbalance
spring.shardingsphere.rules.readwrite-splitting.load-balancers.rr.type=ROUND_ROBIN
#read-write-splitting
#rw-1
spring.shardingsphere.rules.readwrite-splitting.data-sources.rw_0.type=Dynamic
spring.shardingsphere.rules.readwrite-splitting.data-sources.rw_0.load-balancer-name=rr
spring.shardingsphere.rules.readwrite-splitting.data-sources.rw_0.props.auto-aware-data-source-name=auto_datasource_1
spring.shardingsphere.rules.readwrite-splitting.data-sources.rw_0.props.write-data-source-query-enabled=true
#rw-2
spring.shardingsphere.rules.readwrite-splitting.data-sources.rw_1.type=Dynamic
spring.shardingsphere.rules.readwrite-splitting.data-sources.rw_1.load-balancer-name=rr
spring.shardingsphere.rules.readwrite-splitting.data-sources.rw_1.props.auto-aware-data-source-name=auto_datasource_2
spring.shardingsphere.rules.readwrite-splitting.data-sources.rw_1.props.write-data-source-query-enabled=true
#high available
#high-1
spring.shardingsphere.rules.database-discovery.data-sources.auto_datasource_1.data-source-names=db_1_1,db_1_2,db_1_3
spring.shardingsphere.rules.database-discovery.data-sources.auto_datasource_1.discovery-heartbeat-name=hrb_1
spring.shardingsphere.rules.database-discovery.data-sources.auto_datasource_1.discovery-type-name=mgr_1
spring.shardingsphere.rules.database-discovery.discovery-heartbeats.hrb_1.props.keep-alive-cron='0/5 * * * * ?'
spring.shardingsphere.rules.database-discovery.discovery-types.mgr_1.type=MySQL.MGR
spring.shardingsphere.rules.database-discovery.discovery-types.mgr_1.props.group-name=1efc4288-f60b-11ec-a93e-00163e0498e0
#high-2
spring.shardingsphere.rules.database-discovery.data-sources.auto_datasource_2.data-source-names=db_2_1,db_2_2,db_2_3
spring.shardingsphere.rules.database-discovery.data-sources.auto_datasource_2.discovery-heartbeat-name=hrb_2
spring.shardingsphere.rules.database-discovery.data-sources.auto_datasource_2.discovery-type-name=mgr_2
spring.shardingsphere.rules.database-discovery.discovery-heartbeats.hrb_2.props.keep-alive-cron='0/5 * * * * ?'
spring.shardingsphere.rules.database-discovery.discovery-types.mgr_2.type=MySQL.MGR
spring.shardingsphere.rules.database-discovery.discovery-types.mgr_2.props.group-name=cd85be4c-f2d4-11ec-8404-00163e0498e0
#sharding
#db
spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-column=user_id
spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-algorithm-name=db_inline
#table
spring.shardingsphere.rules.sharding.tables.t_order.actual-data-nodes=rw_$->{0..1}.t_order_$->{0..1}
spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-column=order_id
spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-algorithm-name=order_inline
spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.column=order_id
spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.key-generator-name=snow_flake
#algorithm
spring.shardingsphere.rules.sharding.sharding-algorithms.db_inline.type=INLINE
spring.shardingsphere.rules.sharding.sharding-algorithms.db_inline.props.algorithm-expression=rw_$->{user_id % 2}
spring.shardingsphere.rules.sharding.sharding-algorithms.order_inline.type=INLINE
spring.shardingsphere.rules.sharding.sharding-algorithms.order_inline.props.algorithm-expression=t_order_$->{order_id % 2}
#keyGenerators
spring.shardingsphere.rules.sharding.key-generators.snow_flake.type=SNOWFLAKE
spring.shardingsphere.rules.sharding.key-generators.snow_flake.props.worker-id=1

帮顶,这个问题有点意思

京ICP备2021015875号