diff options
Diffstat (limited to 'src/ops.rs')
| -rw-r--r-- | src/ops.rs | 49 |
1 files changed, 0 insertions, 49 deletions
@@ -5,7 +5,6 @@ use crate::db::{self, Db}; use crate::error::Result; use crate::time; -/// Default number of versions kept per pkgbase (§11 `retention_versions`). pub const DEFAULT_KEEP: usize = 3; #[derive(Debug, Default, Clone)] @@ -17,17 +16,12 @@ pub struct RetentionReport { pub staging_swept: usize, } -/// Everything a metrics scrape reports, computed in one pass over the database. -/// -/// Kept as a struct rather than a string builder so the HTTP handler, the CLI and -/// the tests read the same numbers from the same source. #[derive(Debug, Default, Clone)] pub struct Metrics { pub builds: Vec<(String, i64)>, pub queue_depth: i64, pub oldest_queued_age_secs: i64, pub pending_review: i64, - /// Age of pending candidates in seconds, already sorted, for bucketing. pub review_ages: Vec<i64>, pub succeeded: i64, pub failed: i64, @@ -49,9 +43,6 @@ pub struct Metrics { } impl Metrics { - /// Share of recorded builds that published. Reported as 1.0 when nothing has - /// run yet: an alert rule reading 0% success on an empty system pages someone - /// for no reason. pub fn build_success_rate(&self) -> f64 { match self.succeeded + self.failed { 0 => 1.0, @@ -59,9 +50,6 @@ impl Metrics { } } - /// Render in Prometheus text exposition format. Every family is declared with - /// `# HELP` and `# TYPE`, because a scrape that fails validation drops the - /// whole payload. pub fn to_prometheus(&self) -> String { let mut o = String::new(); @@ -79,7 +67,6 @@ impl Metrics { o.push_str(&header("aurbuild_pending_review_candidates", "Reviews waiting on a human — the review debt.")); o.push_str(&format!("aurbuild_pending_review_candidates {}\n", self.pending_review)); - // Not how many reviews are pending, but how stale the pending ones are. o.push_str("# HELP aurbuild_pending_review_age_seconds Histogram of how long pending reviews have waited.\n# TYPE aurbuild_pending_review_age_seconds histogram\n"); for le in [3600i64, 21600, 86400, 259200, 604800] { let n = self.review_ages.iter().filter(|a| **a <= le).count(); @@ -152,7 +139,6 @@ impl Metrics { } } -/// Compute every metric from live state. pub fn metrics(cfg: &Config, db: &Db) -> Result<Metrics> { let mut m = Metrics::default(); let now = time::now(); @@ -195,7 +181,6 @@ pub fn metrics(cfg: &Config, db: &Db) -> Result<Metrics> { Ok(m) } -/// A Prometheus family header. fn header(name: &str, help: &str) -> String { format!("# HELP {name} {help}\n# TYPE {name} gauge\n") } @@ -204,7 +189,6 @@ fn file_len(p: &Path) -> u64 { std::fs::metadata(p).map(|m| m.len()).unwrap_or(0) } -/// `(dir count, total bytes)` under a directory, tolerating concurrent removal. fn staging_usage(root: &Path) -> (usize, u64) { let mut dirs = 0; let mut bytes = 0; @@ -232,9 +216,6 @@ fn dir_bytes(path: &Path) -> u64 { total } -/// Which releases of a pkgbase keep their files, and which lose them. -/// -/// The rule is "newest N, plus anything that would be a lie to evict". pub fn plan_retention(db: &Db, keep: usize) -> Result<(Vec<i64>, Vec<EvictPlan>)> { let keep = keep.max(1); let pkgbases = db::pkgbase_release_pointers(db)?; @@ -243,7 +224,6 @@ pub fn plan_retention(db: &Db, keep: usize) -> Result<(Vec<i64>, Vec<EvictPlan>) let mut evict = Vec::new(); for (pb_id, accepted) in pkgbases { let releases = db::published_release_ids(db, pb_id)?; - // Still in the index? Then it is being served, whatever its age. let serving = db::serving_release_ids(db, pb_id)?; let mut keep_set: std::collections::BTreeSet<i64> = serving.iter().cloned().collect(); @@ -269,16 +249,10 @@ pub struct EvictPlan { pub release_id: i64, } -/// Run retention: evict files for releases beyond the keep window, then sweep -/// abandoned staging directories. -/// -/// Files are only removed when no *retained* release still references them: the store -/// is content-addressed. pub fn retention(cfg: &Config, db: &Db, keep: Option<usize>) -> Result<RetentionReport> { let keep = keep.unwrap_or_else(|| db::setting_i64(db, "retention_versions", DEFAULT_KEEP as i64) as usize); let (kept, evict) = plan_retention(db, keep)?; - // Everything still held by a kept release, so we do not evict a shared file. let mut retained_files: std::collections::BTreeSet<PathBuf> = std::collections::BTreeSet::new(); for id in &kept { for f in release_files(cfg, db, *id)? { @@ -297,7 +271,6 @@ pub fn retention(cfg: &Config, db: &Db, keep: Option<usize>) -> Result<Retention } if let Ok(m) = std::fs::metadata(f) { freed += m.len(); - // A missing file is the state we are trying to reach, not an error. let _ = std::fs::remove_file(f); removed += 1; } @@ -334,15 +307,8 @@ pub fn retention(cfg: &Config, db: &Db, keep: Option<usize>) -> Result<Retention Ok(report) } -/// Grace period before an abandoned staging dir is swept. Anything younger could -/// belong to a build that is still running right now. pub const STAGING_GRACE_SECS: i64 = 3600; -/// The files a release holds on disk: package, signature, build log, and the cached -/// sources it was built from. -/// -/// Returned as a unit because that is how they must be treated: keeping one and -/// dropping the others is how a store ends up full of orphans. pub fn release_files(cfg: &Config, db: &Db, release_id: i64) -> Result<Vec<PathBuf>> { let mut out = Vec::new(); for (path, sig, log) in db::release_artifact_paths(db, release_id)? { @@ -350,8 +316,6 @@ pub fn release_files(cfg: &Config, db: &Db, release_id: i64) -> Result<Vec<PathB out.push(PathBuf::from(p)); } } - // Cached sources, by content digest (§5.1a: these are what make an old - // release rebuildable). let digests = db::release_by_id(db, release_id)? .map(|r| r.source_digests_json) .unwrap_or_else(|| "[]".into()); @@ -365,10 +329,6 @@ pub fn release_files(cfg: &Config, db: &Db, release_id: i64) -> Result<Vec<PathB Ok(out) } -/// Remove staging directories whose build is finished or unknown (§8.2). -/// -/// "Abandoned" is derived, not guessed: a dir is swept when its build row is terminal -/// or absent and the dir is older than the grace period. pub fn sweep_staging(cfg: &Config, db: &Db, grace_secs: i64) -> Result<(usize, u64)> { let root = cfg.staging_dir(); let Ok(entries) = std::fs::read_dir(&root) else { return Ok((0, 0)) }; @@ -385,8 +345,6 @@ pub fn sweep_staging(cfg: &Config, db: &Db, grace_secs: i64) -> Result<(usize, u }; let state = db::builds::get(db, &build_id)?.map(|b| b.state); let abandonable = match &state { - // No build row: staging left over from a crash before the row was - // written. None => true, Some(s) => matches!(s.as_str(), "succeeded" | "failed" | "cancelled"), }; @@ -426,11 +384,6 @@ fn record_run(db: &Db, r: &RetentionReport) -> Result<()> { ) } -/// A consistent snapshot of the database, written to `dest`. -/// -/// `VACUUM INTO` runs on the writer connection so the snapshot cannot interleave with -/// a write, and produces a compacted single file with no WAL. A `cp` of a live WAL -/// database gives a main file and a sidecar log that may not belong to it. pub fn backup(db: &Db, dest: &Path) -> Result<PathBuf> { let dest = dest.to_path_buf(); if dest.exists() { @@ -445,8 +398,6 @@ pub fn backup(db: &Db, dest: &Path) -> Result<PathBuf> { } } db::backup_to(&db.writer, &dest)?; - // The snapshot must be readable on its own: if it does not open and report - // the same schema version, the backup is a file, not a backup. let version = db::schema_version(&dest) .map_err(|e| crate::error::Error::db(format!("backup unreadable: {e}")))?; if version <= 0 { |
