feat(sketch-db): Phase 2c — on-disk schema registry persistence - #24
Merged
Merged
Conversation
Closes the "timeline loses all pre-restart history" gap that Phase 3a explicitly left open. After a restart the §7 schema timeline now recovers the actual `created_at_ms` / `retired_at_ms` / `expires_at_ms` of every known `agg_id` instead of silently re-stamping every schema as "created right now". ## What's persisted `SchemaRegistry::load_or_new_from_config(path, &StreamingConfig)`: * If `path` does not exist: builds from the config and persists immediately — next restart has something to read. * If `path` exists and parses: loads every schema verbatim (timestamps + `AggregationConfig`), then reconciles against the fresh config — new ids become Active, ids only on disk get retired if they weren't already. * If `path` exists but is corrupt / wrong version: log a warning and fall back to fresh registry (preserves forward progress over historical accuracy). Every `reconcile()` call atomically rewrites the file (write tmp + rename). I/O errors are logged but never fail a reconcile — the registry is always authoritative in memory. ## Wire-up * New `AggSchema` derives `Serialize`/`Deserialize` (the underlying `AggregationConfig` already has them). * `PrecomputeEngineConfig` gains `schema_persist_path: Option<PathBuf>` with `#[serde(default)]` for backward-compatible YAML config files. * `--schema-persist-path <path>` CLI flag on the main binary; when unset, registry stays memory-only matching pre-Phase-2c behaviour. * On-disk format is tagged with `PERSIST_FORMAT_VERSION = 1` so future incompatible schema evolution can refuse to load instead of silently corrupting the timeline. ## Test plan - [x] 6 new tests in `stores::sketch_db::schema::tests`: round-trip preserves timestamps across simulated restart, first-run creates file, reconciles against fresh config, corrupt file falls back cleanly, unsupported version is rejected (fallback + rewrite), non-persistent path writes nothing. - [x] 567 lib tests pass (up from 561). - [x] clippy `--workspace --all-targets --tests -- -D warnings` clean. - [x] `cargo fmt -- --check` clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SchemaRegistry::load_or_new_from_config(path, &StreamingConfig)loads a JSON snapshot if present and reconciles against the live config.created_at_ms/retired_at_ms/expires_at_mssurvive restarts.reconcile()rewrites the file atomically (tmp + rename). I/O errors are logged but never block reconcile.PrecomputeEngineConfig::schema_persist_path+--schema-persist-pathCLI flag. Unset = memory-only, matching pre-2c behaviour.PERSIST_FORMAT_VERSION = 1on-disk tag so future incompatible changes refuse to load instead of silently corrupting the timeline.Why
Phase 3a explicitly noted the timeline loses pre-restart history without on-disk persistence. This PR closes that gap — one of the smaller todos on the sketch-DB roadmap but required for the Phase 3b-2 user-visible behaviour to hold across deploys.
Test plan
🤖 Generated with Claude Code