Skip to content

Commit 6fa2f10

Browse files
refactor(db): move deletion store ownership
Signed-off-by: tornquist <[email protected]>
1 parent fcb55ab commit 6fa2f10

3 files changed

Lines changed: 51 additions & 15 deletions

File tree

‎crates/buzz-db/src/deletion.rs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use sqlx::{AssertSqlSafe, PgConnection, PgPool, Postgres, Row, Transaction};
1717
use uuid::Uuid;
1818

1919
use crate::error::{DbError, Result};
20+
use crate::Db;
2021

2122
/// Default PostgreSQL lease duration for one claimed deletion request.
2223
pub const DEFAULT_LEASE_DURATION: Duration = Duration::from_secs(60);
@@ -627,6 +628,23 @@ pub struct DeletionStore {
627628
pool: PgPool,
628629
}
629630

631+
impl Db {
632+
/// Validate the minimum deletion fence catalog required by serving paths.
633+
pub async fn validate_deletion_serving_catalog(&self) -> Result<()> {
634+
self.deletion_store().validate_serving_catalog().await
635+
}
636+
637+
/// Validate the exact live community-deletion tenant catalog for destruction.
638+
pub async fn validate_deletion_catalog(&self) -> Result<()> {
639+
self.deletion_store().validate_catalog().await
640+
}
641+
642+
/// Return the shared durable whole-community deletion adapter.
643+
pub fn deletion_store(&self) -> DeletionStore {
644+
DeletionStore::new(self.pool.clone())
645+
}
646+
}
647+
630648
impl DeletionStore {
631649
/// Construct from the writer pool used by [`crate::Db`].
632650
pub(crate) fn new(pool: PgPool) -> Self {

‎crates/buzz-db/src/lib.rs‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -954,16 +954,6 @@ impl Db {
954954
sqlx::query("SELECT 1").execute(&self.pool).await.is_ok()
955955
}
956956

957-
/// Validate the minimum deletion fence catalog required by serving paths.
958-
pub async fn validate_deletion_serving_catalog(&self) -> Result<()> {
959-
self.deletion_store().validate_serving_catalog().await
960-
}
961-
962-
/// Validate the exact live community-deletion tenant catalog for destruction.
963-
pub async fn validate_deletion_catalog(&self) -> Result<()> {
964-
self.deletion_store().validate_catalog().await
965-
}
966-
967957
/// Returns pool utilisation stats for metrics emission.
968958
///
969959
/// `size` — total connections (idle + active)
@@ -993,11 +983,6 @@ impl Db {
993983
})
994984
}
995985

996-
/// Return the shared durable whole-community deletion adapter.
997-
pub fn deletion_store(&self) -> deletion::DeletionStore {
998-
deletion::DeletionStore::new(self.pool.clone())
999-
}
1000-
1001986
/// Begin a database transaction for atomic multi-statement operations.
1002987
///
1003988
/// Returns a `'static` transaction because `PgPool` is `Arc`-backed internally.

‎crates/buzz-db/tests/store_ownership.rs‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,3 +1183,36 @@ fn maintenance_store_facades_have_single_ownership() {
11831183
);
11841184
assert_eq!(count(event, "name = \"backfill_d_tags\""), 1);
11851185
}
1186+
1187+
#[test]
1188+
fn deletion_store_facades_have_single_ownership() {
1189+
let root = include_str!("../src/lib.rs");
1190+
let store = include_str!("../src/deletion.rs");
1191+
1192+
for method in [
1193+
"validate_deletion_serving_catalog",
1194+
"validate_deletion_catalog",
1195+
] {
1196+
let signature = format!("pub async fn {method}(");
1197+
assert_eq!(count(root, &signature), 0, "{method} remains in lib.rs");
1198+
assert_eq!(
1199+
count(store, &signature),
1200+
1,
1201+
"{method} deletion facade is not unique"
1202+
);
1203+
}
1204+
1205+
assert_eq!(count(root, "pub fn deletion_store("), 0);
1206+
assert_eq!(count(store, "pub fn deletion_store("), 1);
1207+
assert_eq!(count(store, "pub struct DeletionStore"), 1);
1208+
1209+
assert_eq!(
1210+
count(root, "pub async fn insert_event_with_serving_write_guard("),
1211+
1,
1212+
"the cross-domain serving-write/event transaction must remain runtime-owned"
1213+
);
1214+
assert_eq!(
1215+
count(store, "pub async fn insert_event_with_serving_write_guard("),
1216+
0
1217+
);
1218+
}

0 commit comments

Comments
 (0)