Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShardingConditions to avoid same record in table 't_order' routing to multiple data nodes. #33688

Open
clay-f opened this issue Nov 16, 2024 · 0 comments

Comments

@clay-f
Copy link

clay-f commented Nov 16, 2024

Bug Report

Which version of ShardingSphere did you use?

5.5.1

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

ShardingSphere-JDBC

Expected behavior

I'm follow official website doc,copy example config and get error

Actual behavior

this is final error

error

Reason analyze (If you can)

I'm change

actualDataNodes: ds_${0..1}.t_order_${0..1}

to

actualDataNodes: ds_0.t_order_${0..1}

insert value succeed

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

database schema
sql_schema

below is config file, will get to avoid same record in table 't_order' routing to multiple data nodes

mode:
  type: Standalone
  repository:
    type: JDBC

dataSources:
  ds_0:
    dataSourceClassName: com.zaxxer.hikari.HikariDataSource
    driverClassName: com.mysql.cj.jdbc.Driver
    jdbcUrl: jdbc:mysql://localhost:3306/sharding_db0?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
    username: root
    password:
  ds_1:
    dataSourceClassName: com.zaxxer.hikari.HikariDataSource
    driverClassName: com.mysql.cj.jdbc.Driver
    jdbcUrl: jdbc:mysql://localhost:3306/sharding_db1?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
    username: root
    password:

rules:
  - !SHARDING
    tables:
      t_order:
        actualDataNodes: ds_${0..1}.t_order_${0..1}
        tableStrategy:
          standard:
            shardingColumn: order_id
            shardingAlgorithmName: t_order_inline
        keyGenerateStrategy:
          column: order_id
          keyGeneratorName: snowflake
        auditStrategy:
          auditorNames:
            - sharding_key_required_auditor
          allowHintDisable: true
    bindingTables:
      - t_order
    shardingAlgorithms:
      t_order_inline:
        type: INLINE
        props:
          algorithm-expression: t_order_${order_id % 2}
    keyGenerators:
      snowflake:
        type: SNOWFLAKE
    auditors:
      sharding_key_required_auditor:
        type: DML_SHARDING_CONDITIONS

props:
  sql-show: true

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

test insert order code

error_code

entity order object
image

pom file and spring boot version is 3.3.1

image

project structure
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant