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 block cache
(≤ 8 KB values) and a value cache (> 8 KB values) for reads.
Uses per-shard HashMap for O(1) lookup. Ordered scans are available when
opened with iterable(true) via iter_view. Use
VarTypedTree for prefix/range scans without the iterable flag.
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.
§Write hooks
Uses TypedWriteHook<K, T> via [VarTypedHookAdapter]. The hook receives
&T directly; the adapter decodes raw bytes via the codec. on_write fires
on put/insert/delete/cas/compare_delete/update/fetch_update and inside atomic().
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 clean_shutdown(&self) -> DbResult<()>
pub fn clean_shutdown(&self) -> DbResult<()>
Graceful shutdown: write hint files (if enabled), flush write buffers + fsync.
pub fn close(self) -> DbResult<()>
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.
Sourcepub fn get(&self, key: &K) -> Option<T>
pub fn get(&self, key: &K) -> Option<T>
Get and decode a value by key. Returns None if absent or undecodable.
O(1) average index lookup under a brief per-shard mutex; the pread on a cache miss
runs outside the lock, then decode.
Sourcepub fn get_or_err(&self, key: &K) -> DbResult<T>
pub fn get_or_err(&self, key: &K) -> DbResult<T>
Get a value by key, returning Err(KeyNotFound) if absent or
Err(CorruptedEntry) if present but undecodable.
Sourcepub fn try_get(&self, key: &K) -> DbResult<Option<T>>
pub fn try_get(&self, key: &K) -> DbResult<Option<T>>
Strict read: Ok(None) only when absent; Err when present but the value
cannot be read or decoded.
pub fn contains(&self, key: &K) -> bool
Sourcepub fn for_each(&self, f: impl FnMut(K, T))
pub fn for_each(&self, f: impl FnMut(K, T))
Read-only pass over all live entries, decoding each value. Order is
unspecified — intended for schema validation on a quiet database.
Entries whose value fails to decode are skipped (logged at debug),
matching VarTypedTree::iter / VarTypedMap::get.
Sourcepub fn iter_view(&self) -> Option<VarTypedMapIterView<'_, K, T, C, H>>
pub fn iter_view(&self) -> Option<VarTypedMapIterView<'_, K, T, C, H>>
Ordered scan view. None unless the collection was opened with
iterable(true). Direction follows Config::reversed (default DESC).
Occasional admin/maintenance API, not a hot path. Use it to browse a
collection or bulk-clean stale rows (retain); for scan-heavy access reach
for the *Tree sibling — a Map’s strength is O(1) point lookup, and the
companion key index costs extra memory plus O(log N) per write. Unlike a
Tree scan it is not a point-in-time snapshot: the k-way merge drops
each shard lock between batches, so concurrent writes may be only partially
reflected (run on a quiet DB if you need a coherent view).
Sourcepub fn put(&self, key: &K, value: &T) -> DbResult<bool>
pub fn put(&self, key: &K, value: &T) -> DbResult<bool>
Insert or update a key-value pair.
Returns true if a previous value for key existed (overwrite),
false for a fresh insert.
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<()>
Sourcepub fn compare_delete(&self, key: &K, expected: &T) -> DbResult<()>
pub fn compare_delete(&self, key: &K, expected: &T) -> DbResult<()>
Compare-and-delete based on encoded bytes. Relies on deterministic codec output.
Returns Ok(()) on success, Err(CasMismatch) if current != expected,
Err(KeyNotFound) if the key doesn’t exist.
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§fn flush(&self) -> DbResult<()>
fn flush(&self) -> DbResult<()>
Source§fn periodic_flush(&self) -> DbResult<()>
fn periodic_flush(&self) -> DbResult<()>
Source§fn clean_shutdown(&self) -> DbResult<()>
fn clean_shutdown(&self) -> DbResult<()>
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>
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<T, C, H> IndexTarget for VarTypedMap<T::SelfId, T, C, H>
Available on crate feature var-collections only.
impl<T, C, H> IndexTarget for VarTypedMap<T::SelfId, T, C, H>
var-collections only.Source§impl<K, T, C, H> MultiTx for VarTypedMap<K, T, C, H>
Available on crate feature armour only.
impl<K, T, C, H> MultiTx for VarTypedMap<K, T, C, H>
armour only.type Key = K
Source§type Tx<'a> = VarTypedMapTx<'a, K, T, C, H>
where
Self: 'a
type Tx<'a> = VarTypedMapTx<'a, K, T, C, H> where Self: 'a
Source§fn shard_for_key(&self, key: &K) -> usize
fn shard_for_key(&self, key: &K) -> usize
xxh3(key) % shard_count, honoring
shard_prefix_bits).Source§fn begin_tx(&self) -> VarTypedMapTx<'_, K, T, C, H>
fn begin_tx(&self) -> VarTypedMapTx<'_, K, T, C, H>
Source§fn lock_shard_into<'a>(
&'a self,
shard_id: usize,
tx: &mut VarTypedMapTx<'a, K, T, C, H>,
)
fn lock_shard_into<'a>( &'a self, shard_id: usize, tx: &mut VarTypedMapTx<'a, K, T, C, H>, )
tx. Called by the scheduler
in global canonical order.Source§fn release_locks(&self, tx: &mut VarTypedMapTx<'_, K, T, C, H>) -> SyncNeeds
fn release_locks(&self, tx: &mut VarTypedMapTx<'_, K, T, C, H>) -> SyncNeeds
should_sync before dropping),
then release all of this collection’s shard locks. The event log stays.Source§fn run_sync(&self, needs: SyncNeeds) -> DbResult<()>
fn run_sync(&self, needs: SyncNeeds) -> DbResult<()>
sync() the reported shards. No-op when empty.Source§fn replay_hooks(&self, tx: VarTypedMapTx<'_, K, T, C, H>)
fn replay_hooks(&self, tx: VarTypedMapTx<'_, K, T, C, H>)
fn collection_id(&self) -> usize
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).Source§impl<T, C, H> SchemaCollection for VarTypedMap<T::SelfId, T, C, H>
Available on crate feature var-collections only.
impl<T, C, H> SchemaCollection for VarTypedMap<T::SelfId, T, C, H>
var-collections only.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 = NoHook> !UnwindSafe 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,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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