pub struct FilterManager { /* private fields */ }Expand description
Cuckoo filter manager for L3 existence checks.
The filter tracks which keys exist in L3 (SQL). On cache miss:
- If filter says “definitely not” AND trusted → return 404 immediately
- If filter says “maybe” → check L3
- If untrusted → always check L3 (degraded mode)
The filter must be warmed from L3 on startup and verified via merkle root comparison before being marked trusted.
§Persistence
The filter supports export/import for fast startup:
- On shutdown:
export()→ save bytes to SQLite - On startup: load bytes →
import()→mark_trusted()→ ready instantly
Implementations§
Source§impl FilterManager
impl FilterManager
Sourcepub fn new(node_id: impl Into<String>, initial_capacity: usize) -> Self
pub fn new(node_id: impl Into<String>, initial_capacity: usize) -> Self
Create a new filter manager (starts untrusted).
§Arguments
node_id- Unique identifier for deterministic seeding (e.g., hostname)initial_capacity- Expected number of items (filter will grow if exceeded)
Sourcepub fn trust_state(&self) -> FilterTrust
pub fn trust_state(&self) -> FilterTrust
Get current trust state.
Sourcepub fn is_trusted(&self) -> bool
pub fn is_trusted(&self) -> bool
Check if filter is trusted (convenience method).
Sourcepub fn mark_trusted(&self)
pub fn mark_trusted(&self)
Mark filter as trusted (after warmup + verification).
Sourcepub fn mark_untrusted(&self)
pub fn mark_untrusted(&self)
Mark filter as untrusted (e.g., after detecting inconsistency).
Sourcepub fn might_exist(&self, key: &str) -> Option<bool>
pub fn might_exist(&self, key: &str) -> Option<bool>
Check if a key might exist in L3.
Returns:
Some(true)→ key might exist, check L3Some(false)→ key definitely doesn’t exist (trusted mode only)None→ filter is untrusted, must check L3
Sourcepub fn should_check_l3(&self, key: &str) -> bool
pub fn should_check_l3(&self, key: &str) -> bool
Check if we should query L3 for this key.
Sourcepub fn insert(&self, key: &str)
pub fn insert(&self, key: &str)
Insert a key into the filter (call when item is persisted to L3).
Sourcepub fn remove(&self, key: &str) -> bool
pub fn remove(&self, key: &str) -> bool
Remove a key from the filter (call when item is deleted from L3).
Sourcepub fn bulk_insert(&self, keys: &[String])
pub fn bulk_insert(&self, keys: &[String])
Bulk insert keys during warmup.
More efficient than individual inserts for large batches.
Sourcepub fn export(&self) -> Option<Vec<u8>>
pub fn export(&self) -> Option<Vec<u8>>
Export filter state to bytes for persistence.
Save these bytes to SQLite on shutdown for fast startup.
Sourcepub fn import(&self, data: &[u8]) -> Result<(), String>
pub fn import(&self, data: &[u8]) -> Result<(), String>
Import filter state from bytes.
Load bytes from SQLite on startup, then call mark_trusted().
Sourcepub fn stats(&self) -> (usize, usize, FilterTrust)
pub fn stats(&self) -> (usize, usize, FilterTrust)
Get filter stats: (entry_count, capacity, trust_state).
Sourcepub fn memory_usage_bytes(&self) -> usize
pub fn memory_usage_bytes(&self) -> usize
Estimate memory usage in bytes.
Auto Trait Implementations§
impl !Freeze for FilterManager
impl !RefUnwindSafe for FilterManager
impl Send for FilterManager
impl Sync for FilterManager
impl Unpin for FilterManager
impl !UnwindSafe for FilterManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more