Skip to main content

ExplainStore

Struct ExplainStore 

Source
pub struct ExplainStore { /* private fields */ }
Expand description

A bounded, in-memory store of recent request explanations.

A single-instance affordance backing /debug/explain/{request_id} (docs/05 §5 ring buffer). Oldest entries are evicted past capacity, so memory is bounded regardless of traffic.

It retains the assembled trace, not a serialized document: /debug/explain is read for a vanishing fraction of requests, so building the JSON eagerly on every request was pure waste (~12µs/req of allocation + serialization). The doc is built lazily in ExplainStore::get instead; record only clones the (small, owned) trace and pushes it under the lock.

A single lock (not sharded): record’s per-request contention was measured to be dominated by the trace clone, not the lock — even one uncontended mutex under 16 threads matched a 16-way sharded one, because the allocation is the cost. Cloning the trace before taking the lock (below) keeps the critical section to an O(1) deque op, and a fast concurrent allocator (the binary’s mimalloc) is what actually relieves the clone’s cost.

Implementations§

Source§

impl ExplainStore

Source

pub fn new(capacity: usize) -> Self

Creates a store holding at most capacity recent explanations.

Source

pub fn record(&self, request_id: RequestId, trace: &RequestTrace)

Records the trace for request_id, evicting the oldest if full. Retains the trace as-is, the explain document is assembled lazily on Self::get.

Source

pub fn get(&self, request_id: &RequestId) -> Option<Value>

Looks up request_id and assembles its explanation document, if retained. The JSON is built here (read time), not at record time.

Trait Implementations§

Source§

impl Debug for ExplainStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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, 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, 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.