apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.8k stars 6.7k forks source link

READ-WRITE SPLIT not work with SHARDING in SHARDINGJDBC #2681

Closed 276234199 closed 5 years ago

276234199 commented 5 years ago
server:
  port: 12601

spring:
    main:
      allow-bean-definition-overriding: true      
    shardingsphere:
      props:
        sql:
          show: true
      sharding:
        tables:
          test_sharding:
            actual-data-nodes: ds$->{0..1}.test_sharding
            table-strategy:
              inline:
                sharding-column: id
                algorithm-expression: test_sharding
        default-database-strategy: 
          inline: 
            sharding-column: id
            algorithm-expression: master$->{id % 2} 
        master-slave-rules: 
          ds1:
            master-data-source-name: master1
            slave-data-source-names: slave1
            load-balance-algorithm-type: round_robin
          ds0:
            master-data-source-name: master0
            slave-data-source-names: slave0
            load-balance-algorithm-type: round_robin
      datasource:
        names: master1,slave1,master0,slave0
        master1: 
          name: master1
          url: jdbc:mysql://localhost:30001/TestReadWrite?useSSL=false&serverTimezone=GMT%2B8
          username: root
          password: 123456
          #
          type: com.alibaba.druid.pool.DruidDataSource
          driver-class-name: com.mysql.jdbc.Driver
        master0: 
          name: master0
          url: jdbc:mysql://localhost:30003/TestReadWrite?useSSL=false&serverTimezone=GMT%2B8
          username: root
          password: 123456
          #
          type: com.alibaba.druid.pool.DruidDataSource
          driver-class-name: com.mysql.jdbc.Driver          
        slave1:
          name: slave1
          url: jdbc:mysql://localhost:30002/TestReadWrite?useSSL=false&serverTimezone=GMT%2B8
          username: root
          password: 123456
          #
          type: com.alibaba.druid.pool.DruidDataSource
          driver-class-name: com.mysql.jdbc.Driver     
        slave0:
          name: slave0
          url: jdbc:mysql://localhost:30004/TestReadWrite?useSSL=false&serverTimezone=GMT%2B8
          username: root
          password: 123456
          #
          type: com.alibaba.druid.pool.DruidDataSource
          driver-class-name: com.mysql.jdbc.Driver        

---------------------------------------------------------------------------------------------------
springboot+mybatisplus
application.yml is shown above  

sharding is available but 
READ-WRITE SPLIT NOT WORKING
always read master,never read slave 

version : 4.0.0-RC1
terrymanu commented 5 years ago

Please ref example first, all demos can run correctly. https://github.com/apache/incubator-shardingsphere-example/

terrymanu commented 5 years ago

Submit issue for common feature, please make sure examples are incorrect first.