Handle InvalidForeignKey errors when indexing deleted projects
Background
Related to #360581 (closed)
The error described in the issue doesn't happen often (and the instances I've seen are only related to QA data, but it is possible to occur in rare instances).
What's happening is:
- new project is created and queued for indexing
- the
@indexervariable is not set in the initialization ofGitlab::Elastic::Indexer - within the
update_index_statusmethod,Project.exists?passes - project is deleted
-
@index_statusis set usingIndexStatus.find_or_safe_create_by!which throws anActiveRecord::InvalidForeignKeyerror because the project was deleted in the small window between the check and the create call
What does this MR do and why?
- Adds a rescue for
ActiveRecord::InvalidForeignKeyinupdate_index_statusand logs a warning if it occurs - Change
indexer.rbto use thebuild_structured_payloadmethod soclassis filled out in all the logs - Add (and refactor a little) the indexer specs
Screenshots or screen recordings
N/A
How to set up and validate locally
I was unable to verify this manually by indexing b/c it's next to impossible to delete a project in between those checks without a breakpoint
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.