Skip to content
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

Client-side restart of failed transactions on CockroachDB #22240

Merged
merged 5 commits into from Apr 25, 2024

Conversation

paescuj
Copy link
Member

@paescuj paescuj commented Apr 18, 2024

Scope

Implement client-side restart of failed transactions on CockroachDB.

On failed transactions due to serialization error (another transaction attempting to write to the same data), CockroachDB responds with a 40001 error code 1, which indicates that the transaction should be restarted on client-side. This is usually enough to ensure that the transaction can still be executed successfully, as it is now carried out against the latest applicable state.

Reproduction

Before

Notice the missing relation on the user_updated field

before.mp4

After

after.mp4

Potential Risks / Drawbacks

  • Short delay for request
  • Might still fail in the end (i.e. can not auto-cover all cases)

Review Notes / Questions

None


Fixes #21424 (2/2, as follow-up on #22023)

Footnotes

  1. https://www.cockroachlabs.com/docs/stable/transaction-retry-error-reference

Copy link

changeset-bot bot commented Apr 18, 2024

🦋 Changeset detected

Latest commit: 827439f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@directus/api Patch
directus Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@paescuj paescuj requested review from a team, DanielBiegler and licitdev and removed request for a team April 19, 2024 21:09
Copy link
Contributor

@hanneskuettner hanneskuettner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the few comments this looks good to me and works on my end. I'm seeing one retried transaction and then it succeeds.

api/src/utils/transaction.ts Show resolved Hide resolved
api/src/utils/transaction.ts Show resolved Hide resolved
api/src/utils/transaction.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@hanneskuettner hanneskuettner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done!

@hanneskuettner hanneskuettner merged commit 4b75c37 into main Apr 25, 2024
4 checks passed
@hanneskuettner hanneskuettner deleted the retry-cockroach-trx branch April 25, 2024 12:19
@github-actions github-actions bot added this to the Next Release milestone Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

CockroachDB TransactionRetryWithProtoRefreshError on Collection Creation when using System Default fields
2 participants