Add switching logic to capture partition range intervals
What does this MR do and why?
This MR implements the application-layer switching logic that activates the two-layer partition_id resolution strategy. It wires the partition range tracking and override trigger creation into the partition switching lifecycle inside Ci::Partitions::SyncService. 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 |
| !231142 (closed) | Add trigger to create overflow records |
| !229866 (closed) (this MR) | Add switching logic to capture partition range intervals |
| !231138 (closed) | Add backfill migrations for builds partition tracking |
What is added
Override triggers (create_override_triggers) — before switching writes to the next partition, installs AFTER INSERT triggers on each list-partition of p_ci_builds that correspond to the outgoing partition. These triggers call the insert_ci_builds_partition_overrides function to automatically capture any spillover builds into the override table going forward. The trigger definitions are declared in TRIGGER_DEFS, making the pattern extensible to other partitioned tables (e.g. job artifacts).
ID range boundary update (update_range_id_boundaries) — after the switch, computes MIN(id) and MAX(id) of builds in the outgoing partition and records them as the builds_id_range on ci_partitions. The new active partition gets an open-ended range starting from max + 1. This enables the fast, single-scan fallback lookup: given a build_id, the correct partition_id can be resolved by checking which partition's range contains it, without touching p_ci_builds at all.
Why this approach
Changing all Sidekiq worker signatures to accept a partition_id is not feasible short-term — it requires coordinated multi-release changes across every affected worker. This two-layer lookup (override table + ID range index) resolves partition_id transparently at query time with no worker signature changes, no Redis dependency on the hot path, and full durability via the FK cascade.
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 — application logic 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). - Trigger a partition switch via
Ci::Partitions::SyncServiceand verify that:AFTER INSERTtriggers are created on the outgoing partition's list-partitions ofp_ci_builds.ci_partitions.builds_id_rangeis populated for the outgoing partition and an open-ended range is set on the new active partition.
- Run the spec suite for
Ci::Partitions::SyncService.
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)