Add backfill migrations for builds partition tracking
What does this MR do and why?
This MR adds the backfill migrations needed to populate the partition tracking data structures introduced in !228838 (merged). It is part of the corrective action for INC-8367.
This MR has been split out from !228838 (merged). The full work is tracked across the following MRs:
| MR | Description |
|---|---|
| !228838 (merged) | Add ci_builds_partition_overrides table and builds_id_range column on ci_partitions |
| !229866 (closed) | Add switching logic to capture partition range intervals |
| !231138 (closed) (this MR) | Add backfill migrations for builds partition tracking |
| !231142 (closed) | Add trigger to create overflow records |
What is added
BackfillBuildsIdRangeOnCiPartitions (post-migrate) — backfills the builds_id_range column on existing ci_partitions rows by computing the min build ID per partition. For each partition, it sets the range as [min_id_in_partition, min_id_in_next_partition), leaving the last (active) partition with an open-ended range.
QueueBackfillCiBuildsPartitionOverrides (post-migrate) — enqueues a batched background migration (BackfillCiBuildsPartitionOverrides) to populate the override table for all existing spillover records. It processes each non-empty, non-current partition independently, using the builds_id_range boundaries to scope the batch correctly.
BackfillCiBuildsPartitionOverrides (background migration) — the actual BBM worker that inserts (build_id, partition_id, project_id) rows into ci_builds_partition_overrides for all builds in a given partition batch, using ON CONFLICT DO NOTHING for idempotency.
Why this approach
The backfill is necessary to ensure that existing spillover builds (those inserted into a non-active partition before the override table existed) are captured retroactively. Without this, the two-layer lookup introduced in !228838 (merged) and !229866 (closed) would only work for builds created after the trigger is installed.
Changelog: other
References
- Related issue: #593701 (closed) — CI partition pruning: cache record_id → partition_id to fix unpruned single id queries
- Incident review: https://gitlab.com/gitlab-com/gl-infra/production/-/work_items/21534#note_3158996366
- CI partitioning design doc: https://handbook.gitlab.com/handbook/engineering/architecture/design-documents/ci_data_decay/pipeline_partitioning/
Screenshots or screen recordings
N/A — database migrations only
| Before | After |
|---|---|
How to set up and validate locally
- Ensure !228838 (merged) is merged first (provides the
ci_builds_partition_overridestable andbuilds_id_rangecolumn). - Run
db:migrate:post_deploy— verifiesbuilds_id_rangeis backfilled onci_partitionsand the BBM is queued. - Inspect
ci_partitionsrows to confirmbuilds_id_rangeis populated for all non-empty partitions. - Run the spec suite for the background migration and migration specs.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #593701 (closed)