FilterManager

Struct FilterManager 

Source
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

Source

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)
Source

pub fn trust_state(&self) -> FilterTrust

Get current trust state.

Source

pub fn is_trusted(&self) -> bool

Check if filter is trusted (convenience method).

Source

pub fn mark_trusted(&self)

Mark filter as trusted (after warmup + verification).

Source

pub fn mark_untrusted(&self)

Mark filter as untrusted (e.g., after detecting inconsistency).

Source

pub fn might_exist(&self, key: &str) -> Option<bool>

Check if a key might exist in L3.

Returns:

  • Some(true) → key might exist, check L3
  • Some(false) → key definitely doesn’t exist (trusted mode only)
  • None → filter is untrusted, must check L3
Source

pub fn should_check_l3(&self, key: &str) -> bool

Check if we should query L3 for this key.

Source

pub fn insert(&self, key: &str)

Insert a key into the filter (call when item is persisted to L3).

Source

pub fn remove(&self, key: &str) -> bool

Remove a key from the filter (call when item is deleted from L3).

Source

pub fn bulk_insert(&self, keys: &[String])

Bulk insert keys during warmup.

More efficient than individual inserts for large batches.

Source

pub fn export(&self) -> Option<Vec<u8>>

Export filter state to bytes for persistence.

Save these bytes to SQLite on shutdown for fast startup.

Source

pub fn import(&self, data: &[u8]) -> Result<(), String>

Import filter state from bytes.

Load bytes from SQLite on startup, then call mark_trusted().

Source

pub fn len(&self) -> usize

Get current entry count.

Source

pub fn is_empty(&self) -> bool

Check if filter is empty.

Source

pub fn stats(&self) -> (usize, usize, FilterTrust)

Get filter stats: (entry_count, capacity, trust_state).

Source

pub fn memory_usage_bytes(&self) -> usize

Estimate memory usage in bytes.

Source

pub fn node_id(&self) -> &str

Get the node ID used for deterministic seeding.

Source

pub fn seed(&self) -> u64

Get the deterministic seed.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more