Skip to content

Fix transaction pollution in Shard.by_name

Nick Thomas requested to merge (removed):fix-transaction-shard into master

What does this MR do?

Per documentation in https://docs.gitlab.com/ee/development/sql.html#find_or_create_by-is-not-atomic

Spotted while reviewing https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/23508

Currently, we only use Shard.by_name in one place, where it is not run inside a transaction. So it's OK. However, in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/23508 , we start calling it from within a transaction.

In that case, the raising of ActiveRecord::RecordNotUnique pollutes the surrounding transaction. For Shard.by_name to be safe in all cases, we need it to happen within its own new transaction.

What are the relevant issue numbers?

Does this MR meet the acceptance criteria?

Merge request reports