Upsert container repositories when finding or creating them
What does this MR do and why?
In this MR, we use upsert
to create container repositories instead of safe_find_or_create_by
to avoid a race condition where there are multiple attempts to create the same exact container repository, making the uniqueness check fail.
Previously, we had the timeout solution, but with feedback from our database maintainers, we were recommended to use upsert
instead.
- MR with the similar issue with race condition: !138754 (merged)
- Slack thread in
#database
- Database Maintainer feedback: !138616 (comment 1689170603)
In #428115 (closed), we see that for some setups, safe_find_or_create_by
returns a repository that is not yet persisted. That method uses transactions and it's possible that the transaction has not persisted yet. We saw that adding a sleep(1)
fixes the issue as it gives more time to let the transaction persist.
We previously implemented a timeout to solve this but upon discussions with the database maintainers, upsert
was the recommended solution.
How to set up and validate locally
You may refer to the issue on the steps to reproduce locally.
With this fix, doing the podman push ...
should work. docker push ...
should work as well.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #428115 (closed)