You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "charlotte-xiao (via GitHub)" <gi...@apache.org> on 2023/06/05 09:41:08 UTC
[GitHub] [shardingsphere] charlotte-xiao commented on issue #3422: version 4.0.0-RC2: key generated by SnowflakeShardingKeyGenerator mod 4 always is 0/1, expected 0/1/2/3
charlotte-xiao commented on issue #3422:
URL: https://github.com/apache/shardingsphere/issues/3422#issuecomment-1576468926
When I use snowflake algorithm to mod 4, it seems still has this problems.
This is my graddle info:
```
implementation 'org.apache.shardingsphere:shardingsphere-jdbc-core:5.2.1'
// org.springframework.boot version '2.5.14'
implementation 'org.yaml:snakeyaml:1.33'
```
This is my config for shardingsphere:
```
mode:
type: Standalone
dataSources:
ds:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.cj.jdbc.Driver
jdbcUrl:xxxx
username: xxxx
password: xxxx
rules:
- !SHARDING
tables:
tb_user:
actualDataNodes: ds.tb_user_${0..1}
tableStrategy:
standard:
shardingColumn: id
shardingAlgorithmName: tb_user_inline
keyGenerateStrategy:
column: id
keyGeneratorName: snowflake
tb_role:
actualDataNodes: ds.tb_role_${0..1}
tableStrategy:
standard:
shardingColumn: id
shardingAlgorithmName: tb_role_inline
keyGenerateStrategy:
column: id
keyGeneratorName: snowflake
tb_user_role:
actualDataNodes: ds.tb_user_role_${0..1}
tableStrategy:
standard:
shardingColumn: id
shardingAlgorithmName: tb_user_role_inline
keyGenerateStrategy:
column: id
keyGeneratorName: snowflake
tb_order:
actualDataNodes: ds.tb_order_${0..3}
tableStrategy:
standard:
shardingColumn: id
shardingAlgorithmName: tb_order_inline
keyGenerateStrategy:
column: id
keyGeneratorName: snowflake
bindingTables:
- tb_user,tb_role,tb_user_role
shardingAlgorithms:
tb_user_inline:
type: INLINE
props:
algorithm-expression: tb_user_${id.toLong() % 2}
tb_role_inline:
type: INLINE
props:
algorithm-expression: tb_role_${id.toLong() % 2}
tb_user_role_inline:
type: INLINE
props:
algorithm-expression: tb_user_role_${id.toLong() % 2}
tb_order_inline:
type: INLINE
props:
algorithm-expression: tb_order_${id.toLong() % 4}
keyGenerators:
snowflake:
type: SNOWFLAKE
props:
sql-show: true
```
And when insert record to ds.tb_order_${0..3}, I find it will just insert into ds.tb_order_0 and ds.tb_order_1.
--
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