ShardingSphere proxy 使用MySQL 多个MGR集群分库分表读写分离报错

ShardingSphere proxy 使用MySQL 多个MGR集群分库分表读写分离报错

使用环境:使用最新的apache/shardingsphere-proxy 镜像docker

场景、问题:使用多个MGR集群,作为分库分表,读写分离的资源,配置文件见附件

shardingsphere-proxy 容器 启动报错
[INFO ] 2022-10-13 05:36:04.709 [main] org.quartz.impl.StdSchedulerFactory - Quartz scheduler ‘MySQL.MGR-sharding_db_rw-mgr-replication-ds-1’ initialized from an externally provided properties instance.
[INFO ] 2022-10-13 05:36:04.709 [main] org.quartz.impl.StdSchedulerFactory - Quartz scheduler version: 2.3.2
[INFO ] 2022-10-13 05:36:04.762 [main] org.quartz.core.QuartzScheduler - Scheduler MySQL.MGR-sharding_db_rw-mgr-replication-ds-1_$_NON_CLUSTERED started.
Thanks for using Atomikos! This installation is not registered yet.
REGISTER FOR FREE at http://www.atomikos.com/Main/RegisterYourDownload and receive:

  • tips & advice
  • working demos
  • access to the full documentation
  • special exclusive bonus offers not available to others
  • everything you need to get the most out of using Atomikos!
    Exception in thread “main” java.lang.IllegalStateException: Can 't find readwrite-splitting data source rule in database sharding_db_rw.
    at com.google.common.base.Preconditions.checkState(Preconditions.java:589)
    at org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule.updateStatus(ReadwriteSplittingRule.java:172)
    at org.apache.shardingsphere.mode.manager.cluster.coordinator.ClusterContextManagerCoordinator.lambda$disableDataSources$8(ClusterContextManagerCoordinator.java:357)
    at java.base/java.util.HashMap.forEach(HashMap.java:1421)
    at org.apache.shardingsphere.mode.manager.cluster.coordinator.ClusterContextManagerCoordinator.disableDataSources(ClusterContextManagerCoordinator.java:357)
    at org.apache.shardingsphere.mode.manager.cluster.coordinator.ClusterContextManagerCoordinator.lambda$null$5(ClusterContextManagerCoordinator.java:348)
    at java.base/java.util.concurrent.CopyOnWriteArrayList.forEach(CopyOnWriteArrayList.java:807)
    at org.apache.shardingsphere.mode.manager.cluster.coordinator.ClusterContextManagerCoordinator.lambda$disableDataSources$6(ClusterContextManagerCoordinator.java:346)
    at java.base/java.util.concurrent.ConcurrentHashMap.forEach(ConcurrentHashMap.java:1603)
    at org.apache.shardingsphere.mode.manager.cluster.coordinator.ClusterContextManagerCoordinator.disableDataSources(ClusterContextManagerCoordinator.java:346)
    at org.apache.shardingsphere.mode.manager.cluster.coordinator.ClusterContextManagerCoordinator.(ClusterContextManagerCoordinator.java:86)
    at org.apache.shardingsphere.mode.manager.cluster.ClusterContextManagerBuilder.registerOnline(ClusterContextManagerBuilder.java:81)
    at org.apache.shardingsphere.mode.manager.cluster.ClusterContextManagerBuilder.build(ClusterContextManagerBuilder.java:57)
    at org.apache.shardingsphere.proxy.initializer.BootstrapInitializer.createContextManager(BootstrapInitializer.java:67)
    at org.apache.shardingsphere.proxy.initializer.BootstrapInitializer.init(BootstrapInitializer.java:57)
    at org.apache.shardingsphere.proxy.Bootstrap.main(Bootstrap.java:52)

配置文件如下

databaseName: sharding_db_rw
dataSources:
datasource-0-0:
url: jdbc:mysql://192.168.0.1:3307/datasource_0?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
username: root
password: root
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
datasource-0-1:
url: jdbc:mysql://192.168.0.1:3308/datasource_0?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
username: root
password: root
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
datasource-0-2:
url: jdbc:mysql://192.168.0.1:3309/datasource_0?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
username: root
password: root
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
datasource-1-0:
url: jdbc:mysql://192.168.0.1:3317/datasource_0?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
username: root
password: root
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
datasource-1-1:
url: jdbc:mysql://192.168.0.1:3318/datasource_0?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
username: root
password: root
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
datasource-1-2:
url: jdbc:mysql://192.168.0.1:3319/datasource_0?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
username: root
password: root
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
datasource-2-0:
url: jdbc:mysql://192.168.0.1:3327/datasource_0?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
username: root
password: root
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
datasource-2-1:
url: jdbc:mysql://192.168.0.1:3328/datasource_0?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
username: root
password: root
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
datasource-2-2:
url: jdbc:mysql://192.168.0.1:3329/datasource_0?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
username: root
password: root
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1

