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

[2.6.x] Concurrent artifact creation test & fixes #5169

Merged
merged 5 commits into from
Sep 17, 2024

Conversation

EricWittmann
Copy link
Member

@EricWittmann EricWittmann commented Sep 12, 2024

This PR fixes a concurrency problem in the SQL storage when creating artifacts. There are several "upsert" style operations that must happen when creating artifacts, including:

  1. Creating the Group if one does not already exist
  2. Inserting Content only if it does not already exist
  3. Incrementing sequences (e.g. globalId and contentId)

There were existing race conditions (database dependent) for some or all of these operations.

This PR changes 1 and 2 so that the "Ensure Group Exists" and "Ensure Content Exists" operations occur in their own transactions. This allows us to forgo using UPSERT and instead simply try the INSERT and react to the primary key constraint violation. If a PK violation occurs then we simply go on to the next part of the create (e.g. if creating the group fails, it means the group already exists and we can skip to the next thing).

This new approach fixes the concurrency issues and also simplifies the logic a little bit. But it does this at the expense of introducing a small chance that a Group will be created even though it is not needed (e.g. if multiple concurrent operations attempt to auto-create the group but then all fail). The same is true of content.

As a result, this change MAY result in empty Groups or orphaned content. Orphaned content will get cleaned up automatically, but empty groups would need to be deleted manually. I think this is an acceptable tradeoff.

@EricWittmann EricWittmann changed the title Concurrent artifact creation test & fixes [2.6.x] Concurrent artifact creation test & fixes Sep 16, 2024
@EricWittmann EricWittmann marked this pull request as ready for review September 16, 2024 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants