Loading
Draft: docs: plan the repository column on cached remote children, with the migration patterns it uses
Summary
- Change: a plan to store the repository on cached remote versions and manifests (
maven_remote_versions,npm_remote_versions,container_remote_manifests), in nine steps that are safe on the live database. Each step is one MR, and its deploy gate says which earlier steps must run in production before it merges. The MR also updatesdocs/dev/database-migrations.mdanddocs/dev/database.mdwith the patterns the plan uses, so the plan links to them instead of repeating them. This is the first change to use them, so both ship together. - Why: today a query over one repository has to walk every package or image first. Remote cache cleanup and size-based eviction need that query, and adding the column later means a backfill on large partitioned tables. They are still small now.
- Downsides: one more column, a fill trigger and a wider foreign key per table, and a unique index on each parent. Nine deploys, and Steps 2 to 9 wait for the Migrator switch. The trigger stays until the Self-Managed upgrade guide follows the GitLab one-minor-at-a-time rule; #2023 tracks dropping it. No query uses the column yet: the container idle list rework moved to #1887.
The docs change fixes what led the first version of this plan astray:
- They said a partitioned foreign key has no add-then-validate form before PostgreSQL 18. It does:
NOT VALIDandVALIDATEper partition, then the parent attaches the valid keys without a scan. Measured on 16, 17 and 18: about 18 ms for the attach, against about 650 ms for a validating add that blocks writes. - New sections: the deploy-gated sequence for a required column, with a fill trigger so a Self-Managed upgrade that jumps versions stays safe; batched backfills without a framework; why a
NOT VALIDcheck must come after the backfill (it also refuses updates); how to bound locks on busy partitioned tables; and how to make a key add safe to replay: the drop guard on partition keys only, and each parent add in its own transactional migration.
Review order: this is the first time we apply this pattern, so after the team approves, a Database team member (Praba, praba.m7n, who reviewed our schema before) reviews it too. The MR stays a draft until then.
Checklist
- Risk first: Step 3, the backfill. Only Step 1 runs at boot. Steps 2 to 9 wait for the switch to Theseus Migrator (ops#26), whose
pre-upgradeJob gives each statement 15 minutes and each step the Job's deadline, instead of the shared 5-minute boot budget, and each step shows its timing on a Database Lab clone (gitlab-com/gl-infra/data-access/dbo/dbo-issue-tracker#754). If the backfill doesn't fit Migrator, it waits for Migrator's backfill support, and the plan stops there for a decision. - Conflicts: !3864 (merged) (
TestRepositoryScope) lists the old foreign keys as exemptions; Step 9 removes them if !3864 (merged) merged first. The npm deadlock in #1882 (closed) is not touched: neither the insert value nor the trigger takes a new lock. - Reach: none outside this service. No API or client change. GitLab Self-Managed (Beta) upgrades stay safe through the trigger.
- Coverage: the container idle index and query are in #1887. The lower remote levels, hosted and virtual are in the epic gitlab-org#24535.
- Least sure: the timings on production-sized data, which only a Database Lab clone can give. The batched
COMMITinside aDOloop runs through the goose CLI overpgxon PostgreSQL 17; Step 3's migration test proves it through our own runner.
Related to #1752
Edited by João Pereira