Multi DB support for loose foreign keys
What does this MR do and why?
This change adjusts the LooseForeignKeys::CleanupWorker
to work with multiple databases. To keep the delay minimal, we switched the scheduling to 1 minute (it was 5 minutes).
When CI and Main databases are configured:
- In even minutes, run the worker for
LooseForeignKeys::DeletedRecord
records in the Main database. - In odd minutes, run the worker for
LooseForeignKeys::DeletedRecord
records in the CI database.
When only one database (Main) is configured
- Invoke the worker every minute.
Additionally, we add the connection name to the extra metadata which will be logged in kibana.
How to test it:
- Setup two databases (2nd one can be PG.ai).
- Run rails console:
GITLAB_USE_MODEL_LOAD_BALANCING=true rails c
- Verify which DB is picked (changes every minute):
LooseForeignKeys::CleanupWorker.new.send(:connection_with_name)
- Run the worker:
LooseForeignKeys::CleanupWorker.new.perform
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 #341513 (closed)
Edited by Adam Hegyi