Skip to content

Sharding5.3.2:shadow rule error #37081

@18835572909

Description

@18835572909
Image

Version
Springboot 2.7.18
ShardingJdbc 5.3.2

Resource step
PartialSQLRouteExecutor#route

=> step1: sharding rule => RouteUnit(dataSourceMap<db_1,db_1>, tableMap<order_tlb,order_tlb_1>);

=> step2: shadow rule

=> ShadowSQLRouter#decorateRouteContext

	=>AbstractShadowDMLStatementRouteEngine#route
	
	=>ShadowRouteEngine#decorateRouteContext

yml

props:
sql-show: true

dataSources:
db_0:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.jdbc.Driver
jdbcUrl: jdbc:mysql://ip1:3306/db_0?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true
username: root
password: ***
db_1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.jdbc.Driver
jdbcUrl: jdbc:mysql://ip1:3306/db_1?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true
username: root
password: ***
shadow_0:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.jdbc.Driver
jdbcUrl: jdbc:mysql://ip1:3306/shadow_0?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true
username: root
password: ***
shadow_1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.jdbc.Driver
jdbcUrl: jdbc:mysql://ip1:3306/shadow_1?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true
username: root
password: ***

rules:

  • !SHARDING
    shardingAlgorithms:
    table_inline:
    type: INLINE
    props:
    algorithm-expression: order_tbl_$->{Math.abs(order_no.hashCode()) % 2}
    database_inline:
    type: INLINE
    props:
    algorithm-expression: db_$->{Math.abs(user_id.hashCode()) % 2}
    defaultDatabaseStrategy:
    standard:
    shardingColumn: user_id
    shardingAlgorithmName: database_inline
    defaultTableStrategy:
    standard:
    shardingColumn: order_no
    shardingAlgorithmName: table_inline
    tables:
    order_tbl:
    actualDataNodes: db_$->{0..1}.order_tbl_$->{0..1}
  • !SHADOW
    dataSources:
    shadowDataSource1:
    productionDataSourceName: db_1
    shadowDataSourceName: shadow_1
    tables:
    order_tbl:
    dataSourceNames:
    - shadowDataSource1
    shadowAlgorithmNames:
    - user_id_value
    shadowAlgorithms:
    user_id_value:
    type: VALUE_MATCH
    props:
    operation: select
    column: user_id
    value: x3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions