From 38df245d70793df05bb204546d2f276d1f973bfc Mon Sep 17 00:00:00 2001 From: zz_y Date: Wed, 13 May 2026 08:07:56 -0600 Subject: [PATCH] refactor(sketch_db): extract lifecycle/ with eviction service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Post-M2.3 reorg #5 of 8. Creates a new `sketch_db::lifecycle` module and moves `SchemaEvictionService` (and friends) into `lifecycle/eviction.rs`. The sid-level lifecycle FIELDS and methods on `SketchInstanceMetadata` / `SketchStore` stay in `index/` next to the data they gate — only the schedule-driven *service* moves here. `schema/mod.rs` re-exports the eviction types under their legacy path (`sketch_db::schema::SchemaEvictionService`) so existing consumers compile unchanged. Canonical home is now `sketch_db::lifecycle::*`. This is the structural skeleton for the upcoming sub-PRs: - #6 will add `lifecycle::reconcile_from_streaming_config`, reimplementing schema/'s reconcile semantics over the sid catalog. - #7 will then delete `schema/` once the only resident is the thin re-export. 783/783 lib tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../{schema => lifecycle}/eviction.rs | 2 +- .../sketch_db/lifecycle/mod.rs | 27 +++++++++++++++++++ .../src/storage_engines/sketch_db/mod.rs | 1 + .../storage_engines/sketch_db/schema/mod.rs | 7 ++--- 4 files changed, 33 insertions(+), 4 deletions(-) rename data_plane/src/storage_engines/sketch_db/{schema => lifecycle}/eviction.rs (99%) create mode 100644 data_plane/src/storage_engines/sketch_db/lifecycle/mod.rs diff --git a/data_plane/src/storage_engines/sketch_db/schema/eviction.rs b/data_plane/src/storage_engines/sketch_db/lifecycle/eviction.rs similarity index 99% rename from data_plane/src/storage_engines/sketch_db/schema/eviction.rs rename to data_plane/src/storage_engines/sketch_db/lifecycle/eviction.rs index b982be5a..07334a56 100644 --- a/data_plane/src/storage_engines/sketch_db/schema/eviction.rs +++ b/data_plane/src/storage_engines/sketch_db/lifecycle/eviction.rs @@ -54,7 +54,7 @@ use tracing::{info, warn}; use crate::storage_engines::sketch_db::backfill::{BackfillRegistry, BackfillStatus}; use crate::storage_engines::sketch_db::index::SketchStore; -use super::{AggStatus, SchemaRegistry}; +use crate::storage_engines::sketch_db::schema::{AggStatus, SchemaRegistry}; /// Configuration for the eviction loop. Separate from /// `SchemaRegistry`'s `retirement_retention` because the service diff --git a/data_plane/src/storage_engines/sketch_db/lifecycle/mod.rs b/data_plane/src/storage_engines/sketch_db/lifecycle/mod.rs new file mode 100644 index 00000000..45b73c19 --- /dev/null +++ b/data_plane/src/storage_engines/sketch_db/lifecycle/mod.rs @@ -0,0 +1,27 @@ +//! Sid lifecycle — `Active`/`Retired`/`Expired` over per-sid metadata, +//! eviction services, and the ingest barrier. +//! +//! Post-M2.3 reorg #5. The sid-level lifecycle state itself (the +//! `retired_at_ms` / `expires_at_ms` fields on +//! [`crate::storage_engines::sketch_db::index::SketchInstanceMetadata`], +//! plus `force_retire` / `force_expire` / `is_writable` / `list_by_status` +//! / `remove_instance` / `remove_instances_for_agg_config` methods on +//! `SketchStore`) lives in `index/` next to the data it gates. This +//! module owns the **services** that drive lifecycle transitions: +//! +//! - [`eviction::SchemaEvictionService`] — background tokio task that +//! sweeps `Expired` agg-configs (from the `SchemaRegistry`) and +//! removes their residual sids from `SketchStore` via +//! `remove_instances_for_agg_config`. Schedule-driven half of the +//! "controller dropped a config → its sids go away" flow. +//! +//! Future content: +//! - `reconcile_from_streaming_config` — once schema/ is retired, the +//! "controller-reconcile-driven bulk-retire" entrypoint moves here +//! and operates on sids directly. + +pub mod eviction; + +pub use eviction::{ + warn_if_retention_inverted, SchemaEvictionConfig, SchemaEvictionHandle, SchemaEvictionService, +}; diff --git a/data_plane/src/storage_engines/sketch_db/mod.rs b/data_plane/src/storage_engines/sketch_db/mod.rs index 7075eda8..38a7ca43 100644 --- a/data_plane/src/storage_engines/sketch_db/mod.rs +++ b/data_plane/src/storage_engines/sketch_db/mod.rs @@ -32,6 +32,7 @@ pub mod accuracy; pub mod backfill; pub mod data; pub mod index; +pub mod lifecycle; pub mod metrics; pub mod persistence; pub mod query; diff --git a/data_plane/src/storage_engines/sketch_db/schema/mod.rs b/data_plane/src/storage_engines/sketch_db/schema/mod.rs index 13fda708..2e07a1f4 100644 --- a/data_plane/src/storage_engines/sketch_db/schema/mod.rs +++ b/data_plane/src/storage_engines/sketch_db/schema/mod.rs @@ -1276,8 +1276,9 @@ mod tests { } } -// 2026-05 reorg: schema_eviction.rs moved alongside as a submodule. -pub mod eviction; -pub use eviction::{ +// Post-M2.3 reorg: eviction moved to `sketch_db::lifecycle::eviction`. +// Legacy re-exports keep `sketch_db::schema::SchemaEvictionService` callers +// compiling until they migrate to `sketch_db::lifecycle::*`. +pub use crate::storage_engines::sketch_db::lifecycle::{ warn_if_retention_inverted, SchemaEvictionConfig, SchemaEvictionHandle, SchemaEvictionService, };