-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
auto increment primary key backfill failed #24328
Comments
Hi @xrayw, why is your |
@strongduanmu Hi, thanks for your reply. I found the table i configed at the sharding.yml will always run the Or something was wrong with my usage about how to use auto_increment primary key when table is configed in the sharding.yml. |
Do you need more information? |
From your configuration, it seems you don't need sharding? tables:
user:
actualDataNodes: ds_0.user
tableStrategy:
standard:
shardingColumn: id
shardingAlgorithmName: user_archive
keyGenerateStrategy:
column: id
keyGeneratorName: autoinc |
I need!
Always insert to user, and read from multi table such as user, user_0, user_1 |
I can't get your point. If you need to use the sharding, it means that the local id is not globally unique. At this time, a globally unique id must be generated through sharding key generator, such as the snowflake algorithm. |
Example:
Data always insert to main table I can write a shardingRule such as: public class UserShardingAlgorithm implements StandardShardingAlgorithm<Long> {
@Override
public String getType() {
return "USER_SHARD";
}
/**
* [
* {
* range: 1 - 100,
* table: user_1
* },
* {
* range: 101 - 200,
* table: user_2
* }
* ]
*/
@Override
public String doSharding(Collection<String> availables, PreciseShardingValue<Long> shardingValue) {
Long id = shardingValue.getValue();
if (id == null) {
// always insert to user
return "user";
}
// for query,
List<IdTableRange> idTableMapping = someIdMappingLogic();
for (IdTableRange idTableRange : idTableMapping) {
if (idTableRange.contains(id)) {
return idTableRange.table;
}
}
throw new RuntimeException("unreachable");
}
@Override
public Collection<String> doSharding(Collection<String> collection, RangeShardingValue<Long> rangeShardingValue) {
return null;
}
@Override
public Properties getProps() {
return null;
}
@Override
public void init(Properties properties) {
}
} |
If the user table is a single table, there is no need to configure sharding rules and keyGenerateStrategy. |
But i need move old data from user to archive tables like user_1, user_2, ...user_x The |
Hi, Is there any solution for this scenario?? thanks |
It looks like the problem is because the key output by the AUTOINC algorithm is null. For your scenario, you can find a way to control the global self-increment of this value, and let the AUTOINC algorithm output the value according to the expectation. |
This issue has been inactive for a long time, so I will close it. |
Question
I have some table, such as
I want always insert data to user and i'll move old data to user_0/user_1 manually at sometime.
but when i run my code, i got the error:
my config:
sharding.yml
UserShardingAlgorithm
AutoIncrementKeyGeneratorAlgorithm.java
entity
My test code:
UserMapper
I want to know how i can get the auto increment paimary key's value.
Thanks
shardingjdbc version: 5.3.1
mybatisplus version: 3.5.3.1
The text was updated successfully, but these errors were encountered: