docs(transactions): note the lost-update risk in read-modify-write - #4593
Open
shaikn6 wants to merge 1 commit into
Open
docs(transactions): note the lost-update risk in read-modify-write#4593shaikn6 wants to merge 1 commit into
shaikn6 wants to merge 1 commit into
Conversation
The bumpCounter example reads a row and writes counter+1 in a transaction without locking. Under READ COMMITTED (the default) two concurrent runs can both read the same value and lose an update. Add a short section pointing at SELECT ... FOR UPDATE and SERIALIZABLE + retry. Addresses sqlc-dev#3485
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The Using transactions how-to's
bumpCounterexample reads a row and then writescounter + 1inside a transaction:Under the default isolation level (
READ COMMITTED, on both PostgreSQL and MySQL/InnoDB), two transactions running this concurrently can both read the samecounterand both write the samecounter + 1— a lost update. The page presents this as the standard pattern with no caveat, which is what #3485 flags.Change
Docs only. Adds a short Concurrent read-modify-write section after the examples:
GetRecordForUpdatequery usingSELECT ... FOR UPDATESERIALIZABLE+ retry as the alternative, noting sqlc doesn't manage isolation levels or retriesExisting examples are unchanged — they still demonstrate
WithTx, which is the page's purpose.Closes #3485