错误代码:Cause: java.lang.IllegalStateException: no table route info
### The error may involve com.huohuo.sharding.mapper.CourseMapper.insert-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO course ( id, name, type, status ) VALUES ( ?, ?, ?, ? )
### Cause: java.lang.IllegalStateException: no table route info
我们看日志记录可以看到JDBC配置tables如下:
tables:
course:
actualDataNodes: m1.course_$->{1..2}
keyGenerator:
column: id
props:
worker.id: '1'
type: SNOWFLAKE
logicTable: course
tableStrategy:
inline:
algorithmExpression: m1.course_$->{status.toInteger()%2+1}
shardingColumn: status
user:
actualDataNodes: m1.user_$->{1..2}
keyGenerator:
column: id
props:
worker.id: '1'
type: SNOWFLAKE
logicTable: user
tableStrategy:
inline:
algorithmExpression: m1.user_$->{status.toInteger()%2+1}
shardingColumn: status
到底哪里出了问题???看配置文件配置,找了半天不晓得哪里的问题,最终也只是把algorithm-expression的value改动了一下,之前是m1. 然后把这个去掉就执行成功了。
#actual-data-nodes course这个逻辑表对应的真实的表分布 m1.course_1 m1.course_2
spring.shardingsphere.sharding.tables.course.actual-data-nodes=m1.course_$->{1..2}
#主键生成策略 对cid进行一下生成,采用了雪花算法 SNOWFLAKE;对worker.id可不配置,有默认值
spring.shardingsphere.sharding.tables.course.key-generator.column=id
spring.shardingsphere.sharding.tables.course.key-generator.type=SNOWFLAKE
spring.shardingsphere.sharding.tables.course.key-generator.props.worker.id=1
spring.shardingsphere.sharding.tables.course.table-strategy.inline.sharding-column=status
spring.shardingsphere.sharding.tables.course.table-strategy.inline.algorithm-expression=course_$->{status.toInteger()%2+1}
spring.shardingsphere.sharding.tables.user.actual-data-nodes=m1.user_$->{1..2}
spring.shardingsphere.sharding.tables.user.key-generator.column=id
spring.shardingsphere.sharding.tables.user.key-generator.type=SNOWFLAKE
spring.shardingsphere.sharding.tables.user.key-generator.props.worker.id=1
spring.shardingsphere.sharding.tables.user.table-strategy.inline.sharding-column=status
spring.shardingsphere.sharding.tables.user.table-strategy.inline.algorithm-expression=user_$->{status.toInteger()%2+1}
error报错就是:没有表路由信息,不知道锁定那张表,但是就是一个库m1,为何加上m1就不行呢?
目前觉得因为是分表配置,无需加上相关变动value,当执行分库策略时候,就不得不加上前缀了。