apache / shardingsphere

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

Create sharding table rules with same data nodes will cause exception #33050

Closed RaigorJiang closed 1 month ago

RaigorJiang commented 1 month ago

Bug Report

Which version of ShardingSphere did you use?

5.5.1-SNAPSHOT master ec7ce3b9574626ab4a1b716b09aba0a3eaa74207

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

ShardingSphere-Proxy

Expected behavior

Feedback exception when executing DistSQL instead of success

Actual behavior

DistSQL was executed successfully, but an exception occurred when refreshing metadata

Reason analyze (If you can)

29724 added validation in rule, but DistSQL has no corresponding logic

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

  1. create sharding table rule
    
    CREATE SHARDING TABLE RULE tc (
    DATANODES("ds_${0..1}.tc"),
    DATABASE_STRATEGY(TYPE='standard',SHARDING_COLUMN=id,SHARDING_ALGORITHM(TYPE(NAME='inline',PROPERTIES('algorithm-expression'='ds_${id % 2}'))))
    );

CREATE SHARDING TABLE RULE td ( DATANODES("ds_${0..1}.tc"), DATABASE_STRATEGY(TYPE='standard',SHARDING_COLUMN=id,SHARDINGALGORITHM(TYPE(NAME='inline',PROPERTIES('algorithm-expression'='ds${id % 2}')))) );

2. log of proxy
```plain
Exception in thread "main" org.apache.shardingsphere.sharding.exception.metadata.DuplicateSharingActualDataNodeException: Same actual data node cannot be configured in multiple logic tables in same database, logical table 'tc', actual data node 'ds_0.tc'.
    at org.apache.shardingsphere.sharding.rule.checker.ShardingRuleChecker.lambda$checkUniqueActualDataNodesInTableRules$0(ShardingRuleChecker.java:71)
    at org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions.checkNotContains(ShardingSpherePreconditions.java:158)
    at org.apache.shardingsphere.sharding.rule.checker.ShardingRuleChecker.lambda$checkUniqueActualDataNodesInTableRules$1(ShardingRuleChecker.java:70)
    at java.base/java.util.Map.forEach(Map.java:713)
    at org.apache.shardingsphere.sharding.rule.checker.ShardingRuleChecker.checkUniqueActualDataNodesInTableRules(ShardingRuleChecker.java:68)
    at org.apache.shardingsphere.sharding.rule.checker.ShardingRuleChecker.check(ShardingRuleChecker.java:61)
    at org.apache.shardingsphere.sharding.rule.ShardingRule.<init>(ShardingRule.java:142)
    at org.apache.shardingsphere.sharding.rule.builder.ShardingRuleBuilder.build(ShardingRuleBuilder.java:42)
    at org.apache.shardingsphere.sharding.rule.builder.ShardingRuleBuilder.build(ShardingRuleBuilder.java:36)
    at org.apache.shardingsphere.infra.rule.builder.database.DatabaseRulesBuilder.build(DatabaseRulesBuilder.java:69)
    at org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase.create(ShardingSphereDatabase.java:127)