apache / shardingsphere

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

A bug in setting actual-data-nodes with shardingsphere-jdbc-core-spring-boot-starter at version 5.1.2 #19427

Closed win-ho closed 2 years ago

win-ho commented 2 years ago

image As it shows, I have configured the logic table student with 3 physic tables: student_0, student_1 and student_2. But it does not work when inserting data into student_2. And it reminds me that student_2 does not exist.

win-ho commented 2 years ago

it works normally with the same configurations at version 5.1.1

0xkevin commented 2 years ago

it works normally with the same configurations at version 5.1.1

me too

strongduanmu commented 2 years ago

Can you provide a demo to reproduce this bug?

win-ho commented 2 years ago

Can you provide a demo to reproduce this bug?

Sure. Is it zip package ok ?

strongduanmu commented 2 years ago

@win-ho Ok, you can push demo to your github repository, and paste link here.

0xkevin commented 2 years ago

application.yml:

spring:
  shardingsphere:
    props:
      sql-show: true  
    datasource:
      names: ds1,ds2
      ds1:
        driver-class-name: com.mysql.jdbc.Driver
        type: com.zaxxer.hikari.HikariDataSource
        jdbc-url: jdbc:mysql://x.x.x.x:3306/course_db?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8
        username: xxx
        password: xxx
      ds2:
        driver-class-name: com.mysql.jdbc.Driver
        type: com.zaxxer.hikari.HikariDataSource
        jdbc-url: jdbc:mysql://xx.xx.xx.xx:3306/course_db?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8
        username: xxx
        password: xxx
    mode:
      overwrite: false
      type: Cluster
      repository:
        type: ZooKeeper
        props:
          namespace: shardingsphere-rw
          retryIntervalMilliseconds: 500
          server-lists: zoo1:2181,zoo2:2182,zoo3:2183
          timeToLiveSeconds: 60
    rules:
      readwrite-splitting:
        data-sources:
          ds:
            type: Static
            load-balancer-name: my_lb
            props:
              write-data-source-name: ds1
              read-data-source-names: ds2
        load-balancers:
          my_lb:
            type: ROUND_ROBIN  
      sharding:
        key-generators:
          snowflake:
            type: SNOWFLAKE
        sharding-algorithms:
          hl-course-inline:
            type: INLINE
            props:
              algorithm-expression: hl_course_$->{cid % 2 + 1}
        tables:
          hl_course:
            actual-data-nodes: ds.hl_course_$->{1..2}
            key-generate-strategy:
              column: cid
              key-generator-name: snowflake
            table-strategy:
              standard:
                sharding-algorithm-name: hl-course-inline
                sharding-column: cid

#----------------------log--------------------------- 
logging:
  level:
    org.apache.shardingsphere: debug

#----------------------mybatisplus--------------------------- 
mybatis-plus:
  print-sql: true
  configuration:
    cache-enabled: false
    map-underscore-to-camel-case: true
    use-generated-keys: true 
    default-statement-timeout: 600
  global-config:
    banner: false
    db-config:
      table-prefix: hl_

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.atguigu</groupId>
    <artifactId>shardingjdbcdemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>shardingjdbcdemo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
            <version>5.1.2</version>
        </dependency>

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Error Message:

image
win-ho commented 2 years ago

I find that,maybe it's not a bug! but still, it got some confusing problems.

win-ho commented 2 years ago

I just found a directory which named .shardingsphere in my project directory. it worked normally after I delete this directory!

win-ho commented 2 years ago

image I truely config the physical table table_0 and table_1 (test-db.student$->{0..1}) in first time! but I did not notice that a directory was generated in my project. And then I config phsical tables (`test-db.student$->{0..2}`), and rerun my project, error which I just issued just occured.

0xkevin commented 2 years ago

Thanks for your reminder, it's work for me when I deleted shardingsphere-rw directory from zookeeper.

strongduanmu commented 2 years ago

I just found a directory which named .shardingsphere in my project directory. it worked normally after I delete this directory!

This is a cluster mode, it will store config file to .shardingsphere directory.

0xkevin commented 2 years ago
image
strongduanmu commented 2 years ago

@win-ho So, can you close this issue now?

win-ho commented 2 years ago

@win-ho So, can you close this issue now?

OK

win-ho commented 2 years ago

I just found a directory which named .shardingsphere in my project directory. it worked normally after I delete this directory!

This is a cluster mode, it will store config file to .shardingsphere directory.

But still, I want to know that why it worked abnormally in 5.1.2, but not in 5.1.1 without deleting .shardingsphere ?

strongduanmu commented 2 years ago

I truely config the physical table table_0 and table1 (test-db.student$->{0..1}) in first time! but I did not notice that a directory was generated in my project. And then I config phsical tables (test-db.student_$->{0..2}), and rerun my project, error which I just issued just occured.

Maybe you can set overwrite: true.

win-ho commented 2 years ago

I truely config the physical table table_0 and table_1 (test-db.student_Missing superscript or subscript argument

    $-&gt;{0..1}) in first time! but I did not notice that a directory was generated in my project. And then I config phsical tables (test-db.student_$->{0..2}), and rerun my project, error which I just issued just occured.

Maybe you can set overwrite: true.

Thanks for your advice