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

Remove nested transactions #22023

Merged
merged 9 commits into from Apr 16, 2024
Merged

Remove nested transactions #22023

merged 9 commits into from Apr 16, 2024

Conversation

rijkvanzanten
Copy link
Member

@rijkvanzanten rijkvanzanten commented Mar 29, 2024

Scope

What's changed:

When using knex.transaction() it will create a transaction, even if you're already in a parent transaction. This in turn causes issues in some database types that don't handle nested transactions, or mixing of DDL and transactions well, like CockroachDB.

Bug #21424 was caused by the CollectionsService starting a transaction, and using the FieldService which in turn uses the ItemsService to create the fields in the meta tables in another transaction. This nested transaction structure causes CRDB to panic.

As far as I'm aware, we're never utilizing nested transactions on purpose, so to prevent other unexpected issues in the future I replaced every runtime usage of knex.transaction() with a new transaction utility that'll reuse the existing transaction if we're already in a transaction.

Potential Risks / Drawbacks

  • This change affects basically everything in the whole API, so it's a high risk change.

Review Notes / Questions

  • The fix is intended for CockroachDB, so additional testing there would be nice.
  • Seeing the high risk, additional usage testing is required.
  • This might result in a performance improvement in some databases by reducing the number of simultaneous transactions.

Fix 1/2 for #21424

Copy link

changeset-bot bot commented Mar 29, 2024

🦋 Changeset detected

Latest commit: 4be2991

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

Copy link
Member

@br41nslug br41nslug left a comment

Choose a reason for hiding this comment

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

promises promises promises 😂

api/src/services/collections.ts Outdated Show resolved Hide resolved
api/src/utils/transaction.ts Outdated Show resolved Hide resolved
@paescuj paescuj enabled auto-merge (squash) April 15, 2024 23:20
@paescuj paescuj merged commit 577f08e into main Apr 16, 2024
4 checks passed
@paescuj paescuj deleted the issue/21424 branch April 16, 2024 08:13
@github-actions github-actions bot added this to the Next Release milestone Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants