Stop deadlocks between parallel step and image saves (#43) #46
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MassiveDynamic/kataba!46
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/43-write-conflict-row-locks"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #43.
Root cause
The database is MySQL 8.4, not MariaDB. Prisma reports MySQL error 1213 (deadlock) as
TransactionWriteConflict; thequeryRawin the stack trace is the adapter's own method, notlockStep. The statement that failed wasstepLine.createinsaveStep.Under REPEATABLE READ,
deleteMany({where: {stepId}})on a step with no lines takes a gap lock on the(stepId, position)index. When two parallel tests save empty steps whose ids fall in the same gap, both get the gap lock and each insert waits for the other. A two-connection script reproduces this: 1213 under REPEATABLE READ, no error under READ COMMITTED. Annotations are replaced the same way (delete, then insert).Changes
src/db.ts, the client's defaulttransactionOptions). Transactions already serialise on parent-row locks, so the gap locks guarded nothing.saveSteplocked the guide and then the step; image and annotation changes locked the step and then the guide (viatouchGuide), so they could deadlock on each other.lockStepis gone: every change inside a guide takeslockGuidefirst.addStepnow takes it too, so two adds at once can't get the same position.Verification
--repeat-each=3, with no retries, every one passing and no write-conflict lines in the server log.🤖 Generated with Claude Code