omendb_core/omen/mod.rs
1//! .omen single-file storage format for `OmenDB`
2//!
3//! Layout:
4//! ```text
5//! ┌─────────────────────────────────────────────────────────────┐
6//! │ HEADER (4KB, page 0) │
7//! ├─────────────────────────────────────────────────────────────┤
8//! │ VECTOR SECTION (page-aligned, mmap) │
9//! ├─────────────────────────────────────────────────────────────┤
10//! │ GRAPH SECTION (page-aligned, mmap) │
11//! ├─────────────────────────────────────────────────────────────┤
12//! │ METADATA SECTION │
13//! ├─────────────────────────────────────────────────────────────┤
14//! │ WAL SECTION (append-only, at end) │
15//! └─────────────────────────────────────────────────────────────┘
16//! ```
17
18mod file;
19mod graph;
20mod header;
21mod metadata;
22mod section;
23mod vectors;
24mod wal;
25
26pub use file::OmenFile;
27pub use graph::GraphSection;
28pub use header::{Metric, OmenHeader, HEADER_SIZE, MAGIC, VERSION_MAJOR, VERSION_MINOR};
29pub use metadata::{FieldIndex, Filter, FilterValue, MetadataIndex};
30pub use section::{SectionEntry, SectionType};
31pub use vectors::VectorSection;
32pub use wal::{Wal, WalEntry, WalEntryType};
33
34/// Page size for alignment (8KB optimal for `NVMe`)
35pub const PAGE_SIZE: usize = 8192;
36
37/// Align a value to page boundary
38#[inline]
39#[must_use]
40pub const fn align_to_page(value: usize) -> usize {
41 (value + PAGE_SIZE - 1) & !(PAGE_SIZE - 1)
42}
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_align_to_page() {
50 assert_eq!(align_to_page(0), 0);
51 assert_eq!(align_to_page(1), PAGE_SIZE);
52 assert_eq!(align_to_page(PAGE_SIZE), PAGE_SIZE);
53 assert_eq!(align_to_page(PAGE_SIZE + 1), PAGE_SIZE * 2);
54 }
55}