summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/db/builds/mod.rs27
-rw-r--r--src/db/builds/steps.rs45
-rw-r--r--src/db/invariants.rs30
-rw-r--r--src/db/migrations.rs2
-rw-r--r--src/db/mod.rs67
-rw-r--r--src/db/model/mod.rs19
-rw-r--r--src/db/model/state.rs12
-rw-r--r--src/db/notices.rs18
-rw-r--r--src/db/packages.rs12
-rw-r--r--src/db/pkgbases.rs20
-rw-r--r--src/db/publish_writes.rs2
-rw-r--r--src/db/retention.rs2
-rw-r--r--src/db/staleness.rs11
-rw-r--r--tests/architecture-budget.json24
-rwxr-xr-xtools/arch-census.py8
15 files changed, 62 insertions, 237 deletions
diff --git a/src/db/builds/mod.rs b/src/db/builds/mod.rs
index 2e116bb..2035cfd 100644
--- a/src/db/builds/mod.rs
+++ b/src/db/builds/mod.rs
@@ -286,27 +286,10 @@ pub fn cancel_requested(db: &Db, id: &str) -> Result<bool> {
// legal moves.
mod steps;
+
pub use steps::{
- StepRow,
- begin_step,
- blocked_builds,
- cancel_superseded,
- claim_batch,
- current_state,
- finish_step,
- in_flight,
- queue_depth,
- requeue_transient,
- retry,
- set_blocked_on,
- set_candidate,
- set_kind,
- set_pkgbase,
- set_profile,
- set_release,
- set_release_in,
- set_world,
- step_status,
- steps,
- touch,
+ begin_step, blocked_builds, cancel_superseded, claim_batch,
+ finish_step, in_flight, queue_depth, requeue_transient,
+ retry, set_blocked_on, set_release_in, set_world,
+ step_status, steps, touch,
};
diff --git a/src/db/builds/steps.rs b/src/db/builds/steps.rs
index 64d57c7..01d7c40 100644
--- a/src/db/builds/steps.rs
+++ b/src/db/builds/steps.rs
@@ -1,4 +1,4 @@
-use rusqlite::{params, Connection, OptionalExtension};
+use rusqlite::{params, OptionalExtension};
use super::transition_in_tx;
use crate::db::{BuildState, Db, StepState};
@@ -163,10 +163,6 @@ pub fn set_release_in(tx: &rusqlite::Transaction<'_>, id: &str, release_id: i64)
Ok(())
}
-pub fn set_release(db: &Db, id: &str, release_id: i64) -> Result<()> {
- let id = id.to_string();
- db.writer.tx(move |tx| set_release_in(tx, &id, release_id))
-}
pub fn set_world(db: &Db, id: &str, world_id: i64) -> Result<()> {
let id = id.to_string();
@@ -176,37 +172,9 @@ pub fn set_world(db: &Db, id: &str, world_id: i64) -> Result<()> {
})
}
-pub fn set_candidate(db: &Db, id: &str, candidate_id: i64) -> Result<()> {
- let id = id.to_string();
- db.writer.tx(move |tx| {
- tx.execute("UPDATE build SET candidate_id=?1 WHERE id=?2", params![candidate_id, id])?;
- Ok(())
- })
-}
-pub fn set_pkgbase(db: &Db, id: &str, pkgbase_id: i64) -> Result<()> {
- let id = id.to_string();
- db.writer.tx(move |tx| {
- tx.execute("UPDATE build SET pkgbase_id=?1 WHERE id=?2", params![pkgbase_id, id])?;
- Ok(())
- })
-}
-pub fn set_profile(db: &Db, id: &str, profile: &str) -> Result<()> {
- let (id, p) = (id.to_string(), profile.to_string());
- db.writer.tx(move |tx| {
- tx.execute("UPDATE build SET build_profile=?1 WHERE id=?2", params![p, id])?;
- Ok(())
- })
-}
-pub fn set_kind(db: &Db, id: &str, kind: &str) -> Result<()> {
- let (id, k) = (id.to_string(), kind.to_string());
- db.writer.tx(move |tx| {
- tx.execute("UPDATE build SET kind=?1 WHERE id=?2", params![k, id])?;
- Ok(())
- })
-}
pub fn set_blocked_on(db: &Db, id: &str, blocked_on: &[String]) -> Result<()> {
let id = id.to_string();
@@ -217,17 +185,6 @@ pub fn set_blocked_on(db: &Db, id: &str, blocked_on: &[String]) -> Result<()> {
})
}
-pub fn current_state(c: &Connection, id: &str) -> Result<Option<BuildState>> {
- let s: Option<String> = c
- .query_row("SELECT state FROM build WHERE id=?1", params![id], |r| r.get(0))
- .optional()?;
- match s {
- None => Ok(None),
- Some(text) => BuildState::parse(&text)
- .map(Some)
- .ok_or_else(|| Error::invalid(format!("build {id} has a state outside the state machine: {text:?}"))),
- }
-}
pub fn claim_batch(db: &Db, owner: &str, limit: usize, lease_secs: i64) -> Result<Vec<String>> {
if limit == 0 {
diff --git a/src/db/invariants.rs b/src/db/invariants.rs
index 398590b..9853003 100644
--- a/src/db/invariants.rs
+++ b/src/db/invariants.rs
@@ -21,36 +21,6 @@ pub fn unapproved_index_entries(db: &Db) -> Result<Vec<String>> {
})
}
-pub fn index_pkgbase_drift(db: &Db) -> Result<(Vec<String>, Vec<String>)> {
- db.read(|c| {
- let mut orphans = Vec::new();
- let mut stmt = c.prepare(
- "SELECT DISTINCT b.name FROM package p
- JOIN release r ON r.id = p.release_id
- JOIN pkgbase b ON b.id = r.pkgbase_id
- WHERE p.state='in_index'
- AND r.id NOT IN (SELECT current_accepted_release_id FROM pkgbase
- WHERE current_accepted_release_id IS NOT NULL)",
- )?;
- let rows = stmt.query_map([], |r| r.get::<_, String>(0))?;
- for r in rows {
- orphans.push(r?);
- }
- let mut missing = Vec::new();
- let mut stmt = c.prepare(
- "SELECT b.name FROM pkgbase b
- JOIN subscription s ON s.pkgbase = b.name AND s.state IN ('active','orphaned')
- WHERE b.current_accepted_release_id IS NOT NULL
- AND NOT EXISTS (SELECT 1 FROM package p WHERE p.release_id = b.current_accepted_release_id
- AND p.state='in_index')",
- )?;
- let rows = stmt.query_map([], |r| r.get::<_, String>(0))?;
- for r in rows {
- missing.push(r?);
- }
- Ok((orphans, missing))
- })
-}
#[derive(Debug, Clone)]
pub struct Unbuilt {
diff --git a/src/db/migrations.rs b/src/db/migrations.rs
index 0a1ca27..cb01765 100644
--- a/src/db/migrations.rs
+++ b/src/db/migrations.rs
@@ -334,7 +334,7 @@ pub static MIGRATIONS: &[Migration] = &[
Migration { version: 8, name: "retention", sql: M_0008_RETENTION },
];
-pub const DEFAULT_SETTINGS: &[(&str, &str)] = &[
+pub(crate) const DEFAULT_SETTINGS: &[(&str, &str)] = &[
("max_concurrent_builds", "1"),
("build_timeout", "5400"),
("poll_interval", "86400"),
diff --git a/src/db/mod.rs b/src/db/mod.rs
index d4befcc..13d7d9d 100644
--- a/src/db/mod.rs
+++ b/src/db/mod.rs
@@ -25,32 +25,32 @@ mod subscriptions;
mod world;
pub use migrations::MIGRATIONS;
+pub(crate) use model::StateEnum;
+pub(crate) use model::json_or;
pub use model::{
- BUILD_STEPS, BuildState, CandidateRow, CandidateState, Identity, Recipe, ReleaseRow,
- ReleaseState, SourceDigest, SourceEntry, StageBCacheRow, StateEnum, StepState,
- SubscriptionState, UpstreamPin, WorldMember, candidate_kind, json_or, notice_kind,
+ BUILD_STEPS, BuildState, CandidateRow, CandidateState,
+ Identity, Recipe, ReleaseRow, ReleaseState,
+ SourceDigest, SourceEntry, StageBCacheRow, StepState,
+ SubscriptionState, UpstreamPin, WorldMember, candidate_kind,
+ notice_kind,
};
-pub use audit::{AuditEntry, AuditRow, audit, audit_in, audit_system, list_audit};
-pub use invariants::{Unbuilt, approved_but_unbuilt, index_pkgbase_drift, unapproved_index_entries};
+pub use audit::{AuditEntry, audit, audit_in, audit_system, list_audit};
+pub use invariants::{approved_but_unbuilt, unapproved_index_entries};
pub use metrics::{
artifact_bytes_served, build_state_counts, count_index_packages, count_pending_reviews,
- count_published_releases, count_subscriptions, count_unacknowledged_notices,
- last_gc_age_secs, last_poll_age_secs, oldest_queued_age_secs, pending_review_ages_secs,
+ count_published_releases, count_subscriptions, count_unacknowledged_notices, last_gc_age_secs,
+ last_poll_age_secs, oldest_queued_age_secs, pending_review_ages_secs,
};
-pub use notices::{NoticeRow, acknowledge_notice, list_notices, put_notice, put_notice_once};
+pub use notices::{acknowledge_notice, list_notices, put_notice_once};
pub use packages::{
- PackageRow, accepted_recipe, builds_for_pkgbase, index_artifact, index_packages,
- index_version, is_ours, our_package_names,
-};
-pub use pkgbases::{
- Pkgbase, cas_accepted_release, get_pkgbase, get_pkgbase_by_id, list_pkgbases, set_aur_head,
- set_unpinable,
+ accepted_recipe, builds_for_pkgbase, index_artifact, index_packages,
+ index_version, our_package_names,
};
+pub use pkgbases::{Pkgbase, cas_accepted_release, get_pkgbase, get_pkgbase_by_id, set_aur_head};
pub use publish_writes::{
- NewRelease, accepted_pointer_in, artifact_id_by_digest_in, artifact_path,
- cas_accepted_release_in, insert_package_in, insert_release_in, remove_index_packages_in,
- remove_package_by_name_in,
+ NewRelease, accepted_pointer_in, artifact_path, cas_accepted_release_in,
+ insert_package_in, insert_release_in, remove_index_packages_in, remove_package_by_name_in,
};
pub use releases::{
accepted_release, all_published_releases, release_by_id, releases_for_pkgbase,
@@ -58,19 +58,19 @@ pub use releases::{
};
pub use repos::{ensure_repo, repo_id};
pub use retention::{
- ArtifactPaths, mark_release_purged, pkgbase_release_pointers, published_release_ids,
- record_gc_run, release_artifact_paths, serving_release_ids,
+ mark_release_purged, pkgbase_release_pointers, published_release_ids, record_gc_run,
+ release_artifact_paths, serving_release_ids,
};
pub use settings::{all_settings, set_setting, setting, setting_i64};
pub use snapshots::{SnapshotRow, put_snapshot, snapshot_by_commit, snapshot_by_id};
pub use stage_b::{stage_b_cache_get, stage_b_cache_put, stage_b_recent};
pub use staleness::{
- NewArtifact, approval_note, candidate_snapshot_id, index_recipes, insert_artifact_in,
- published_world_members, put_source_cache, served_vs_offered_pkgvers, source_cache_path,
- subscription_poll_interval,
+ NewArtifact, approval_note, candidate_snapshot_id, index_recipes,
+ insert_artifact_in, published_world_members, put_source_cache, served_vs_offered_pkgvers,
+ source_cache_path,
};
pub use subscriptions::{
- Subscription, due_subscriptions, get_subscription, list_subscriptions, note_check,
+ due_subscriptions, get_subscription, list_subscriptions, note_check,
set_subscription_state, subscribe,
};
pub use world::{put_world_snapshot, world_members};
@@ -88,7 +88,6 @@ pub(crate) fn state_col<T: StateEnum>(col: usize, text: &str) -> rusqlite::Resul
})
}
-
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
@@ -197,7 +196,7 @@ impl Writer {
&self.path
}
- pub fn is_alive(&self) -> bool {
+ fn is_alive(&self) -> bool {
self.alive.load(Ordering::SeqCst)
}
@@ -256,16 +255,9 @@ impl Writer {
{
self.tx(f)
}
-
- pub fn call_for_tests<T>(&self, f: impl FnOnce(&mut Connection) -> Result<T> + Send + 'static) -> Result<T>
- where
- T: Send + 'static,
- {
- self.call(f)
- }
}
-pub struct Readers {
+pub(crate) struct Readers {
path: PathBuf,
}
@@ -300,7 +292,7 @@ impl Readers {
#[derive(Clone)]
pub struct Db {
pub writer: Arc<Writer>,
- pub readers: Arc<Readers>,
+ pub(crate) readers: Arc<Readers>,
}
impl Db {
@@ -338,10 +330,3 @@ pub fn schema_version(path: &Path) -> Result<i64> {
.map_err(|e| Error::db(format!("{} has no schema version: {e}", path.display())))
}
-pub fn wal_stats(db: &Db) -> (u64, u64) {
- let db_file = std::fs::metadata(db.writer.path()).map(|m| m.len()).unwrap_or(0);
- let mut wal = db.writer.path().as_os_str().to_os_string();
- wal.push("-wal");
- let wal_file = std::fs::metadata(&wal).map(|m| m.len()).unwrap_or(0);
- (db_file, wal_file)
-}
diff --git a/src/db/model/mod.rs b/src/db/model/mod.rs
index 741f1f4..acfcda5 100644
--- a/src/db/model/mod.rs
+++ b/src/db/model/mod.rs
@@ -193,7 +193,7 @@ impl CandidateRow {
}
}
-pub fn json_or<T: serde::de::DeserializeOwned>(s: &str, fallback: T) -> T {
+pub(crate) fn json_or<T: serde::de::DeserializeOwned>(s: &str, fallback: T) -> T {
serde_json::from_str(s).unwrap_or(fallback)
}
@@ -202,16 +202,7 @@ pub fn json_or<T: serde::de::DeserializeOwned>(s: &str, fallback: T) -> T {
mod build_state;
mod state;
-pub use build_state::{
- BUILD_STEPS,
- BuildState,
- StepState,
-};
-pub use state::{
- CandidateState,
- ReleaseState,
- StateEnum,
- SubscriptionState,
- candidate_kind,
- notice_kind,
-};
+pub(crate) use state::StateEnum;
+
+pub use build_state::{BUILD_STEPS, BuildState, StepState};
+pub use state::{CandidateState, ReleaseState, SubscriptionState, candidate_kind, notice_kind};
diff --git a/src/db/model/state.rs b/src/db/model/state.rs
index 4882428..777840f 100644
--- a/src/db/model/state.rs
+++ b/src/db/model/state.rs
@@ -53,7 +53,7 @@ impl CandidateState {
}
}
- pub fn predecessors(to: CandidateState) -> Vec<&'static str> {
+ pub(crate) fn predecessors(to: CandidateState) -> Vec<&'static str> {
CandidateState::ALL
.iter()
.filter(|from| from.can_transition(to))
@@ -118,10 +118,9 @@ impl std::fmt::Display for ReleaseState {
}
}
-pub trait StateEnum: Copy + Sized {
+pub(crate) trait StateEnum: Copy + Sized {
const KIND: &'static str;
fn parse(text: &str) -> Option<Self>;
- fn as_str(&self) -> &'static str;
}
macro_rules! impl_state_enum {
@@ -131,9 +130,6 @@ macro_rules! impl_state_enum {
fn parse(text: &str) -> Option<Self> {
<$t>::parse(text)
}
- fn as_str(&self) -> &'static str {
- <$t>::as_str(self)
- }
}
};
}
@@ -147,12 +143,8 @@ impl_state_enum!(SubscriptionState, "subscription");
pub mod notice_kind {
pub const PIN_DRIFT: &str = "pin_drift";
pub const RECIPE_DRIFT: &str = "recipe_drift";
- pub const DIGEST_DRIFT: &str = "digest_drift";
pub const INTEGRITY_ALERT: &str = "integrity_alert";
- pub const UNPINABLE_PKGVER: &str = "unpinable_pkgver";
- pub const ORPHANED: &str = "orphaned";
pub const DELETED: &str = "deleted";
- pub const RENAMED: &str = "renamed";
pub const DOWNGRADE: &str = "downgrade";
}
diff --git a/src/db/notices.rs b/src/db/notices.rs
index 4e0e4f2..36263a4 100644
--- a/src/db/notices.rs
+++ b/src/db/notices.rs
@@ -6,24 +6,6 @@ use crate::time;
// ----------------------------------------------------------------- notice --
-pub fn put_notice(
- writer: &Writer,
- pkgbase_id: i64,
- kind: &str,
- severity: &str,
- detail: serde_json::Value,
-) -> Result<i64> {
- let (k, s, d) = (kind.to_string(), severity.to_string(), detail.to_string());
- let at = time::now();
- writer.tx(move |tx| {
- tx.execute(
- "INSERT INTO notice (pkgbase_id, kind, severity, detail_json, created_at)
- VALUES (?1,?2,?3,?4,?5)",
- params![pkgbase_id, k, s, d, at],
- )?;
- Ok(tx.last_insert_rowid())
- })
-}
pub fn put_notice_once(
writer: &Writer,
diff --git a/src/db/packages.rs b/src/db/packages.rs
index 6708c99..0a302b0 100644
--- a/src/db/packages.rs
+++ b/src/db/packages.rs
@@ -78,18 +78,6 @@ pub fn index_artifact(db: &Db, name: &str) -> Result<Option<(String, String)>> {
})
}
-pub fn is_ours(db: &Db, name: &str) -> Result<bool> {
- db.read(|c| {
- c.query_row(
- "SELECT 1 FROM package WHERE name=?1 AND state='in_index' LIMIT 1",
- params![name],
- |r| r.get::<_, i64>(0),
- )
- .optional()
- .map(|o| o.is_some())
- .map_err(Into::into)
- })
-}
pub fn our_package_names(db: &Db) -> Result<std::collections::BTreeSet<String>> {
db.read(|c| {
diff --git a/src/db/pkgbases.rs b/src/db/pkgbases.rs
index a652093..bf1fa7b 100644
--- a/src/db/pkgbases.rs
+++ b/src/db/pkgbases.rs
@@ -57,17 +57,6 @@ pub fn get_pkgbase_by_id(db: &Db, id: i64) -> Result<Option<Pkgbase>> {
})
}
-pub fn list_pkgbases(db: &Db) -> Result<Vec<Pkgbase>> {
- db.read(|c| {
- let mut stmt = c.prepare(&format!("SELECT {PKGBASE_COLS} FROM pkgbase ORDER BY name"))?;
- let rows = stmt.query_map([], row_to_pkgbase)?;
- let mut out = Vec::new();
- for r in rows {
- out.push(r?);
- }
- Ok(out)
- })
-}
pub fn set_aur_head(writer: &Writer, pkgbase_id: i64, head: &str, mirror: &str) -> Result<()> {
let (h, m) = (head.to_string(), mirror.to_string());
@@ -80,15 +69,6 @@ pub fn set_aur_head(writer: &Writer, pkgbase_id: i64, head: &str, mirror: &str)
})
}
-pub fn set_unpinable(writer: &Writer, pkgbase_id: i64, unpinable: bool) -> Result<()> {
- writer.tx(move |tx| {
- tx.execute(
- "UPDATE pkgbase SET unpinable=?1 WHERE id=?2",
- params![unpinable as i64, pkgbase_id],
- )?;
- Ok(())
- })
-}
pub fn cas_accepted_release(
writer: &Writer,
diff --git a/src/db/publish_writes.rs b/src/db/publish_writes.rs
index 27ab4f6..e5ce73f 100644
--- a/src/db/publish_writes.rs
+++ b/src/db/publish_writes.rs
@@ -12,7 +12,7 @@ pub fn artifact_path(db: &Db, id: i64) -> Result<Option<String>> {
})
}
-pub fn artifact_id_by_digest_in(tx: &rusqlite::Transaction<'_>, digest: &str) -> Result<Option<i64>> {
+fn artifact_id_by_digest_in(tx: &rusqlite::Transaction<'_>, digest: &str) -> Result<Option<i64>> {
Ok(tx
.query_row("SELECT id FROM artifact WHERE digest=?1", params![digest], |r| r.get::<_, i64>(0))
.optional()?)
diff --git a/src/db/retention.rs b/src/db/retention.rs
index ca468e1..3e6f22f 100644
--- a/src/db/retention.rs
+++ b/src/db/retention.rs
@@ -45,7 +45,7 @@ pub fn serving_release_ids(db: &Db, pkgbase_id: i64) -> Result<Vec<i64>> {
})
}
-pub type ArtifactPaths = (Option<String>, Option<String>, Option<String>);
+type ArtifactPaths = (Option<String>, Option<String>, Option<String>);
pub fn release_artifact_paths(db: &Db, release_id: i64) -> Result<Vec<ArtifactPaths>> {
db.read(|c| {
diff --git a/src/db/staleness.rs b/src/db/staleness.rs
index 8987e85..59fccee 100644
--- a/src/db/staleness.rs
+++ b/src/db/staleness.rs
@@ -77,17 +77,6 @@ pub fn candidate_snapshot_id(db: &Db, candidate_id: i64) -> Result<Option<i64>>
})
}
-pub fn subscription_poll_interval(db: &Db, pkgbase: &str) -> Result<Option<i64>> {
- db.read(|c| {
- Ok(c.query_row(
- "SELECT poll_interval_secs FROM subscription WHERE pkgbase=?1",
- params![pkgbase],
- |r| r.get::<_, Option<i64>>(0),
- )
- .optional()?
- .flatten())
- })
-}
pub fn put_source_cache(writer: &Writer, url: &str, digest: &str, size: u64, path: &str) -> Result<()> {
let (u, d, p) = (url.to_string(), digest.to_string(), path.to_string());
diff --git a/tests/architecture-budget.json b/tests/architecture-budget.json
index f717923..969b945 100644
--- a/tests/architecture-budget.json
+++ b/tests/architecture-budget.json
@@ -89,14 +89,14 @@
"test": 5
},
"db": {
- "dead": 49,
- "deadonly": 36,
+ "dead": 24,
+ "deadonly": 11,
"glob": 0,
- "largest": 568,
- "largest_file": "src/db/builds.rs",
- "lines": 3948,
- "priv": 5,
- "pub": 226,
+ "largest": 364,
+ "largest_file": "src/db/candidates.rs",
+ "lines": 3731,
+ "priv": 10,
+ "pub": 201,
"test": 13
},
"error": {
@@ -299,15 +299,15 @@
}
},
"totals": {
- "dead": 219,
- "deadonly": 146,
+ "dead": 194,
+ "deadonly": 121,
"edges": 80,
"glob": 2,
"largest": 603,
"largest_file": "src/shims/mod.rs",
- "lines": 13810,
- "priv": 42,
- "pub": 585,
+ "lines": 13593,
+ "priv": 47,
+ "pub": 560,
"test": 73
}
}
diff --git a/tools/arch-census.py b/tools/arch-census.py
index e6a8300..24f2c5f 100755
--- a/tools/arch-census.py
+++ b/tools/arch-census.py
@@ -10,6 +10,14 @@ the crate. `tests/` counts as an outside reader on purpose — the integration
tests are separate crates, so a name only they use is genuinely `pub`, and the
honest way to say that is to count it rather than pretend it is private.
+What `dead` means precisely is *the name is never written outside the module*.
+That is a lead, not a verdict. A row type returned by a public query is part of
+the interface even though no caller ever writes its name — they bind it with
+`let` and call methods on it — so the way to find out which flagged items are
+real is to privatize them and let the compiler answer: it rejects the ones that
+are load-bearing and says nothing about the rest. Whatever survives that is
+budgeted rather than zeroed, and the budget is where the reason lives.
+
Reported per module:
pub items declared `pub` (fn, struct, enum, trait, const, static, type)
dead of those, ones no file outside the module names — including tests/