Skip to main content

BufferPool

Struct BufferPool 

Source
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

Source

pub fn new(capacity: usize) -> Self

Source

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.

Source

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).

Source

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.

Source

pub fn mark_dirty(&mut self, page_id: PageId)

Mark a page as dirty (modified in current write transaction).

Source

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.

Source

pub fn discard_dirty(&mut self)

Discard all dirty pages (on transaction abort). Removes dirty entries from the cache.

Source

pub fn len(&self) -> usize

Number of pages currently in the cache.

Source

pub fn is_empty(&self) -> bool

Whether the cache is empty.

Source

pub fn dirty_count(&self) -> usize

Number of dirty pages.

Source

pub fn capacity(&self) -> usize

Cache capacity.

Source

pub fn is_cached(&self, page_id: PageId) -> bool

Check if a page is cached.

Source

pub fn clear(&mut self)

Clear all entries from the cache.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V