Loading
feat(rpm): add the RPM package and version tables (S38 plan: 8/59)
Summary
- Problem: RPM needs somewhere to keep its packages and versions before an upload can commit one.
- Impact: Users see nothing. No RPM repository can be created before Step 54, and no code writes the new tables yet.
- Change: Adds
rpm_packagesandrpm_versionsas S38 Data sets them onmain. Every row carriesrpm_repository_id, not null, and a version references its package with it, so a version cannot name another repository's package. A package name and a version's NEVRA (name,evr_key, architecture) are unique among live rows only, so a deleted name or NEVRA can be uploaded again. A version stores the header fields the rebuild needs and holds a blob attachment.rpm_versionsjoins the test-only pending list, so the catalog-derived tests accept it before its reconcile, reap and attachment-guard code exists. The list now reads its tables from its formats, sorpm_versionsleaves it with RPM. - Downsides: The package-read index is partial, as S38 on
mainsays. The open amendment !3863 (merged) makes it non-partial for the rebuild's lookup of deleted versions by checksum, and #1975 (closed) records that Step 26 makes that change. The plan line for it belongs in !3863 (merged), beside that S38 row, so this MR leaves the plan alone. The header strings (summary,description,packagerand the rest) carry no length CHECK: S38 bounds them only throughrpm.max_header_size, which an administrator can raise, so a fixed cap could refuse a valid package.
What this does not reach, and who owns it:
- The reconcile, reap and attachment-guard code for
rpm_versions. Step 49 (#1998) adds the tombstone scans and counts, Step 50 (#1999 (closed)) the components count, reconcile walk and fixture, and Step 51 (#2000) the attachment guard clause. Until then the pending list lets the five version-type invariants and the attachment guard's pin pass without them. A site that does namerpm_versionsis still checked. The exemption covers the table, not each site, so until Step 53 a site that already namesrpm_versionscould lose it with no test failing. Nothing writes the table before Step 54, and the attachment key refuses the delete of an attachment a version holds, so a missing guard clause fails with an error rather than losing data. - Taking
rpm_versionsoff the pending list. It leaves with RPM in Step 53 (#2002).pendingformats.Tablesreads its tables fromFormats, so a table cannot stay on the list after its format leaves it. - Merge order. None is required. !4068 (merged) (Step 10) has merged, and this branch is rebased onto it with both facts kept in the
pendingformatsdoc comment. !3863 (merged), !4054 (merged) and !4085 (merged) also edit S38, and each merges cleanly with this MR at c16430a7. No other open S38 MR touches this MR's files. - !3863 (merged)'s wording. Its Step 8 line and its two new index rows name
(id, namespace_id, rpm_repository_id). This MR builds(namespace_id, rpm_repository_id, id), the order onmain's plan, so one index serves the version reference and the key checks when an RPM repository or a namespace is deleted. Withidfirst,rpm_packageswould need one more index, because its live-name index is partial. The reference itself still lists(id, namespace_id, rpm_repository_id), asdocs/dev/database.mdshows. !3863 (merged) should name the built order.
Plan and spec amendments
- S38 gains the
rpm_versions (namespace_id, blob_storage_attachment_id)index row: the attachment-delete key check. Every table with an attachment key carries that index, andTestDeleteUnreferencedAttachmentStmt_EveryClauseCorrelationIsIndexedrequires it.
Testing
internal/datastore/migrations, one suite per table.rpm_packages: the name bound, with a multibyte value at the cap; the version-7 id; a live and a tombstoned package sharing a name; a second live one refused by the live-name index, and another name or another repository allowed; a null, absent or other-namespace repository refused; and the RPM row's delete refused while a package is left.rpm_versions: every CHECK bound (epoch, name, version, release,evr_key, architecture,file_name, the header range, the two provenance ids,blob_sha256, the id); a live and a tombstoned version sharing a NEVRA; another name, another architecture and another repository allowed; a second live version refused by the identity index even when its uploaded version is spelled differently; a null repository, package, attachment orblob_sha256refused; a package of another repository or namespace, or none, refused; an attachment that is absent, of another blob or of another namespace refused; and the package and attachment deletes refused while a version is left.- The file-layout tests Step 7 added now cover both migrations: keys last under
lock_timeout, each add after its guard, everyCREATEguarded, and the Down order.
internal/datastore:TestRepositoryStore_DeleteFKAssumption_SchemaGuardexpects the newrpm_packagestorpm_repositoriesblocking edge. The version-type invariants and the attachment guard's pin read the pending list.- I broke these constraints in
structure.sql, one at a time, and a test failed every time: both live-only indexes made non-partial,namedropped from both, architecture dropped from the identity index, the package reference narrowed to(rpm_package_id, namespace_id), the package and repository references madeCASCADE, the attachment key dropped,rpm_repository_idmade nullable on each table,rpm_package_id,blob_storage_attachment_idandblob_sha256each made nullable onrpm_versions, each of the three header-range conditions dropped, and one bound loosened on each of epoch,evr_key(both ends), architecture (both ends), version, release, name (both tables),file_name,gitlab_user_idandblob_sha256. Taking RPM offpendingformats.Formatsempties the table list too, and fails all five invariants and the guard's pin. Dropping the new blocking edge fails the schema guard. - At c16430a7 the full
internal/datastore/migrationsintegration suite, theinternal/datastoreandinternal/usagedataunit tests andTestRepositoryStore_DeleteFKAssumption_SchemaGuardpass on PostgreSQL 16. CI runs every suite on 16, 17 and 18. After the rebase, a freshscripts/db/dump-structure.shrun matches the committedstructure.sql. golangci-lint, untagged and throughscripts/ci/lint-integration.sh, reports 0 issues on the changed packages.
Checklist
- Ran it: I ran both migrations up, down and up again on PostgreSQL 16. No client applies: no route reads or writes these tables yet.
- Interfaces and data: Schema only: two new tables. No API or configuration change. S38 describes the tables, and this MR adds its missing attachment index row. No user docs, since RPM is not usable yet.
- Failure: The database refuses a bad row with a CHECK, unique, not-null or foreign-key error. Nothing writes these tables yet, so no client sees one.
- Rollout: The previous release never reads the new tables. A rollback drops them, which loses nothing before Step 54 accepts creates.
- Hot path: No new query. The attachment key adds one check to every attachment delete, in every format: a lookup on
index_rpm_versions_on_ns_id_bsa_idin one partition, which is empty until Step 54. - Database: Yes: two new migrations and no query. The migration timings are below.
- Security: No input, route or permission. A version row keeps the upload's provenance,
gitlab_user_idandpackager, which S38's Lifecycle names as data that identifies people. - ADRs: ADR-007 (hash partitions on
namespace_id, composite keys, one attachment per blob use, no cascade into the attachment tables), and ADR-025 (every stored file holds an attachment). Both hold: every reference takesNO ACTION, so the reap removes each version with its attachment. - E2E: None. No route or client behavior changes.
- Simplicity: I built S38's index list, plus the one attachment index
TestDeleteUnreferencedAttachmentStmt_EveryClauseCorrelationIsIndexedrequires, and left out the tombstone, download and size indexes the npm and Maven tables carry, since no RPM read uses them yet. The unique key leads withnamespace_idandrpm_repository_id, so it also serves both delete-side key checks without another index.
Database Review Evidence
This MR adds no query, so there are no plans.
Migrations
Note
Timings are from CI (db:migrate matrix, goose verbose) against an
empty database, in apply / rollback order per PG version.
Production-scale validation via Database Lab is not yet available. See
Database review evidence
for the matrix rationale and how to read the numbers.
| Migration | PG 16 | PG 17 | PG 18 |
|---|---|---|---|
20261112100000_create_rpm_packages.sql |
OK (1.28s / 239.07ms) | OK (596.17ms / 180.45ms) | OK (829.65ms / 279.29ms) |
20261112100100_create_rpm_versions.sql |
OK (2s / 538.17ms) | OK (887.47ms / 429.14ms) | OK (1.63s / 697.58ms) |
The jobs ran on the merged-result pipeline for 8b7afa6b. Both migration files are unchanged since then.
Migration notes:
- Both migrations take over 1s on PG 16, and
create_rpm_versions.sqlon PG 18 too. No version is over twice the next slowest. Each migration creates a table with 64 partitions, and the tables are new and empty in production too, so this time does not grow with data. - Each foreign-key add in
create_rpm_versions.sqltakesShareRowExclusiveLockon its target and its partitions. Fornamespacesandblob_storage_attachmentsthat blocks writes, and so uploads in every format, for the add's catalog work. Validation reads only the new, empty table, andlock_timeout = '5s'fails a wait instead of queueing uploads behind it.
Closes #1957 (closed)
Edited by Dzmitry (Dima) Meshcharakou