Handle InvalidForeignKey error within `ensure_metrics`
What does this MR do?
This MR fixes a race condition that could lead to InvalidForeignKey
error.
Example:
Merge request is being processed in two different processes (process_1, process_2).
-
process_2
callssave
on an existing MR. -
process_1
callsdelete
on the merge request at the same time. -
process_2
starts processingafter_save
callbacks -
process_1
finished deleting the MR. -
process_2
has no metrics records (deleted) and it tries to create it (#ensure_metrics
) -
process_2
fails to create the metrics record since themerge_request
record is not there anymore (invalid FK)
I'm setting the ~backstage label because the error mostly occurs within sidekiq.
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Closes #200095 (closed)
Edited by Adam Hegyi