apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.83k stars 6.71k forks source link

ShardingProxy 5.5.0 version: SQL cannot to be routed to the shadow database data source for execution. #33045

Closed liuli12345 closed 5 hours ago

liuli12345 commented 1 day ago

Version 5.2.1 is good, but after upgrading to version 5.5.0, SQL cannot to be routed to the shadow database data source for execution.

database-shadow.YAML

databaseName: shadow_db
dataSources:
 ds:
   url: jdbc:mysql://localhost:3306/user?serverTimezone=UTC&useSSL=false
   username: root
   password: xxx
   connectionTimeoutMilliseconds: 30000
   idleTimeoutMilliseconds: 60000
   maxLifetimeMilliseconds: 1800000
   maxPoolSize: 50
   minPoolSize: 1
 shadow_ds:
   url: jdbc:mysql://localhost:3306/user_shadow?serverTimezone=UTC&useSSL=false
   username: root
   password: xxx
   connectionTimeoutMilliseconds: 30000
   idleTimeoutMilliseconds: 60000
   maxLifetimeMilliseconds: 1800000
   maxPoolSize: 50
   minPoolSize: 1

rules:
- !SINGLE
 tables:
   - "*.*"
 defaultDataSource: ds
- !SHADOW
  dataSources:
    shadowDataSource:
      productionDataSourceName: ds
      shadowDataSourceName: shadow_ds
  defaultShadowAlgorithmName: sql_hint_algorithm
  shadowAlgorithms:
    sql_hint_algorithm:
      type: SQL_HINT

An example of using shadow SQL Hint:

/* SHARDINGSPHERE_HINT: SHADOW=true */ SELECT * FROM t_user;
liuli12345 commented 17 hours ago

Use shadow SQL Hint is invalid image

liuli12345 commented 17 hours ago

Use the SQL Hint of data source pass through is valid image

terrymanu commented 17 hours ago

Thank you for the feedback, I will investigate it soon

strongduanmu commented 5 hours ago

I will fix this bug, thank you for your feedback. @liuli12345

strongduanmu commented 5 hours ago

This bug is due to Shadow's incorrect use of SQL Hint. HintValueContext should be used instead of extracting comment from SQLStatement.

After sql hint extracts the key value, in order to improve the hit rate of sql parsing cache, the sql hint comment will be deleted. At this time, the sql hint content cannot be obtained by obtaining comment through SQLStatement.

strongduanmu commented 4 hours ago

Hi @liuli12345, can you help test shadow sql hint with master branch?