Skip to content

Use replica DB to read ContainerRepository requiring_cleanup ids

Context

The ContainerExpirationPolicies::CleanupContainerRepositoryWorker is a limited capacity worker. Those "type" of workers don't receive the element to work on in their #perform method. Instead, they need to fetch it.

In our concerned worker, the query to fetch the next record to work on is causing a high database CPU usage. The database team suggested this approach to direct the query to fetch the records from the replica database instead of the main one.

What does this MR do and why?

  • Use the replica database to fetch the IDs of the latest 10 requiring cleaning container_repositories rows.
  • Use those 10 fetched IDs to narrow down the search scope of the query on the main database.
  • Add a new index to the container_repositories table to enhance the performance of the replica database query. The index is added on the columns used for sorting (expiration_policy_cleanup_status & expiration_policy_started_at).

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Related to #440874 (closed)

Edited by Moaz Khalifa

Merge request reports