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
impl DiskKvStore
Sourcepub fn open(config: DiskConfig) -> Result<Self, StoreError>
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.
pub fn root(&self) -> &Path
Sourcepub fn put(&self, hash: BlockHash, block: KvBlock) -> Result<(), StoreError>
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.
Sourcepub fn put_blocking(
&self,
hash: BlockHash,
block: KvBlock,
) -> Result<(), StoreError>
pub fn put_blocking( &self, hash: BlockHash, block: KvBlock, ) -> Result<(), StoreError>
Like Self::put, but always writes on the calling thread.
Sourcepub fn flush(&self)
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.
Sourcepub fn get(&self, hash: &BlockHash, expected: &CacheSignature) -> ReadOutcome
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.
Sourcepub fn read_async(
&self,
hash: &BlockHash,
expected: &CacheSignature,
) -> ReadHandle
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.
Sourcepub fn prefetch(&self, hashes: &[BlockHash], expected: &CacheSignature)
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.
Sourcepub fn clear_prefetch(&self)
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.
Sourcepub fn reindex(&self) -> Result<usize, StoreError>
pub fn reindex(&self) -> Result<usize, StoreError>
Adopts the blocks already under root, as a restart would.
Sourcepub fn remove(&self, hash: &BlockHash)
pub fn remove(&self, hash: &BlockHash)
Removes a block from the index, the write buffer, and the disk.
Sourcepub fn contains(&self, hash: &BlockHash) -> bool
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.
Sourcepub fn effective_capacity(&self) -> u64
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.
Sourcepub fn block_path(&self, hash: &BlockHash) -> PathBuf
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.
pub fn stats(&self) -> DiskStats
Trait Implementations§
Source§impl Drop for DiskKvStore
impl Drop for DiskKvStore
Source§fn drop(&mut self)
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.
Auto Trait Implementations§
impl !RefUnwindSafe for DiskKvStore
impl !UnwindSafe for DiskKvStore
impl Freeze for DiskKvStore
impl Send for DiskKvStore
impl Sync for DiskKvStore
impl Unpin for DiskKvStore
impl UnsafeUnpin for DiskKvStore
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> 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