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
@indexer
variable is not set in the initialization ofGitlab::Elastic::Indexer
- within the
update_index_status
method,Project.exists?
passes - project is deleted
-
@index_status
is set usingIndexStatus.find_or_safe_create_by!
which throws anActiveRecord::InvalidForeignKey
error 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::InvalidForeignKey
inupdate_index_status
and logs a warning if it occurs - Change
indexer.rb
to use thebuild_structured_payload
method soclass
is 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.