Skip to main content

PageStore

Trait PageStore 

Source
pub trait PageStore: Send + Sync {
    // Required methods
    fn page_size(&self) -> usize;
    fn allocate_page(&self) -> Page;
    fn read_into(&self, id: PageId, page: &mut Page) -> PageResult<()>;
    fn write_page(&self, id: PageId, page: &mut Page) -> PageResult<()>;
    fn sync(&self) -> PageResult<()>;
}
Expand description

A backing store of fixed-size pages addressed by PageId.

This is the extension seam between the buffer pool and what holds the pages. PageFile is the implementation that matters — pages on disk through Direct I/O — but the pool is written against this trait so it can be driven by an in-memory store in tests, or by an alternative backend later, without change.

A store does not cache, pin, or track dirtiness; those are the pool’s job. A store only has to read a page by id, write a page to an id, allocate a blank page of the right size, and flush to durability.

§Examples

A PageFile is a PageStore, so it can back a pool:

use page_db::{BufferPool, PageFile, PageId, DEFAULT_PAGE_SIZE};

let file = PageFile::open(&path, DEFAULT_PAGE_SIZE)?;
let pool = BufferPool::new(file, 64);   // 64 frames over the file
let _ = pool.new_page(PageId::new(0))?;

Required Methods§

Source

fn page_size(&self) -> usize

The fixed page size of this store, in bytes.

Source

fn allocate_page(&self) -> Page

Allocate a blank page sized for this store. The page is in memory only.

Source

fn read_into(&self, id: PageId, page: &mut Page) -> PageResult<()>

Read the page at id into page, verifying it.

Reusing the caller’s buffer is what lets the pool recycle a frame on a miss without allocating.

§Errors

Implementation-defined; for a file this is a short read past end-of-file or a failed integrity check.

Source

fn write_page(&self, id: PageId, page: &mut Page) -> PageResult<()>

Write page to slot id. The page’s header is stamped (id + checksum) as part of the write.

§Errors

Implementation-defined; for a file this is an I/O failure or a page-size mismatch.

Source

fn sync(&self) -> PageResult<()>

Flush all written pages to stable storage.

§Errors

Implementation-defined; for a file this is an I/O failure.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§