Add trigger to create overflow records
What does this MR do and why?
This MR adds the database trigger that automatically captures spillover builds into the ci_builds_partition_overrides table on insert. 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 p_ci_builds_partition_overrides table and builds_id_range column on ci_partitions |
| !231142 (closed) (this MR) | Add trigger to create overflow records |
| !229866 (closed) | Add switching logic to capture partition range intervals |
| !231138 (closed) | Add backfill migrations for builds partition tracking |
What is added
AddTriggersForBuildsOverrides (post-migrate) — creates the insert_ci_builds_partition_overrides trigger function and installs AFTER INSERT triggers on all currently active list-partitions of p_ci_builds. On each insert into p_ci_builds, the trigger automatically writes (build_id, partition_id, project_id) into ci_builds_partition_overrides using ON CONFLICT DO NOTHING for idempotency.
The trigger is scoped to active partitions (those with status = 3 in ci_partitions) and uses with_lock_retries to safely acquire the necessary locks. The trigger function itself is also created by !229866 (closed)'s SyncService at partition switch time going forward — this migration ensures the function and triggers exist for the currently active partition immediately after deploy.
Why this approach
The trigger provides real-time capture of spillover builds as they are inserted, complementing the backfill in !231138 (closed) which handles historical data. Together they ensure the override table stays complete and up-to-date, enabling reliable partition_id resolution without cross-partition scans.
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). - Run
db:migrate:post_deploy— verifies theinsert_ci_builds_partition_overridestrigger function is created and triggers are installed on activep_ci_buildspartitions. - Insert a row into an active
p_ci_buildspartition and confirm a corresponding row appears inci_builds_partition_overrides. - Run the spec suite for the migration spec.
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)