8000 feat(phase6.2): packed pages + LRU page cache by adityamukho · Pull Request #13 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.7.0] - 2026-03-22

### Added
- Packed fact pages (`page_type = 0x02`): ~25 facts per 4KB page, ~25× disk space reduction vs v4
- LRU page cache (`src/storage/cache.rs`): configurable capacity (default 256 pages = 1MB)
- `OpenOptions::page_cache_size(usize)` — tune page cache capacity
- `CommittedFactReader` trait: index-driven fact resolution via page cache (no startup load-all)
- File format v5: `fact_page_format` header field; auto-migration from v4 on first open
- Page-based CRC32 checksum (v5): streams raw committed pages instead of all facts

### Changed
- `PersistentFactStorage::new()` takes `page_cache_capacity: usize` as second argument
- Committed facts no longer loaded into `Vec<Fact>` at startup; only pending facts held in memory
- `FactStorage::get_facts_by_entity`, `get_facts_by_attribute` use EAVT/AEVT index range scans

### Fixed
- v4 databases auto-migrated to v5 packed format on first open (no data loss)

## [0.6.0] - 2026-03-21

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "minigraf"
version = "0.6.0"
version = "0.7.0"
edition = "2024"
description = "Zero-config, single-file, embedded graph database with bi-temporal Datalog queries"
license = "MIT OR Apache-2.0"
Expand Down
16 changes: 14 additions & 2 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ pub struct OpenOptions {
/// Defaults to 1000. Lower values mean more frequent checkpoints (smaller WAL,
/// more I/O). Higher values mean less frequent checkpoints (larger WAL, less I/O).
pub wal_checkpoint_threshold: usize,
/// Number of pages to hold in the LRU page cache. Default: 256 (= 1MB at 4KB pages).
pub page_cache_size: usize,
}

impl Default for OpenOptions {
fn default() -> Self {
OpenOptions {
wal_checkpoint_threshold: 1000,
page_cache_size: 256,
}
}
}
Expand All @@ -72,6 +75,14 @@ impl OpenOptions {
Self::default()
}

/// Set the number of pages to hold in the LRU page cache.
///
/// Each page is 4KB, so the default of 256 pages uses ~1MB of memory.
pub fn page_cache_size(mut self, size: usize) -> Self {
self.page_cache_size = size;
self
}

/// Set the path for a file-backed database.
pub fn path(self, path: impl AsRef<Path>) -> OpenOptionsWithPath {
OpenOptionsWithPath {
Expand Down Expand Up @@ -186,7 +197,7 @@ impl Minigraf {

// Open the main .graph file
let backend = FileBackend::open(&db_path)?;
let pfs = PersistentFactStorage::new(backend)?;
let pfs = PersistentFactStorage::new(backend, opts.page_cache_size)?;

// Share the fact storage
let fact_storage = pfs.storage().clone();
Expand Down Expand Up @@ -225,7 +236,7 @@ impl Minigraf {
/// Create an in-memory database (no WAL, no persistence). Suitable for tests and REPL.
pub fn in_memory() -> Result<Self> {
let backend = MemoryBackend::new();
let pfs = PersistentFactStorage::new(backend)?;
let pfs = PersistentFactStorage::new(backend, 8)?;
let fact_storage = pfs.storage().clone();

// For in-memory databases we don't need the PFS beyond initialisation;
Expand Down Expand Up @@ -949,6 +960,7 @@ mod tests {

let opts = OpenOptions {
wal_checkpoint_threshold: 5,
page_cache_size: 256,
};
let db = Minigraf::open_with_options(&path, opts).unwrap();
assert_eq!(db.inner.options.wal_checkpoint_threshold, 5);
Expand Down
Loading
Loading
0