feat(prefilter): stale-while-revalidate refresh thread#210
Merged
Conversation
Closes design Goal 2 ("Stale-while-revalidate — periodic refresh without
blocking queries") and the last Phase-1 gap called out by the post-merge
Plan Review.
A single dedicated thread per engine, spawned from the server's boot
phase 7 (after eager preload + bound cache). Each tick (default 10s):
for entry in registry.entries():
if entry.is_stale(now): refresh_prefilter(entry.name)
`refresh_prefilter` recomputes off the query path and atomically swaps
the bitmap via ArcSwap — in-flight queries holding the old Arc continue
reading; next query sees the new one.
Lifecycle safety:
- Holds `Weak<ConcurrentEngine>`, so engine drop breaks the cycle.
- Checks `self.shutdown` between entries (not just per-tick), so the
thread can exit promptly even if it's mid-refresh on a stale entry.
Integration test `swr_thread_refreshes_stale_prefilters` verifies
end-to-end: register 10 docs → insert 5 more → rewind last_refreshed →
cardinality flips to 15 within 5s.
With the age gauge from PR #209, ops can alert on SWR thread liveness
(bitdex_prefilter_age_seconds > 2 × refresh_interval = something is
wedged).
Co-Authored-By: Claude Opus 4.6 (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
Closes design Goal 2 ("Stale-while-revalidate — periodic refresh without blocking queries") and the last Phase-1 gap from the post-merge Plan Review.
A single dedicated thread per engine, spawned from the server's boot phase 7 (after eager preload + bound cache). Each tick (default 10s), walks the registry and recomputes any entry past its `refresh_interval_secs`. Recompute runs off the query path; the new bitmap is published atomically via `ArcSwap` so in-flight queries holding the old `Arc` continue reading the old bitmap.
Lifecycle safety
Depends on / builds on
Test plan
Operational notes
With the age gauge from PR #209, ops can alert on SWR thread wedging: `bitdex_prefilter_age_seconds > 2 * refresh_interval_secs` means something's stuck (thread panic, upgrade failure, etc.). That's the SLO for "the prefilter is being maintained."
Follow-ups after this
Phase 2 work — nothing on the critical path for civitai_safe.
🤖 Generated with Claude Code