apache / shardingsphere

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

DistSQL lacks inline actual data nodes validation #33723

Closed RaigorJiang closed 1 day ago

RaigorJiang commented 2 days ago

Bug Report

Which version of ShardingSphere did you use?

5.5.2-SNAPSHOT master 89f21d4f4a08da6f7f35f699585e7392aab6b250

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

ShardingSphere-Proxy

Expected behavior

DistSQL execution fails when inline expressions do not match actual nodes

Actual behavior

DistSQL execution succeeded, metadata update failed

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

  1. Create sharding table rule with wrong nodes in inline expression

    CREATE SHARDING TABLE RULE t_order (
    DATANODES("ds_${0..3}.t_order_${0..2}"),
    DATABASE_STRATEGY(
    TYPE="standard",
    SHARDING_COLUMN=user_id,
    SHARDING_ALGORITHM(
    TYPE(NAME="inline",PROPERTIES("algorithm-expression"="dss_${user_id % 4}")))),
    TABLE_STRATEGY(
    TYPE="standard",
    SHARDING_COLUMN=order_id,
    SHARDING_ALGORITHM(
    TYPE(NAME="inline",PROPERTIES("algorithm-expression"="t_order_${order_id % 3}"))))
    );
  2. Refresh metadata failed

    [Curator-SafeNotifyService-0] c.g.common.eventbus.EventBus.default - Exception thrown by subscriber method renew(org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent) on subscriber org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.RuleItemChangedSubscriber@27854b33 when dispatching event: org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent@5c60de44
    org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException: Algorithm 'Object.'INLINE' initialization failed, reason is: `t_order_database_inline` sharding algorithm configuration of `t_order` does not match the actual data nodes.
    at org.apache.shardingsphere.sharding.rule.checker.ShardingRuleChecker.lambda$validateInlineShardingAlgorithm$6(ShardingRuleChecker.java:178)
    at org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions.checkState(ShardingSpherePreconditions.java:44)
    at org.apache.shardingsphere.sharding.rule.checker.ShardingRuleChecker.validateInlineShardingAlgorithm(ShardingRuleChecker.java:176)
    at org.apache.shardingsphere.sharding.rule.checker.ShardingRuleChecker.lambda$checkInlineShardingAlgorithmsInTableRules$5(ShardingRuleChecker.java:157)
    at java.base/java.util.Map.forEach(Map.java:713)
    at org.apache.shardingsphere.sharding.rule.checker.ShardingRuleChecker.checkInlineShardingAlgorithmsInTableRules(ShardingRuleChecker.java:155)
    at org.apache.shardingsphere.sharding.rule.checker.ShardingRuleChecker.check(ShardingRuleChecker.java:62)
    at org.apache.shardingsphere.sharding.rule.ShardingRule.<init>(ShardingRule.java:141)
    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:96)
    at org.apache.shardingsphere.mode.metadata.manager.DatabaseRuleConfigurationManager.alterRuleConfiguration(DatabaseRuleConfigurationManager.java:78)
    at org.apache.shardingsphere.mode.metadata.manager.RuleItemManager.alterRuleItem(RuleItemManager.java:67)
    at org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.RuleItemChangedSubscriber.renew(RuleItemChangedSubscriber.java:46)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:569)
RaigorJiang commented 2 days ago

Similar to #33050