pub struct BufferPool { /* private fields */ }Expand description
Buffer pool: caches decrypted pages in memory with SIEVE eviction.
Keyed by physical disk offset (not logical page_id) because under CoW/MVCC the same logical page_id can exist at different disk locations.
Invariants:
- HMAC is verified BEFORE decryption on every page fetch (cache miss).
- Dirty pages are PINNED and never evictable until commit.
- Transaction size is bounded by buffer pool capacity.
Implementations§
Source§impl BufferPool
impl BufferPool
pub fn new(capacity: usize) -> Self
Sourcepub fn fetch(
&mut self,
io: &dyn PageIO,
page_id: PageId,
dek: &[u8; 32],
mac_key: &[u8; 32],
encryption_epoch: u32,
) -> Result<&Page>
pub fn fetch( &mut self, io: &dyn PageIO, page_id: PageId, dek: &[u8; 32], mac_key: &[u8; 32], encryption_epoch: u32, ) -> Result<&Page>
Fetch a page by page_id. Reads from cache or disk.
On cache miss: reads from disk, verifies HMAC BEFORE decrypting, verifies xxHash64 checksum after decrypting.
Sourcepub fn fetch_mut(
&mut self,
io: &dyn PageIO,
page_id: PageId,
dek: &[u8; 32],
mac_key: &[u8; 32],
encryption_epoch: u32,
) -> Result<&mut Page>
pub fn fetch_mut( &mut self, io: &dyn PageIO, page_id: PageId, dek: &[u8; 32], mac_key: &[u8; 32], encryption_epoch: u32, ) -> Result<&mut Page>
Fetch a page mutably (for modification during write transaction).
Sourcepub fn insert_new(&mut self, page_id: PageId, page: Page) -> Result<()>
pub fn insert_new(&mut self, page_id: PageId, page: Page) -> Result<()>
Insert a new page directly into the buffer pool (for newly allocated pages). Marks it as dirty immediately.
Sourcepub fn mark_dirty(&mut self, page_id: PageId)
pub fn mark_dirty(&mut self, page_id: PageId)
Mark a page as dirty (modified in current write transaction).
Sourcepub fn flush_dirty(
&mut self,
io: &dyn PageIO,
dek: &[u8; 32],
mac_key: &[u8; 32],
encryption_epoch: u32,
) -> Result<()>
pub fn flush_dirty( &mut self, io: &dyn PageIO, dek: &[u8; 32], mac_key: &[u8; 32], encryption_epoch: u32, ) -> Result<()>
Flush all dirty pages to disk: encrypt + compute MAC + write. Clears dirty flags after successful flush.
Sourcepub fn discard_dirty(&mut self)
pub fn discard_dirty(&mut self)
Discard all dirty pages (on transaction abort). Removes dirty entries from the cache.
Sourcepub fn dirty_count(&self) -> usize
pub fn dirty_count(&self) -> usize
Number of dirty pages.