You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "Famezyy (via GitHub)" <gi...@apache.org> on 2024/06/07 07:13:44 UTC
[I] mixing shadow rule and sharding rule doesn't work [shardingsphere]
Famezyy opened a new issue, #31622:
URL: https://github.com/apache/shardingsphere/issues/31622
for the below configuration, if I comment out the `sharding` rule then the `shadow` function is working well:
*configuration*
```yaml
mode:
type: Standalone
props:
sql-show: true
dataSources:
db-order0:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.cj.jdbc.Driver
jdbcUrl: jdbc:mysql://localhost:3306/sharding?allowPublicKeyRetrieval=true
username: root
password: 123456
db-order1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.cj.jdbc.Driver
jdbcUrl: jdbc:mysql://localhost:3307/sharding?allowPublicKeyRetrieval=true
username: root
password: 123456
db-order2:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.cj.jdbc.Driver
jdbcUrl: jdbc:mysql://localhost:3308/sharding?allowPublicKeyRetrieval=true
username: root
password: 123456
rules:
- !SINGLE
tables:
- "*.*"
# - !SHARDING
# tables:
# user:
# actualDataNodes: db-order$->{0..2}.user
# databaseStrategy:
# standard:
# shardingColumn: id
# shardingAlgorithmName: inline
# shardingAlgorithms:
# inline:
# type: INLINE
# props:
# algorithm-expression: db-order$->{id % 2}
- !SHADOW
dataSources:
shadowDataSource:
productionDataSourceName: db-order1
shadowDataSourceName: db-order2
tables:
user:
dataSourceNames:
- shadowDataSource
shadowAlgorithmNames:
- user_id_insert_match_algorithm
defaultShadowAlgorithmName:
shadowAlgorithms:
user_id_insert_match_algorithm:
type: VALUE_MATCH
props:
operation: insert
column: id
value: 1
```
*output*
```sql
Logic SQL: INSERT INTO user ( id ) VALUES ( ? )
# This SQL is successfully rotated to shadow database db-order2
Actual SQL: db-order2 ::: INSERT INTO user ( id ) VALUES ( ? ) ::: [1]
Logic SQL: INSERT INTO user ( id ) VALUES ( ? )
Actual SQL: db-order1 ::: INSERT INTO user ( id ) VALUES ( ? ) ::: [2]
```
But if I add `sharding` rules, the `shadow` function doesn't work using the exact same sql.
*conofiguration*
```yaml
mode:
type: Standalone
props:
sql-show: true
dataSources:
db-order0:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.cj.jdbc.Driver
jdbcUrl: jdbc:mysql://localhost:3306/sharding?allowPublicKeyRetrieval=true
username: root
password: 123456
db-order1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.cj.jdbc.Driver
jdbcUrl: jdbc:mysql://localhost:3307/sharding?allowPublicKeyRetrieval=true
username: root
password: 123456
db-order2:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.cj.jdbc.Driver
jdbcUrl: jdbc:mysql://localhost:3308/sharding?allowPublicKeyRetrieval=true
username: root
password: 123456
rules:
- !SINGLE
tables:
- "*.*"
- !SHARDING
tables:
user:
actualDataNodes: db-order$->{0..2}.user
databaseStrategy:
standard:
shardingColumn: id
shardingAlgorithmName: inline
shardingAlgorithms:
inline:
type: INLINE
props:
algorithm-expression: db-order$->{id % 2}
- !SHADOW
dataSources:
shadowDataSource:
productionDataSourceName: db-order1
shadowDataSourceName: db-order2
tables:
user:
dataSourceNames:
- shadowDataSource
shadowAlgorithmNames:
- user_id_insert_match_algorithm
defaultShadowAlgorithmName:
shadowAlgorithms:
user_id_insert_match_algorithm:
type: VALUE_MATCH
props:
operation: insert
column: id
value: 1
```
*output*
```sql
Logic SQL: INSERT INTO user ( id ) VALUES ( ? )
# This SQL should be routed to shadow database db-order2
Actual SQL: db-order1 ::: INSERT INTO user ( id ) VALUES (?) ::: [1]
Logic SQL: INSERT INTO user ( id ) VALUES ( ? )
Actual SQL: db-order0 ::: INSERT INTO user ( id ) VALUES (?) ::: [2]
```
I'm not sure is it normal or something went wrong in my configuration.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] mixing shadow rule and sharding rule doesn't work [shardingsphere]
Posted by "Famezyy (via GitHub)" <gi...@apache.org>.
Famezyy commented on issue #31622:
URL: https://github.com/apache/shardingsphere/issues/31622#issuecomment-2156665086
I figured it out, in sharding rule I have to use the logic data source name defined in shadow rule. It is working well as expected.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] mixing shadow rule and sharding rule doesn't work [shardingsphere]
Posted by "Famezyy (via GitHub)" <gi...@apache.org>.
Famezyy closed issue #31622: mixing shadow rule and sharding rule doesn't work
URL: https://github.com/apache/shardingsphere/issues/31622
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org