读写分离和discovery如何结合

读写分离和discovery结合是咋用的,这些配置结合起来不知道会起什么效果

rules:
  - !READWRITE_SPLITTING
    dataSources:
      ms_ds:
        writeDataSourceName: hostM1
        readDataSourceNames:
          - hostM2
          - hostS1
  - !DB_DISCOVERY
    dataSources:
      pr_ds:
        dataSourceNames:
          - hostM1
          - hostM2
          - hostS1
        discoveryTypeName: mgr
    discoveryTypes:
      mgr:
        type: MGR
        props:
          groupName: 92504d5b-6dec-11e8-91ea-246e9612aaf1
          zkServerLists: 'node1:2181'
          keepAliveCron: '0/5 * * * * ?'

你好, 可以试试下面的配置 :

schemaName: database_discovery_db

dataSources:
  ds_0:
    url: jdbc:mysql://127.0.0.1:3306/demo_primary_ds?serverTimezone=UTC&useSSL=false
    username: root
    password: 123456
    connectionTimeoutMilliseconds: 3000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
  ds_1:
    url: jdbc:mysql://127.0.0.1:3307/demo_primary_ds?serverTimezone=UTC&useSSL=false
    username: root
    password: 123456
    connectionTimeoutMilliseconds: 3000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
  ds_2:
    url: jdbc:mysql://127.0.0.1:3308/demo_primary_ds?serverTimezone=UTC&useSSL=false
    username: root
    password: 123456
    connectionTimeoutMilliseconds: 3000
    idleTimeoutMilliseconds: 50000
    maxLifetimeMilliseconds: 1300000
    maxPoolSize: 50
    minPoolSize: 1

rules:
  - !READWRITE_SPLITTING
    dataSources:
      replication_ds:
        type: Dynamic
        props:
          auto-aware-data-source-name: mgr_replication_ds
  - !DB_DISCOVERY
    dataSources:
      mgr_replication_ds:
        dataSourceNames:
          - ds_0
          - ds_1
          - ds_2
        discoveryHeartbeatName: mgr-heartbeat
        discoveryTypeName: mgr
    discoveryHeartbeats:
      mgr-heartbeat:
        props:
          keep-alive-cron: '0/5 * * * * ?'
    discoveryTypes:
      mgr:
        type: MGR
        props:
          group-name: b13df29e-90b6-11e8-8d1b-525400fc3996

好的,请问下这种情况的话是如何判断哪个数据源作为主库,哪个数据源作为从库用来读呢?
还有 group-name: b13df29e-90b6-11e8-8d1b-525400fc3996 这个属性有具体用途么?

第一个问题: 如何判断哪个数据源作为主库,哪个数据源作为从库用来读呢?

回答: 这个不需要业务关心, ShardingSphere 会自动发现主从关系, 读操作会自动路由到备库

第二个问题: group-name: b13df29e-90b6-11e8-8d1b-525400fc3996

回答: 这个是 MySQL MGR 组的 ID, 可以通过 SELECT * FROM performance_schema.global_variables WHERE VARIABLE_NAME='group_replication_group_name' 查询出 group-name.

用途是来检验你所配置的 ds 所对应的 MGR group 与你配置的 group-name 是否为同一组.

1 个赞

好的了解,非常感谢

京ICP备2021015875号