feat(server): drain resident WAL writers on graceful shutdown - #167
Merged
Conversation
`ShardWriter` has no `Drop`, so its background tasks are only reclaimed by an explicit `close().await`. At process shutdown the runtime is about to stop, so the detached best-effort close in `RolloutStore::Drop` may never run. Add `AppState::shutdown()` to await `close()` on every resident rollout writer, and call it in `main` after `axum::serve` returns (connections drained). Idempotent and a no-op on an empty cache. Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
3 tasks
beinan
added a commit
that referenced
this pull request
Jul 22, 2026
…#168) ## Summary - `AppError::from_lance` took `impl Display` and string-matched the rendered message (`"not found"`, `"Invalid"`, `"DatasetNotFound"`). That is brittle (breaks on any Display wording change) and over-broad (any message containing `"Invalid"` — e.g. `InvalidTableLocation`, `InvalidRef` — became a 400). - Now takes `lance::Error` by value (re-exported as `LanceError` from `lance-context-core`) and matches **typed variants**: `DatasetNotFound`/`NotFound` → 404, `DatasetAlreadyExists` → 409, `InvalidInput`/`SchemaMismatch` → 400, else 500. - The one signal Lance exposes no dedicated variant for — "compaction already in progress", raised as an `ArrowError::InvalidArgumentError` folded into Lance's generic `Arrow` variant — is still matched by text, but checked **up front** so it keeps mapping to 409 `COMPACTION_IN_PROGRESS`. - All call sites already passed `lance::Error`, so no caller changes were needed. ## Test plan - [x] `cargo test -p lance-context-server error::` (typed-variant mapping + Arrow-wrapped compaction case) - [x] `cargo clippy -p lance-context-server -p lance-context-core` clean - [x] `cargo fmt --all` Independent of #166 and #167. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4 <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
ShardWriterhas noDrop, so its background tasks are only reclaimed by an explicitclose().await. At process shutdown the runtime is about to stop, so the detached best-effort close inRolloutStore::Dropmay never run — leaking those tasks / skipping a clean drain.AppState::shutdown(), which snapshots the resident LRU and awaitsRolloutStore::close()on each handle. Wired intomainright afteraxum::serve(...).with_graceful_shutdown(...)returns (connections already drained). Idempotent and a no-op on an empty cache.Test plan
cargo test -p lance-context-server state::(incl. newshutdown_closes_resident_writers)cargo clippy -p lance-context-servercleancargo fmt --allNote: this branch is independent of #166; it does not touch the
cleanup_interval_secsremoval.🤖 Generated with Claude Code