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_packages and rpm_versions as S38 Data sets them on main. Every row carries rpm_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_versions joins 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, so rpm_versions leaves it with RPM.
  • Downsides: The package-read index is partial, as S38 on main says. 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, packager and the rest) carry no length CHECK: S38 bounds them only through rpm.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 name rpm_versions is still checked. The exemption covers the table, not each site, so until Step 53 a site that already names rpm_versions could 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_versions off the pending list. It leaves with RPM in Step 53 (#2002). pendingformats.Tables reads its tables from Formats, 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 pendingformats doc 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 on main's plan, so one index serves the version reference and the key checks when an RPM repository or a namespace is deleted. With id first, rpm_packages would need one more index, because its live-name index is partial. The reference itself still lists (id, namespace_id, rpm_repository_id), as docs/dev/database.md shows. !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, and TestDeleteUnreferencedAttachmentStmt_EveryClauseCorrelationIsIndexed requires 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 or blob_sha256 refused; 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, every CREATE guarded, and the Down order.
  • internal/datastore: TestRepositoryStore_DeleteFKAssumption_SchemaGuard expects the new rpm_packages to rpm_repositories blocking 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, name dropped from both, architecture dropped from the identity index, the package reference narrowed to (rpm_package_id, namespace_id), the package and repository references made CASCADE, the attachment key dropped, rpm_repository_id made nullable on each table, rpm_package_id, blob_storage_attachment_id and blob_sha256 each made nullable on rpm_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_id and blob_sha256. Taking RPM off pendingformats.Formats empties 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/migrations integration suite, the internal/datastore and internal/usagedata unit tests and TestRepositoryStore_DeleteFKAssumption_SchemaGuard pass on PostgreSQL 16. CI runs every suite on 16, 17 and 18. After the rebase, a fresh scripts/db/dump-structure.sh run matches the committed structure.sql.
  • golangci-lint, untagged and through scripts/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_id in 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_id and packager, 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 takes NO 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_EveryClauseCorrelationIsIndexed requires, 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 with namespace_id and rpm_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.sql on 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.sql takes ShareRowExclusiveLock on its target and its partitions. For namespaces and blob_storage_attachments that blocks writes, and so uploads in every format, for the add's catalog work. Validation reads only the new, empty table, and lock_timeout = '5s' fails a wait instead of queueing uploads behind it.

Closes #1957 (closed)

Edited by Dzmitry (Dima) Meshcharakou

Merge request reports

Loading
Loading