pub struct Page { /* private fields */ }Expand description
A 4KB page with header and content
This is the core data structure for the storage engine.
Implementations§
Source§impl Page
impl Page
Sourcepub fn from_bytes(data: [u8; 4096]) -> Self
pub fn from_bytes(data: [u8; 4096]) -> Self
Create a page from raw bytes
Sourcepub fn from_slice(slice: &[u8]) -> Result<Self, PageError>
pub fn from_slice(slice: &[u8]) -> Result<Self, PageError>
Create a page from a byte slice (must be exactly PAGE_SIZE)
Sourcepub fn as_bytes_mut(&mut self) -> &mut [u8; 4096]
pub fn as_bytes_mut(&mut self) -> &mut [u8; 4096]
Get mutable raw page data
Sourcepub fn header(&self) -> Result<PageHeader, PageError>
pub fn header(&self) -> Result<PageHeader, PageError>
Get page header
Sourcepub fn set_header(&mut self, header: &PageHeader)
pub fn set_header(&mut self, header: &PageHeader)
Set page header
Sourcepub fn lsn(&self) -> u64
pub fn lsn(&self) -> u64
Get the WAL Log Sequence Number stamped on this page.
0 means “no WAL guarantee” — the page was modified through a
path that did not append a WAL record (freelist trunks, header
shadow pages). The double-write buffer is responsible for the
integrity of lsn == 0 pages.
See src/storage/engine/btree/README.md § Invariant 3.
Sourcepub fn set_lsn(&mut self, lsn: u64)
pub fn set_lsn(&mut self, lsn: u64)
Stamp the WAL LSN of the record describing the most recent
mutation to this page. The pager’s flush path guarantees that
the WAL is durable up to this LSN before writing the page to
disk (WAL-first ordering — see PLAN.md § Target 3).
Callers should pass the LSN returned by WalWriter::append
for the change record. Pass 0 only on legacy / non-WAL
write paths (DWB-protected freelist + header writes).
Sourcepub fn cell_count(&self) -> u16
pub fn cell_count(&self) -> u16
Get cell count
Sourcepub fn set_cell_count(&mut self, count: u16)
pub fn set_cell_count(&mut self, count: u16)
Set cell count
Sourcepub fn set_parent_id(&mut self, parent_id: u32)
pub fn set_parent_id(&mut self, parent_id: u32)
Set parent page ID
Sourcepub fn right_child(&self) -> u32
pub fn right_child(&self) -> u32
Get right child page ID (for interior nodes)
Sourcepub fn set_right_child(&mut self, child_id: u32)
pub fn set_right_child(&mut self, child_id: u32)
Set right child page ID (for interior nodes)
Sourcepub fn free_start(&self) -> u16
pub fn free_start(&self) -> u16
Get free_start offset
Sourcepub fn set_free_start(&mut self, offset: u16)
pub fn set_free_start(&mut self, offset: u16)
Set free_start offset
Sourcepub fn set_free_end(&mut self, offset: u16)
pub fn set_free_end(&mut self, offset: u16)
Set free_end offset
Sourcepub fn content_mut(&mut self) -> &mut [u8] ⓘ
pub fn content_mut(&mut self) -> &mut [u8] ⓘ
Get mutable content area
Sourcepub fn update_checksum(&mut self)
pub fn update_checksum(&mut self)
Calculate and update checksum
Sourcepub fn verify_checksum(&self) -> Result<(), PageError>
pub fn verify_checksum(&self) -> Result<(), PageError>
Verify page checksum
Sourcepub fn get_cell_pointer(&self, index: usize) -> Result<u16, PageError>
pub fn get_cell_pointer(&self, index: usize) -> Result<u16, PageError>
Get cell pointer at index
Cell pointers are stored as u16 offsets starting at HEADER_SIZE.
Sourcepub fn set_cell_pointer(
&mut self,
index: usize,
pointer: u16,
) -> Result<(), PageError>
pub fn set_cell_pointer( &mut self, index: usize, pointer: u16, ) -> Result<(), PageError>
Set cell pointer at index
Sourcepub fn insert_cell(
&mut self,
key: &[u8],
value: &[u8],
) -> Result<usize, PageError>
pub fn insert_cell( &mut self, key: &[u8], value: &[u8], ) -> Result<usize, PageError>
Insert a new cell (key-value pair) into the page
Returns the cell index on success.
Sourcepub fn read_cell(&self, index: usize) -> Result<(Vec<u8>, Vec<u8>), PageError>
pub fn read_cell(&self, index: usize) -> Result<(Vec<u8>, Vec<u8>), PageError>
Read key and value from cell at index
Sourcepub fn search_key(&self, key: &[u8]) -> Result<usize, usize>
pub fn search_key(&self, key: &[u8]) -> Result<usize, usize>
Binary search for key in sorted cell array
Returns Ok(index) if key is found, Err(insert_pos) if not.
Sourcepub fn new_header_page(page_count: u32) -> Self
pub fn new_header_page(page_count: u32) -> Self
Create a database header page (page 0)
Sourcepub fn read_page_count(&self) -> u32
pub fn read_page_count(&self) -> u32
Read page count from header page
Sourcepub fn write_page_count(&mut self, count: u32)
pub fn write_page_count(&mut self, count: u32)
Write page count to header page
Sourcepub fn read_freelist_head(&self) -> u32
pub fn read_freelist_head(&self) -> u32
Read freelist head from header page
Sourcepub fn write_freelist_head(&mut self, page_id: u32)
pub fn write_freelist_head(&mut self, page_id: u32)
Write freelist head to header page
Sourcepub fn verify_header_page(&self) -> Result<(), PageError>
pub fn verify_header_page(&self) -> Result<(), PageError>
Verify this is a valid header page
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Page
impl RefUnwindSafe for Page
impl Send for Page
impl Sync for Page
impl Unpin for Page
impl UnsafeUnpin for Page
impl UnwindSafe for Page
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request