pub struct MemoryKv { /* private fields */ }Expand description
An in-memory NamespaceStore over a BTreeMap per partition.
apply validates the batch, then, under one lock and with no await,
reads the injected clock once and checks every precondition. A bounded
undo journal rolls back writes on a capacity error or panic, without
copying the whole partition. A poisoned lock is recovered.
Implementations§
Source§impl MemoryKv
impl MemoryKv
Sourcepub fn with_clock(clock: Arc<dyn Clock>) -> Self
pub fn with_clock(clock: Arc<dyn Clock>) -> Self
A store with full capabilities whose NotAfter clock is clock.
Sourcepub fn new(caps: StoreCapabilities) -> Self
pub fn new(caps: StoreCapabilities) -> Self
A store with reduced capabilities and the host clock.
Sourcepub fn with_capabilities(self, caps: StoreCapabilities) -> Self
pub fn with_capabilities(self, caps: StoreCapabilities) -> Self
Report and enforce caps.
Sourcepub fn with_fault(self, fault: MemoryFault) -> Self
pub fn with_fault(self, fault: MemoryFault) -> Self
Arm a one-shot MemoryFault.
Sourcepub fn with_capacity_limit(self, bytes: u64) -> Self
pub fn with_capacity_limit(self, bytes: u64) -> Self
Cap each partition at bytes (keys plus values): a batch with a put
that would exceed it fails with StoreError::Full; reads and
delete-only batches keep working.
Trait Implementations§
Source§impl Default for MemoryKv
Available on non-WebAssembly only.Full capabilities and the host clock.
impl Default for MemoryKv
Available on non-WebAssembly only.
Full capabilities and the host clock.
Source§impl NamespaceStore for MemoryKv
impl NamespaceStore for MemoryKv
Source§fn capabilities(&self) -> StoreCapabilities
fn capabilities(&self) -> StoreCapabilities
What this store supports.
Source§async fn get(
&self,
p: &Partition,
key: &Key,
) -> Result<Option<Value>, StoreError>
async fn get( &self, p: &Partition, key: &Key, ) -> Result<Option<Value>, StoreError>
The value at
key, if any.Source§async fn scan(
&self,
p: &Partition,
start: &Key,
end: &Key,
after: Option<&Cursor>,
limit: u32,
) -> Result<ScanPage, StoreError>
async fn scan( &self, p: &Partition, start: &Key, end: &Key, after: Option<&Cursor>, limit: u32, ) -> Result<ScanPage, StoreError>
Up to
limit (at least 1) entries in [start, end), ascending by
key bytes. after resumes strictly after the cursor’s position; a
cursor outside [start, end) (forged, or from another range) is
StoreError::Invalid. A page may hold fewer than limit entries
and still return next: callers page until next is None.Source§async fn apply(
&self,
p: &Partition,
batch: Batch,
) -> Result<BatchOutcome, StoreError>
async fn apply( &self, p: &Partition, batch: Batch, ) -> Result<BatchOutcome, StoreError>
One atomic, all-or-nothing batch: validate it, read the backend
clock once, check every precondition in order against committed
state (
NotAfter against that reading); on the first failure return
BatchOutcome::PreconditionFailed or
BatchOutcome::DeadlinePassed and write nothing, otherwise apply
every write and return BatchOutcome::Committed.Source§async fn stats(&self, p: &Partition) -> Result<PartitionStats, StoreError>
async fn stats(&self, p: &Partition) -> Result<PartitionStats, StoreError>
Storage used by one partition; may be approximate or up to 60 s
stale.
Source§fn has(
&self,
p: &Partition,
key: &Key,
) -> impl Future<Output = Result<bool, StoreError>> + MaybeSend
fn has( &self, p: &Partition, key: &Key, ) -> impl Future<Output = Result<bool, StoreError>> + MaybeSend
Whether
key holds a value.Source§fn get_many(
&self,
p: &Partition,
keys: &[Key],
) -> impl Future<Output = Result<Vec<Option<Value>>, StoreError>> + MaybeSend
fn get_many( &self, p: &Partition, keys: &[Key], ) -> impl Future<Output = Result<Vec<Option<Value>>, StoreError>> + MaybeSend
Several keys in one round trip; results in input order. The default
issues sequential
Self::get calls.Source§fn scan_many(
&self,
p: &Partition,
ranges: &[RangeScan],
) -> impl Future<Output = Result<Vec<ScanPage>, StoreError>> + MaybeSend
fn scan_many( &self, p: &Partition, ranges: &[RangeScan], ) -> impl Future<Output = Result<Vec<ScanPage>, StoreError>> + MaybeSend
Scan a served prefix of
ranges in order. A nonempty request returns
at least its first page and at most one page per range; callers
re-request any unserved suffix. Every returned page obeys Self::scan.
The default serves every range sequentially.Auto Trait Implementations§
impl !Freeze for MemoryKv
impl !RefUnwindSafe for MemoryKv
impl !UnwindSafe for MemoryKv
impl Send for MemoryKv
impl Sync for MemoryKv
impl Unpin for MemoryKv
impl UnsafeUnpin for MemoryKv
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
Mutably borrows from an owned value. Read more