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

Fix shadow moudle throw 'Table does not exist' exception #31378

Closed
wants to merge 2 commits into from

Conversation

TherChenYang
Copy link
Collaborator

Fixes #31360.

Changes proposed in this pull request:

  • When we have configured the relevant table property configuration for shadow in config.yaml, but our table has been
    created ahead of time and not through ShardingSphereConection, an error is thrownTableNotFoundException: Table or view ‘t_order’ does not exist.
  • we should refer to the tables that are preloaded in the configuration class in shadingRule, which can avoid this problem

For Example

  • Configuration file
mode:
  type: Standalone
  repository:
    type: JDBC
    props:
      path: demo

dataSources:
  ds_0:
    dataSourceClassName: com.zaxxer.hikari.HikariDataSource
    driverClassName: com.mysql.jdbc.Driver
    jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true
    username: root
    password: mcycxc19740203
    maxPoolSize: 10
  ds_1:
    dataSourceClassName: com.zaxxer.hikari.HikariDataSource
    driverClassName: com.mysql.jdbc.Driver
    jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true
    username: root
    password: mcycxc19740203
    maxPoolSize: 10

rules:
- !SHADOW
  tables:
    t_order:
      dataSourceNames:
        - shadow_group
      shadowAlgorithmNames:
        - user_id_insert_match_algorithm
        - user_id_delete_match_algorithm
        - user_id_select_match_algorithm
  dataSources:
    shadow_group:
      productionDataSourceName: ds_0
      shadowDataSourceName: ds_1
  shadowAlgorithms:
    user_id_insert_match_algorithm:
      type: REGEX_MATCH
      props:
        operation: insert
        column: order_type
        regex: "[1]"
    user_id_delete_match_algorithm:
      type: REGEX_MATCH
      props:
        operation: delete
        column: order_type
        regex: "[1]"
    user_id_select_match_algorithm:
      type: REGEX_MATCH
      props:
        operation: select
        column: order_type
        regex: "[1]"
props:
  sql-show: true
  • Code
image
  • Exception
image

-- After modification
image


Before committing this PR, I'm sure that I have checked the following options:

  • My code follows the code of conduct of this project.
  • I have self-reviewed the commit code.
  • I have (or in comment I request) added corresponding labels for the pull request.
  • I have passed maven check locally : ./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e.
  • I have made corresponding changes to the documentation.
  • I have added corresponding unit tests for my changes.

Copy link
Member

@terrymanu terrymanu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix CI


private final CaseInsensitiveSet<String> logicalTableMapper;

public ShadowTableMapperRuleAttribute(final Collection<String> encryptTableNames) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encryptTableNames should not here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your review. It was my carelessness that caused this issue. I have adjusted the variable names and want to express my gratitude again.

@RaigorJiang RaigorJiang added this to the 5.5.1 milestone May 26, 2024
@zhaojinchao95
Copy link
Contributor

@TherChenYang Hi, #31360 configuration has problem, so can you close this pr?

@TherChenYang
Copy link
Collaborator Author

@zhaojinchao95 Okay, I will close this PR. Do we need to make corresponding adjustments to our example module and official documentation for users to access it more quickly?

@zhaojinchao95
Copy link
Contributor

@zhaojinchao95 Okay, I will close this PR. Do we need to make corresponding adjustments to our example module and official documentation for users to access it more quickly?

@zhaojinchao95 Okay, I will close this PR. Do we need to make corresponding adjustments to our example module and official documentation for users to access it more quickly?

@zhaojinchao95 Okay, I will close this PR. Do we need to make corresponding adjustments to our example module and official documentation for users to access it more quickly?

Yes, would you like to adjustment example?

@TherChenYang
Copy link
Collaborator Author

@zhaojinchao95 Okay, thank you very much. I will adjust the corresponding documents and examples

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

Successfully merging this pull request may close these issues.

Shadow sample throws exception 'Table does not exist'
4 participants