feat: Enable automatic DB reindexing using CronJob
What does this MR do?
feat: Enable automatic DB reindexing using CronJob
Related to gitlab-com/gl-infra/delivery#21668
Automatic database reindexing is possible in an Omnibus installation by flipping some
configuration values inside the gitlab.rb file. As far as I can tell, Helm chart installations
that use CNG (Cloud Native GitLab) container images do not have a native method for runnig
reindexing periodically.
The Toolbox chart already has a CronJob for taking a backup. So, I am proposing that we add a CronJob that will perform automatic database reindexing on a user-specified schedule.
The script that is mentioned in this MR is added to the Rails image in this CNG MR: gitlab-org/build/CNG!2712 As usual, before running the script, we ensure that the dependencies (Postgres and Redis) are accessible.
The script will run a Rake task, which emulates the behavior from Omnibus, when the configuration flags mentioned here are enabled: https://gitlab.com/gitlab-org/omnibus-gitlab/-/blob/b26f58eb8a5e14be5ee3ddc6c16a8ecf9a462181/files/gitlab-cookbooks/gitlab/recipes/database_reindexing_enable.rb#L27
Changelog: added
What Does gitlab:db:reindex Do?
This Rake task has limitations on the job's workload that are defined inside the GitLab codebase: It will create at most 2 indexes (asynchronously) and re-index at most 2 existing indexes. So, it will not run indefinitely, and we don't need to impose any other limits on it. The code identifies what to re-index using an index bloat heuristic.
-
db.rake-
Async index creation
- At most 2 indexes will be created
-
Async constraint validation
- At most 2 constraints will be validated
-
Reindexing
- At most 2 existing indexes will be reindexed
-
Async index creation
Related issues
Author checklist
For general guidance, please follow our Contributing guide.
Required
For anything in this list which will not be completed, please provide a reason in the MR discussion.
-
Merge Request Title and Description are up to date, accurate, and descriptive. -
MR targeting the appropriate branch. -
MR has a green pipeline. -
Documentation created/updated. -
Tests added/updated, and test plan for scenarios not covered by automated tests. -
Equivalent MR/issue for omnibus-gitlab opened. - Not required. Omnibus already has this feature. See https://docs.gitlab.com/omnibus/settings/database/#automatic-database-reindexing for the configuration flags which should be set to use this.
Reviewers checklist
-
MR has a green pipeline on https://gitlab.com/gitlab-org/charts/gitlab. -
Consider downstream impact to the Operator, as per evaluating impact from changes to GitLab chart.