Skip to main content

VarTypedMap

Struct VarTypedMap 

Source
pub struct VarTypedMap<K: Key + Send + Sync + Hash + Eq, T: Send + Sync, C: Codec<T> + Clone, H: TypedWriteHook<K, T> = NoHook> { /* private fields */ }
Expand description

A map with fixed-size keys and typed values T. Values are encoded via a Codec and stored on disk (variable length), with a BlockCache for reads. Uses per-shard HashMap for O(1) lookup. No ordered iteration — use VarTypedTree if you need prefix/range scans.

Thin wrapper around VarMap<K, VarTypedHookAdapter<K, T, C, H>>.

§Error handling

Same convention as VarTypedTree: get returns None on decode errors. migrate keeps entries that fail to decode.

Implementations§

Source§

impl<K: Key + Send + Sync + Hash + Eq, T: Send + Sync, C: Codec<T> + Clone> VarTypedMap<K, T, C>

Source

pub fn open(path: impl AsRef<Path>, config: Config, codec: C) -> DbResult<Self>

Open or create a VarTypedMap at the given path.

Source§

impl<K: Key + Send + Sync + Hash + Eq, T: Send + Sync, C: Codec<T> + Clone, H: TypedWriteHook<K, T>> VarTypedMap<K, T, C, H>

Source

pub fn open_hooked( path: impl AsRef<Path>, config: Config, codec: C, hook: H, ) -> DbResult<Self>

Open or create a VarTypedMap with a typed write hook.

Source

pub fn close(self) -> DbResult<()>

Graceful shutdown: write hint files (if enabled), flush write buffers + fsync.

Source

pub fn flush_buffers(&self) -> DbResult<()>

Flush all shard write buffers to disk (without fsync).

Source

pub fn config(&self) -> &Config

Get the database configuration.

Source

pub fn compact(&self) -> DbResult<usize>

Trigger a compaction pass across all shards.

Source

pub fn sync_hints(&self) -> DbResult<()>

Write hint files for all active shard files. Call during graceful shutdown.

Source

pub fn warmup(&self) -> DbResult<()>

Pre-populate the block cache with blocks containing live values.

Source

pub fn as_inner(&self) -> &VarMap<K, VarTypedHookAdapter<K, T, C, H>>

Access the underlying VarMap.

Source

pub fn codec(&self) -> &C

Access the codec used for encoding / decoding values.

Source

pub fn get(&self, key: &K) -> Option<T>

Source

pub fn get_or_err(&self, key: &K) -> DbResult<T>

Source

pub fn contains(&self, key: &K) -> bool

Source

pub fn put(&self, key: &K, value: &T) -> DbResult<()>

Source

pub fn insert(&self, key: &K, value: &T) -> DbResult<()>

Source

pub fn delete(&self, key: &K) -> DbResult<bool>

Source

pub fn cas(&self, key: &K, expected: &T, new_value: &T) -> DbResult<()>

Source

pub fn update(&self, key: &K, f: impl FnOnce(&T) -> T) -> DbResult<Option<T>>

Source

pub fn fetch_update( &self, key: &K, f: impl FnOnce(&T) -> T, ) -> DbResult<Option<T>>

Source

pub fn atomic<R>( &self, shard_key: &K, f: impl FnOnce(&mut VarTypedMapShard<'_, K, T, C, H>) -> DbResult<R>, ) -> DbResult<R>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn shard_for(&self, key: &K) -> usize

Source

pub fn entry_len(&self, key: &K) -> Option<u32>

Encoded value byte length for key, or None if absent. Reads only the in-memory index entry (DiskLoc::len); no disk I/O.

Source

pub fn migrate(&self, f: impl Fn(&K, &T) -> MigrateAction<T>) -> DbResult<usize>

Trait Implementations§

Source§

impl<T, C, H> Collection for VarTypedMap<T::SelfId, T, C, H>
where T: CollectionMeta + Send + Sync, C: Codec<T> + Clone + 'static, H: TypedWriteHook<T::SelfId, T>, T::SelfId: Key + Send + Sync + Hash + Eq,

Available on crate feature armour only.
Source§

fn name(&self) -> &str

Collection name (from CollectionMeta::NAME).
Source§

fn len(&self) -> usize

Number of entries in the collection.
Source§

fn compact(&self) -> DbResult<usize>

Run a compaction pass across all shards.
Source§

fn flush(&self) -> DbResult<()>

Flush in-memory write buffers and pending hint data so an immediate process exit will not lose committed writes. No default — every impl must provide this to avoid silent durability gaps.
Source§

fn is_empty(&self) -> bool

Source§

impl<K: Key + Send + Sync + Hash + Eq, T: Send + Sync, C: Codec<T> + Clone, H: TypedWriteHook<K, T>> CompactionIndex<K> for VarTypedMap<K, T, C, H>

Source§

fn update_if_match(&self, key: &K, old_loc: DiskLoc, new_loc: DiskLoc) -> bool

If the current index points to old_loc, it is updated to new_loc and returns true.
Source§

fn invalidate_blocks(&self, shard_id: u8, file_id: u32, total_bytes: u64)

Invalidate cached blocks for a file after compaction replaces its contents.
Source§

fn contains_key(&self, key: &K) -> bool

Returns true if the key currently exists in the index (i.e. has a live Put).
Source§

impl<K: Key + Send + Sync + Hash + Eq, T: Send + Sync, C: Codec<T> + Clone, H: TypedWriteHook<K, T>> ReplicationTarget for VarTypedMap<K, T, C, H>

Available on crate feature replication only.
Source§

fn apply_entry( &self, shard_inner: &mut ShardInner, shard_id: u8, file_id: u32, entry_offset: u64, header: &EntryHeader, key: &[u8], value: &[u8], ) -> DbResult<ApplyOutcome>

Apply entry with known key/value split (streaming mode, O(1) routing). Returns the outcome so the registry can account dead bytes.
Source§

fn try_apply_entry( &self, shard_inner: &mut ShardInner, shard_id: u8, file_id: u32, entry_offset: u64, header: &EntryHeader, raw_after_header: &[u8], ) -> DbResult<ApplyOutcome>

Try to apply entry with CRC matching (catch-up mode). Returns ApplyOutcome::NotMatched if CRC fails (key belongs to a different target).
Source§

fn key_len(&self) -> usize

The key length (K) for this tree type.

Auto Trait Implementations§

§

impl<K, T, C, H = NoHook> !Freeze for VarTypedMap<K, T, C, H>

§

impl<K, T, C, H = NoHook> !RefUnwindSafe for VarTypedMap<K, T, C, H>

§

impl<K, T, C, H> Send for VarTypedMap<K, T, C, H>

§

impl<K, T, C, H> Sync for VarTypedMap<K, T, C, H>

§

impl<K, T, C, H> Unpin for VarTypedMap<K, T, C, H>
where C: Unpin, H: Unpin, K: Unpin,

§

impl<K, T, C, H> UnsafeUnpin for VarTypedMap<K, T, C, H>
where C: UnsafeUnpin, H: UnsafeUnpin,

§

impl<K, T, C, H = NoHook> !UnwindSafe for VarTypedMap<K, T, C, H>

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

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,