Repository navigation
fix(storage-postgres): apply a TransactWriteItems once when two sends share a ClientRequestToken #873
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
Open
LeeroyHannigan
wants to merge
6
commits into
fix/transact-index-key-order
Choose a base branch
from
fix/851-pg-token-race
base: fix/transact-index-key-order
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix(storage-postgres): apply a TransactWriteItems once when two sends share a ClientRequestToken #873
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ed1ab6d
fix: apply a TransactWriteItems once on PostgreSQL when two sends sha…
LeeroyHannigan 6651759
Merge fix/transact-index-key-order into fix/851-pg-token-race
LeeroyHannigan 4b6c58b
fix: answer TransactionInProgress if the second token read is still s…
LeeroyHannigan ba547aa
test: cover two requests with one token and two sends that take an ol…
LeeroyHannigan 3acef8c
docs: say that the second token read depends on READ COMMITTED
LeeroyHannigan 60d1296
Merge fix/transact-index-key-order into fix/851-pg-token-race
LeeroyHannigan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: fail closed if the second read is still stale. The doc comment shows that the second statement cannot return no row or a
cancelled:row of this request. If it ever did, this arm would treat the token as new and apply the request again, which is #851.That argument rests on two facts that this function does not check. The transaction runs at READ COMMITTED, but
begin()takes the role's default (see the review summary). AndNOW()is the same in both statements. A later change could break either one. AnsweringTransactionInProgressin that case costs nothing. It is the answer the service gave in 18 of 20 rounds of this race in the PR's measurement, the engine maps it toTransactionInProgressException("Transaction from previous request is still in progress"),is_conflict_abortpasses it through, and the Cassandra backend already returns it for an in-progress token:I applied this locally:
cargo fmt --checkandcargo clippy -p extenddb-storage-postgres --all-targets -- -D warningsstay clean, andtwi_conflictpasses 14 of 14.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 4b6c58b. If the second statement still returns no row, or this request's
cancelled:row, the check now answersTransactionInProgressand does not run the request. Both reads use one helper,stale_read. 3acef8c changes the doc comment.begin()takes the default isolation level of the role or the database. So the comment now says that the second statement reads the locked row when the transaction runs at READ COMMITTED.I ran the four race tests in
twi_conflict.rs3 times with each answer printed, and no call answeredTransactionInProgress. In all 240 roundsngrew by 1 and one call answeredOk. The other call answered the replay in the three tests with one request, and the mismatch in the test with two requests.twi_conflictpassed in 5 of 5 runs (16 tests), andcargo fmt --checkand both clippy commands ofclippy.ymlare clean.