diff options
| author | aur-build <aur-build@localhost> | 2026-11-18 10:02:04 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-18 10:02:04 +0000 |
| commit | bc63622a1a91f6e1036eb8e6824c04f922e2654e (patch) | |
| tree | 6ca0a3d136ac5c5ba3d8abe89a2bce4b8531803c /src/db/migrations.rs | |
| parent | 5809493be2f6e47e3bbfc8a645ea0d82d5aedd82 (diff) | |
| download | aur-build-bc63622a1a91f6e1036eb8e6824c04f922e2654e.tar.gz aur-build-bc63622a1a91f6e1036eb8e6824c04f922e2654e.zip | |
ops: retention that never lies about what is on disk, metrics that cannot drift, and a backup that restores
Three §15 features, each with a failure mode worth designing against.
**Retention** evicts the files of releases beyond the keep window and never
deletes a row. The artifact keeps its digest, size and provenance and gains a
purged_at, so the record says 'these bytes existed and were dropped at T'
instead of continuing to claim a file that is no longer there. A package, its
signature, its build log and its cached sources are evicted as one unit — a
package whose log is gone but whose bytes remain is the worst outcome: full
price, no explanation. Shared content-addressed files are reference-checked
against every *retained* release first, because two releases built from the same
source share one cached archive and aging one out must not corrupt the other.
The currently accepted release and anything still backing an in_index package are
kept regardless of how far down the list they sit: deleting the bytes the index
is pointing at is the one thing retention must never do.
**Staging sweep** derives 'abandoned' rather than guessing it: the dir's build is
terminal, or has no build row at all, and the dir is older than a grace period.
A dir whose build is running is left alone however old it looks, because a long
build is not an abandoned one.
**Metrics** are computed from live state on every scrape. There are no counters
incremented at event sites, because a counter maintained by every code path is a
counter that quietly drifts the first time a path is added; a query cannot
drift. Includes queue depth, the review-debt age histogram (not just how many
reviews are pending but how stale they are), build success rate, WAL size,
stale counts by reason and staging usage. A fresh install reports success rate
1.0 rather than NaN or 0%, so an empty system does not page anyone. Served at
GET /metrics and by 'aur-build metrics'.
**Backup** uses VACUUM INTO on the writer connection, so it cannot interleave
with a write, and refuses to overwrite an existing file — a backup that silently
replaces last week's backup is a way of losing the only copy on the day you need
it. The snapshot is then reopened and checked for schema version and approval
rows: if it does not open on its own it is a file, not a backup.
New CLI: metrics, gc [--keep N] [--dry-run], backup <path>.
tests/ops.rs: 9 tests. 170 tests pass, clippy clean.
Diffstat (limited to 'src/db/migrations.rs')
| -rw-r--r-- | src/db/migrations.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/db/migrations.rs b/src/db/migrations.rs index bb8974f..9e60132 100644 --- a/src/db/migrations.rs +++ b/src/db/migrations.rs @@ -319,6 +319,35 @@ CREATE TABLE stage_b_cache ( CREATE INDEX stage_b_cache_by_pkgbase ON stage_b_cache (pkgbase_id, resolved_at); "#; +/// Retention (§15, open question 21). The rows are never compacted — the whole +/// point of the schema is that "which bytes produced this installed package" +/// stays answerable — but the bytes on disk cannot be kept forever. So eviction +/// is recorded rather than implied: the artifact row keeps its digest, size and +/// provenance and gains a `purged_at`, which says "these bytes existed, and were +/// dropped from the store at T" instead of silently pretending they are still +/// there. A `cp` of the store and a database that disagrees about what is on disk +/// is the failure mode this avoids. +const M_0008_RETENTION: &str = r#" +ALTER TABLE artifact ADD COLUMN purged_at TEXT; + +-- Set when a release's files have been evicted; NULL means the bytes are held. +ALTER TABLE release ADD COLUMN purged_at TEXT; + +-- Staging is disposable (§8.2), but "disposable" needs a definition: a dir is +-- swept when its build is terminal or unknown and the dir is older than the +-- grace period. Recording the sweep keeps a crashed-then-swept build auditable. +CREATE TABLE IF NOT EXISTS gc_run ( + id INTEGER PRIMARY KEY, + ran_at TEXT NOT NULL, + releases_kept INTEGER NOT NULL, + releases_evicted INTEGER NOT NULL, + files_removed INTEGER NOT NULL, + bytes_freed INTEGER NOT NULL, + staging_swept INTEGER NOT NULL, + detail_json TEXT NOT NULL DEFAULT '{}' +); +"#; + pub static MIGRATIONS: &[Migration] = &[ Migration { version: 1, name: "core", sql: M_0001_CORE }, Migration { version: 2, name: "build", sql: M_0002_BUILD }, @@ -327,6 +356,7 @@ pub static MIGRATIONS: &[Migration] = &[ Migration { version: 5, name: "artifact-build", sql: M_0005_ARTIFACT_BUILD }, Migration { version: 6, name: "approval-immutable", sql: M_0006_APPROVAL_IMMUTABLE }, Migration { version: 7, name: "stage-b-cache", sql: M_0007_STAGE_B_CACHE }, + Migration { version: 8, name: "retention", sql: M_0008_RETENTION }, ]; /// Default settings seeded into `settings` (DESIGN.md §11). |
