apache / shardingsphere

Empowering Data Intelligence with Distributed SQL for Sharding, Scalability, and Security Across All Databases.
Apache License 2.0
19.96k stars 6.74k forks source link

Master-slave problem #20845

Closed strongyc closed 2 years ago

strongyc commented 2 years ago

Bug Report

Using version 5.1.2, after configuring read-write separation and data fragmentation, the fragmented table cannot be read from the slave library, and other tables can read from the slave library normally. Why For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details. If no response anymore and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use?

5.1.2

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-JDBC

spring: shardingsphere: mode: type: Memory datasource: names: db1,db2 db1: driver-class-name: com.mysql.cj.jdbc.Driver jdbc-url: jdbc:mysql://192.168.37.130:3306/student?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai username: root password: type: com.zaxxer.hikari.HikariDataSource db2: driver-class-name: com.mysql.cj.jdbc.Driver jdbc-url: jdbc:mysql://192.168.37.132:3306/student?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai username: root password: type: com.zaxxer.hikari.HikariDataSource rules: sharding: tables: document: actual-data-nodes: db1.document_$->{2013..2022} table-strategy: standard: sharding-algorithm-name: document-inline # 分片算法名称 sharding-column: documentyear key-generate-strategy: column: id key-generator-name: timestamp #主键生成算法#主键生成算法 sharding-algorithms: document-inline: type: INLINE props: algorithm-expression: document$->{document_year} key-generators: timestamp: type: SNOWFLAKE

  readwrite-splitting:
    data-sources:
      read_write_db:
        type: Static
        props:
          write-data-source-name: db1
          read-data-source-names: db2
        load-balancer-name: round_robin
    load-balancers:
      round_robin:
        type: ROUND_ROBIN

props:
  sql-show: true

Expected behavior

Actual behavior

select use db2

Reason analyze (If you can)

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

Example codes for reproduce this issue (such as a github link).

strongyc commented 2 years ago

results: 2022-09-07 13:52:50.801 INFO 25968 --- [nio-8080-exec-1] ShardingSphere-SQL : Actual SQL: db1 ::: SELECT id,document_name,document_detail,document_year FROM document_2013 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2014 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2015 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2016 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2017 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2018 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2019 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2020 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2021 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2022

strongyc commented 2 years ago

According to the configuration, db1 is the master library and db2 is the slave Library,why is db1

strongduanmu commented 2 years ago

Hi @strongyc, thank you for your feedback. Can you modify the title for searching friendly? Besides, can you format your issue with markdown?

strongyc commented 2 years ago

Hi @strongyc, thank you for your feedback. Can you modify the title for searching friendly? Besides, can you format your issue with markdown?

1.problem

Using version 5.1.2, after configuring read-write separation and data fragmentation, the fragmented table cannot be read from the slave library, and other tables can read from the slave library normally. Why

2. Which version of ShardingSphere did you use?

5.1.2

3. Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-JDBC

4.settings

springboot2.7.3+MybaitsPlus3.5.2+shardingShere5.1.2

spring:
  shardingsphere:
    mode:
      type: Memory
    datasource:
      names: db1,db2
      db1:
        driver-class-name: com.mysql.cj.jdbc.Driver
        jdbc-url: jdbc:mysql://192.168.37.130:3306/student?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
        username: root
        password: 
        type: com.zaxxer.hikari.HikariDataSource
      db2:
        driver-class-name: com.mysql.cj.jdbc.Driver
        jdbc-url: jdbc:mysql://192.168.37.132:3306/student?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
        username: root
        password: 
        type: com.zaxxer.hikari.HikariDataSource
    rules:
      sharding:
        tables:
          document:
            actual-data-nodes: db1.document_$->{2013..2022}
            table-strategy:
              standard:
                sharding-algorithm-name: document-inline # 分片算法名称
                sharding-column: document_year
            key-generate-strategy:
              column: id
              key-generator-name: timestamp #主键生成算法#主键生成算法
        sharding-algorithms:
          document-inline:
            type: INLINE
            props:
              algorithm-expression: document_$->{document_year}
        key-generators:
          timestamp:
            type: SNOWFLAKE

      readwrite-splitting:
        data-sources:
          read_write_db:
            type: Static
            props:
              write-data-source-name: db1
              read-data-source-names: db2
            load-balancer-name: round_robin
        load-balancers:
          round_robin:
            type: ROUND_ROBIN

    props:
      sql-show: true

5.results of enforcement

2022-09-07 13:52:50.801 INFO 25968 --- [nio-8080-exec-1] ShardingSphere-SQL : Actual SQL: db1 ::: SELECT id,document_name,document_detail,document_year FROM document_2013 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2014 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2015 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2016 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2017 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2018 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2019 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2020 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2021 UNION ALL SELECT id,document_name,document_detail,document_year FROM document_2022

6.why?

According to the configuration, db1 is the master library and db2 is the slave Library,why is db1

strongyc commented 2 years ago

image The library without fragment key is correct

strongyc commented 2 years ago

Hi @strongyc, thank you for your feedback. Can you modify the title for searching friendly? Besides, can you format your issue with markdown?

thinks,resolved