-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If the autoid service node is not leader, save the cached ids back would cause potential 'Duplicate entry' error #46444
Comments
I would like to add more details on how 'Duplicate entry' can be encountered due to this bug(which is not easy actually).
And when the
Step 4 is a MUST to trigger this bug because if TiDB B keeps acting as the auto id owner, the range of ID cached in it is always correct, and it will overwrite the correct value for 'base' of auto id when reserving a new range of ID. |
Few more queries along the same line:
|
… for AUTO_ID_CACHE=1 tables (pingcap#46445) close pingcap#46444
… for AUTO_ID_CACHE=1 tables (pingcap#46445) close pingcap#46444
Yes, when the insert operation adds more records continuously, the autoid could grow and finally reach a new value that is greater than all the previous allocated ones. Then the duplicate entry error is gone.
alter table t auto_increment = xxx xxx can be get from 'show table t next_row_id'
alter table t auto_increment = xxx can be used to rebase the value to avoid the the duplicate id. |
… for AUTO_ID_CACHE=1 tables (pingcap#46445) close pingcap#46444
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
By read the code logic ... not easy to reproduce without special hack.
Imagine that tidb5 is autoid service leader.
It allocates id to 30000
Then tidb1 become leader, it continue to provide service.
tidb1 allocates to 34000
Then tidb5 exit, it doesn't know it's not leader anymore, and store 30000 the current max autoid
Later, there would be duplicated entry in range [30000, 34000)
2. What did you expect to see? (Required)
If the autoid service is not leader, it should not store the max autoid back when it exit.
3. What did you see instead (Required)
This line has bug!
tidb/autoid_service/autoid.go
Line 328 in 5ecf980
4. What is your TiDB version? (Required)
The text was updated successfully, but these errors were encountered: