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>
impl<K: Key + Send + Sync + Hash + Eq, T: Send + Sync, C: Codec<T> + Clone> VarTypedMap<K, T, C>
Source§impl<K: Key + Send + Sync + Hash + Eq, T: Send + Sync, C: Codec<T> + Clone, H: TypedWriteHook<K, T>> VarTypedMap<K, T, C, H>
impl<K: Key + Send + Sync + Hash + Eq, T: Send + Sync, C: Codec<T> + Clone, H: TypedWriteHook<K, T>> VarTypedMap<K, T, C, H>
Sourcepub fn open_hooked(
path: impl AsRef<Path>,
config: Config,
codec: C,
hook: H,
) -> DbResult<Self>
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.
Sourcepub fn close(self) -> DbResult<()>
pub fn close(self) -> DbResult<()>
Graceful shutdown: write hint files (if enabled), flush write buffers + fsync.
Sourcepub fn flush_buffers(&self) -> DbResult<()>
pub fn flush_buffers(&self) -> DbResult<()>
Flush all shard write buffers to disk (without fsync).
Sourcepub fn sync_hints(&self) -> DbResult<()>
pub fn sync_hints(&self) -> DbResult<()>
Write hint files for all active shard files. Call during graceful shutdown.
Sourcepub fn warmup(&self) -> DbResult<()>
pub fn warmup(&self) -> DbResult<()>
Pre-populate the block cache with blocks containing live values.
Sourcepub fn as_inner(&self) -> &VarMap<K, VarTypedHookAdapter<K, T, C, H>>
pub fn as_inner(&self) -> &VarMap<K, VarTypedHookAdapter<K, T, C, H>>
Access the underlying VarMap.
pub fn get(&self, key: &K) -> Option<T>
pub fn get_or_err(&self, key: &K) -> DbResult<T>
pub fn contains(&self, key: &K) -> bool
pub fn put(&self, key: &K, value: &T) -> DbResult<()>
pub fn insert(&self, key: &K, value: &T) -> DbResult<()>
pub fn delete(&self, key: &K) -> DbResult<bool>
pub fn cas(&self, key: &K, expected: &T, new_value: &T) -> DbResult<()>
pub fn update(&self, key: &K, f: impl FnOnce(&T) -> T) -> DbResult<Option<T>>
pub fn fetch_update( &self, key: &K, f: impl FnOnce(&T) -> T, ) -> DbResult<Option<T>>
pub fn atomic<R>( &self, shard_key: &K, f: impl FnOnce(&mut VarTypedMapShard<'_, K, T, C, H>) -> DbResult<R>, ) -> DbResult<R>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn shard_for(&self, key: &K) -> usize
Sourcepub fn entry_len(&self, key: &K) -> Option<u32>
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.
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>
Available on crate feature armour only.
impl<T, C, H> Collection for VarTypedMap<T::SelfId, T, C, H>
armour only.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>
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
fn update_if_match(&self, key: &K, old_loc: DiskLoc, new_loc: DiskLoc) -> bool
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)
fn invalidate_blocks(&self, shard_id: u8, file_id: u32, total_bytes: u64)
Source§fn contains_key(&self, key: &K) -> bool
fn contains_key(&self, key: &K) -> bool
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.
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>
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>
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>
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>
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>
ApplyOutcome::NotMatched if CRC fails (key belongs to a different target).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>
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> 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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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