pub struct MemMapCfg {
pub module_id: u8,
pub path: PathBuf,
pub version: u32,
pub initial_t: usize,
pub sync_interval: Option<Duration>,
pub page_size: Option<PageSize>,
}Expand description
Configurations for MemMap
§Example
use frozen_core::memmap::MemMapCfg;
use std::time::Duration;
let cfg = MemMapCfg {
module_id: 1,
path: std::path::PathBuf::from("test.db"),
version: 1,
initial_t: 512,
sync_interval: Some(Duration::from_millis(0x64)),
page_size: None,
};
assert_eq!(cfg.version, 1);
assert_eq!(cfg.initial_t, 512);
assert_eq!(cfg.sync_interval, Some(Duration::from_millis(0x64)));
assert_eq!(cfg.page_size, None);Fields§
§module_id: u8Identifier used while error propagation
path: PathBufBase path for/of the file
§Notes
- The caller must make sure that the path represents a file and all the parent directories included in the path do exist
- The actual file created on disk is derived by appending the
versionto the base file name (e.g.data.binwith version1becomesdata_1.bin)
version: u32Schema or layout version of the underlying memory-mapped file
Because the binary layout on disk is constructed according to the initial type T and
structural parameters, MemMap strictly requires type invariants across a file’s lifetime
When an application evolves its data structures or migrates T, incrementing version
ensures a new versioned backing file (<name>_<ver>) is created on disk without corrupting
or clashing with previously persisted data
initial_t: usizeNumber of T elements to pre-allocate on fs when MemMap is initialized
Initial file length will be core::mem::size_of::<T>() * initial_t (bytes)
sync_interval: Option<Duration>Optional interval for the background sync thread
If Some(duration), a background worker thread is spawned which flushes dirty mapped pages
at this interval; and if None, background sync is disabled and durability advances via
manual sync or forced tickets
page_size: Option<PageSize>Configured page size unit for file allocation and growth
Must be a power of 2 and at least 4096 bytes (PageSize::K4).
If None, defaults to the platform/host page size ([PlatformMemMap::page_size()]).