rules:

  • !SHARDING
    bindingTables:

    • t_order,t_order_item
      broadcastTables:
    • t_address
      tables:
      t_order:
      actualDataNodes: rw-ds-$->{0…2}.t_order_$->{0…2}
      databaseStrategy:
      standard:
      shardingColumn: order_id
      shardingAlgorithmName: t-order-database-inline
      tableStrategy:
      standard:
      shardingColumn: order_id
      shardingAlgorithmName: t-order-table-inline
      t_order_item:
      actualDataNodes: rw-ds-$->{0…2}.t_order_item_$->{0…2}
      databaseStrategy:
      standard:
      shardingColumn: order_id
      shardingAlgorithmName: t-order-item-database-inline
      tableStrategy:
      standard:
      shardingColumn: order_id
      shardingAlgorithmName: t-order-item-table-inline
      shardingAlgorithms:
      t-order-database-inline:
      type: INLINE
      props:
      algorithm-expression: rw-ds-$->{order_id % 3}
      t-order-table-inline:
      type: INLINE
      props:
      algorithm-expression: t_order_$->{(order_id/3)% 3}
      t-order-item-database-inline:
      type: INLINE
      props:
      algorithm-expression: rw-ds-$->{order_id % 3}
      t-order-item-table-inline:
      type: INLINE
      props:
      algorithm-expression: t_order_item_$->{(order_id/3) % 3}
  • !DB_DISCOVERY
    dataSources:
    mgr_replication_ds_0:
    dataSourceNames:
    - datasource-0-0
    - datasource-0-1
    - datasource-0-2
    discoveryHeartbeatName: mgr-heartbeat
    discoveryTypeName: mgr0
    mgr_replication_ds_1:
    dataSourceNames:
    - datasource-1-0
    - datasource-1-1
    - datasource-2-2
    discoveryHeartbeatName: mgr-heartbeat
    discoveryTypeName: mgr1
    mgr_replication_ds_2:
    dataSourceNames:
    - datasource-2-0
    - datasource-2-1
    - datasource-2-2
    discoveryHeartbeatName: mgr-heartbeat
    discoveryTypeName: mgr2
    discoveryHeartbeats:
    mgr-heartbeat:
    props:
    keep-alive-cron: ‘0/5 * * * * ?’
    discoveryTypes:
    mgr0:
    type: MySQL.MGR
    props:
    group-name: 1c9a3ee9-01c8-e687-39a6-58165ad822da
    mgr1:
    type: MySQL.MGR
    props:
    group-name: 1c9a3ee9-01c8-e687-39a6-58165ad822da
    mgr2:
    type: MySQL.MGR
    props:
    group-name: 1c9a3ee9-01c8-e687-39a6-58165ad822da

  • !READWRITE_SPLITTING
    dataSources:
    rw-ds-0:
    dynamicStrategy:
    autoAwareDataSourceName: mgr_replication_ds_0
    # 读库全部下线,主库是否承担读流量
    writeDataSourceQueryEnabled: true
    loadBalancerName: round-robin
    rw-ds-1:
    dynamicStrategy:
    autoAwareDataSourceName: mgr_replication_ds_1
    # 读库全部下线,主库是否承担读流量
    writeDataSourceQueryEnabled: true
    loadBalancerName: round-robin
    rw-ds-2:
    dynamicStrategy:
    autoAwareDataSourceName: mgr_replication_ds_2
    # 读库全部下线,主库是否承担读流量
    writeDataSourceQueryEnabled: true
    loadBalancerName: round-robin
    loadBalancers:
    round-robin:
    type: ROUND_ROBIN

你好,我尝试了多次,仍无法重现这个问题,现在有另一位社区同学在跟踪,有进展后在这里更新。

京ICP备2021015875号