Expand description
Per-query memory tracking and budget enforcement.
The MemoryTracker provides a lightweight mechanism to enforce
per-query memory limits. Query operators call try_allocate before
materializing intermediate results; if the cumulative allocation
exceeds the configured budget, the query fails with
QueryError::QueryMemoryExceeded rather than causing OOM.
§Incremental budget enforcement
All query operators (aggregate, dedup, window) perform pre-allocation memory estimates before building results. For grouped aggregation, the budget is checked incrementally as new groups are created. For dedup and window, the estimated output size is checked before materialization. Full spill-to-disk is in the backlog.
§Usage
use chronix_query::memory::MemoryTracker;
let tracker = MemoryTracker::new(1024 * 1024); // 1 MiB budget
tracker.try_allocate(512 * 1024).unwrap(); // OK — 512 KiB used
tracker.try_allocate(256 * 1024).unwrap(); // OK — 768 KiB used
assert_eq!(tracker.allocated(), 768 * 1024);
tracker.deallocate(512 * 1024); // release 512 KiB
assert_eq!(tracker.allocated(), 256 * 1024);Structs§
- Memory
Tracker - Tracks memory allocations against a per-query budget.