Skip to main content

DiskKvStore

Struct DiskKvStore 

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

A content-addressed block store on disk, with its own writer threads.

Not Clone on purpose – it owns the writer threads and joins them when it drops. Share it as an Arc<DiskKvStore>; every method takes &self.

Implementations§

Source§

impl DiskKvStore

Source

pub fn open(config: DiskConfig) -> Result<Self, StoreError>

Creates the store’s directories and starts its writer threads. Does not scan root for pre-existing blocks: reattaching to a store left by a previous process is Self::reindex, an explicit step, because it costs a directory walk and a caller may prefer to start cold.

Source

pub fn root(&self) -> &Path

Source

pub fn put(&self, hash: BlockHash, block: KvBlock) -> Result<(), StoreError>

Accepts a block: buffered, indexed, then queued. Returns as soon as the block is visible – a reader can have it immediately, whether or not it has reached disk.

If the write queue is full the block is written on this thread rather than dropped, and the fallback is counted.

Source

pub fn put_blocking( &self, hash: BlockHash, block: KvBlock, ) -> Result<(), StoreError>

Like Self::put, but always writes on the calling thread.

Source

pub fn flush(&self)

Runs every pending write to completion, on this thread if no writer thread gets there first. Returns once the queue is empty and nothing is in flight.

Source

pub fn get(&self, hash: &BlockHash, expected: &CacheSignature) -> ReadOutcome

Looks a block up, verifying it against expected before returning it. Blocks until the answer is in hand.

This is exactly Self::read_async plus a wait – the disk tier has no separate synchronous read path for a prefetch to have to work around later.

Source

pub fn read_async( &self, hash: &BlockHash, expected: &CacheSignature, ) -> ReadHandle

Starts a read and returns immediately. The handle can be polled with ReadHandle::try_claim or waited on.

Source

pub fn prefetch(&self, hashes: &[BlockHash], expected: &CacheSignature)

Reads hashes ahead of anyone asking for them, on the reader threads, and returns without waiting.

Intended for a prefix chain the moment its hashes are known: every block the request is about to want, read while the tokens before it are still being processed. Blocks already staged, in flight, or in memory are skipped; so is everything past prefetch_capacity, because reading ahead must never be the thing that exhausts memory.

Source

pub fn clear_prefetch(&self)

Drops any staged read-ahead results. A caller that abandons a request it prefetched for should say so rather than leave the blocks occupying staging until something else needs the room.

Source

pub fn reindex(&self) -> Result<usize, StoreError>

Adopts the blocks already under root, as a restart would.

Source

pub fn remove(&self, hash: &BlockHash)

Removes a block from the index, the write buffer, and the disk.

Source

pub fn contains(&self, hash: &BlockHash) -> bool

True if the index holds an entry for hash – on disk or still buffered. Says nothing about whether its contents will verify.

Source

pub fn capacity(&self) -> u64

Byte ceiling an operator configured.

Source

pub fn effective_capacity(&self) -> u64

The ceiling eviction is actually working to right now: the configured one, or less when free disk says so.

Source

pub fn block_path(&self, hash: &BlockHash) -> PathBuf

Where a block’s file lives (or would). Useful to an operator tracing one block; the file may not exist yet, or at all.

Source

pub fn stats(&self) -> DiskStats

Trait Implementations§

Source§

impl Drop for DiskKvStore

Source§

fn drop(&mut self)

Stops accepting queued work and joins the worker threads. Blocks already queued but not started are not written: they were never durable, and a shutdown that waits for an arbitrarily deep queue is worse than a cold cache. Call Self::flush first if they matter.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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> 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.