Skip to main content

Page

Struct Page 

Source
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

Source

pub fn new(page_type: PageType, page_id: u32) -> Page

Create a new empty page

Source

pub fn from_bytes(data: [u8; 4096]) -> Page

Create a page from raw bytes

Source

pub fn from_slice(slice: &[u8]) -> Result<Page, PageError>

Create a page from a byte slice (must be exactly PAGE_SIZE)

Source

pub fn as_bytes(&self) -> &[u8; 4096]

Get raw page data

Source

pub fn as_bytes_mut(&mut self) -> &mut [u8; 4096]

Get mutable raw page data

Source

pub fn header(&self) -> Result<PageHeader, PageError>

Get page header

Source

pub fn set_header(&mut self, header: &PageHeader)

Set page header

Source

pub fn page_type(&self) -> Result<PageType, PageError>

Get page type

Source

pub fn page_id(&self) -> u32

Get page ID

Source

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.

Source

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

Source

pub fn cell_count(&self) -> u16

Get cell count

Source

pub fn set_cell_count(&mut self, count: u16)

Set cell count

Source

pub fn parent_id(&self) -> u32

Get parent page ID

Source

pub fn set_parent_id(&mut self, parent_id: u32)

Set parent page ID

Source

pub fn right_child(&self) -> u32

Get right child page ID (for interior nodes)

Source

pub fn set_right_child(&mut self, child_id: u32)

Set right child page ID (for interior nodes)

Source

pub fn free_start(&self) -> u16

Get free_start offset

Source

pub fn set_free_start(&mut self, offset: u16)

Set free_start offset

Source

pub fn free_end(&self) -> u16

Get free_end offset

Source

pub fn set_free_end(&mut self, offset: u16)

Set free_end offset

Source

pub fn content(&self) -> &[u8]

Get content area (everything after header)

Source

pub fn content_mut(&mut self) -> &mut [u8]

Get mutable content area

Source

pub fn update_checksum(&mut self)

Calculate and update checksum

Source

pub fn verify_checksum(&self) -> Result<(), PageError>

Verify page checksum

Source

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.

Source

pub fn set_cell_pointer( &mut self, index: usize, pointer: u16, ) -> Result<(), PageError>

Set cell pointer at index

Source

pub fn get_cell(&self, index: usize) -> Result<&[u8], PageError>

Get cell data by index

Source

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.

Source

pub fn read_cell(&self, index: usize) -> Result<(Vec<u8>, Vec<u8>), PageError>

Read key and value from cell at index

Source

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.

Source

pub fn new_header_page(page_count: u32) -> Page

Create a database header page (page 0)

Source

pub fn read_page_count(&self) -> u32

Read page count from header page

Source

pub fn write_page_count(&mut self, count: u32)

Write page count to header page

Source

pub fn read_freelist_head(&self) -> u32

Read freelist head from header page

Source

pub fn write_freelist_head(&mut self, page_id: u32)

Write freelist head to header page

Source

pub fn verify_header_page(&self) -> Result<(), PageError>

Verify this is a valid header page

Trait Implementations§

Source§

impl Clone for Page

Source§

fn clone(&self) -> Page

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Page

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Page

Source§

fn default() -> Page

Returns the “default value” for a type. Read more

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more