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

ShardingRuleChecker fail issue #33838

Open
GuryYu opened this issue Nov 29, 2024 · 0 comments
Open

ShardingRuleChecker fail issue #33838

GuryYu opened this issue Nov 29, 2024 · 0 comments

Comments

@GuryYu
Copy link

GuryYu commented Nov 29, 2024

Bug Report

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.5.1

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

ShardingSphere-JDBC

Expected behavior

expected pass the validation and run normally.

Actual behavior

Error Info:

Algorithm 'Object.'INLINE' initialization failed, reason is: `sensitivityShardingAlgorithm` sharding algorithm configuration of `logic_base_visual_release` does not match the actual data nodes.

Reason analyze (If you can)

In org.apache.shardingsphere.sharding.rule.ShardingTable class createDataSourceDataNode method.

private static final Pattern DATA_NODE_SUFFIX_PATTERN = Pattern.compile("\\d+$");
...
String prefix = DATA_NODE_SUFFIX_PATTERN.matcher(actualDataNodes.iterator().next().getDataSourceName()).replaceAll("");

prefix val is ds_normal

But in org.apache.shardingsphere.sharding.rule.checker.ShardingRuleChecker class validateInlineShardingAlgorithm method.
check expression is null == result || result.startsWith(dataNodeInfo.getPrefix())
result val is ds_sensitive, not match prefix result, then throw exception.

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

The following configuration defines two data sources, named ds_normal and ds_sensitive. The sharding rules are defined using an enumerated value in a Groovy line expression. It works fine in version 5.3.2, but an error occurs when running in version 5.5.1.

dataSources: 
  ds_normal: 
    ...
  ds_sensitive: 
    ...
rules: 
  - !SHARDING 
    tables:
      logic_base_visual_release: 
        actualDataNodes: "ds_$->{['normal', 'sensitive']}.base_visual_release"
      logic_base_visual_dev:
        actualDataNodes: "ds_$->{['normal', 'sensitive']}.base_visual_dev"
        defaultDatabaseStrategy:
      standard:
        shardingColumn: f_special_mark
        shardingAlgorithmName: sensitivityShardingAlgorithm
    shardingAlgorithms:
      sensitivityShardingAlgorithm:
        type: INLINE
        props:
          algorithm-expression: "ds_$->{f_special_mark == 0 ? 'normal' : 'sensitive'}"

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

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

No branches or pull requests

2 participants