Race condition in AutoIncrementTracker can cause two transactions to get assigned the same auto-incrementing ID.
- Dominant language
- Go
- Stars
- 24.4k
- Forks
- 873
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 121
Description
`AUTO INCREMENT` is supposed to be unaffected by transactions: not-yet-committed transactions can still advance the counter, and rolling back a transaction does not reset the counter. This allows two concurrent transactions to both insert into the same table with an `AUTO INCREMENT` column without causing a transaction conflict.
Unfortunately, it appears that in rare cases we can generate the same ID for two concurrent transactions, causing a conflict for whichever transaction commits second.
I was only able to get this to reproduce when the insertion was happening as the result of a trigger.
Steps to reproduce:
```
dolt sql <
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by running the SQL reproduction against dolt sql-server and compare the two transaction versions of the timestamps table for duplicate primary keys. Trace the AutoIncrementTracker behavior during trigger-driven inserts and concurrent transactions. Done means the reproduction no longer assigns the same auto-incrementing ID to both transactions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100