Struct rustdb::compact::CompactFile

source ·
pub struct CompactFile {
    pub stg: Box<dyn Storage>,
    /* private fields */
}
Expand description

CompactFile stores logical pages in smaller regions of backing storage.

Each logical page has a fixed size “starter page”.

A logical page that does not fit in the “starter page” has 1 or more “extension pages”.

Each extension page starts with its logical page number, to allow extension pages to be relocated as required.

When a new extension page is needed, it is allocated from the end of the file.

When an extension page is freed, the last extension page in the file is relocated to fill it.

The starter page section is extended as required when a logical page is written by relocating the first extension page to the end of the file.

File layout: file header | starter pages | extension pages.

Layout of starter page: 2 byte logical page size | array of 8 byte page numbers | user data | unused data.

Layout of extension page: 8 byte logical page number | user data | unused data.

All pages ( whether allocated or not ) initially have size zero.

Pages are allocated by simply incrementing lp_alloc, so sizes in the starter page section must be pre-initialised to zero when it is extended or after a renumber operation.

Fields§

§stg: Box<dyn Storage>

Underlying storage.

Implementations§

source§

impl CompactFile

source

pub fn new(stg: Box<dyn Storage>, sp_size: usize, ep_size: usize) -> Self

Construct a new CompactFile.

Trait Implementations§

source§

impl PageStorage for CompactFile

source§

fn size(&self, lpnum: u64) -> usize

Get page size (for repacking).
source§

fn info(&self) -> Box<dyn PageStorageInfo>

Information about page sizes.
source§

fn set_page(&mut self, lpnum: u64, data: Data)

Set contents of page.
source§

fn get_page(&self, lpnum: u64) -> Data

Get contents of page.
source§

fn new_page(&mut self) -> u64

Make a new page, result is page number.
source§

fn drop_page(&mut self, pnum: u64)

Drop page number.
source§

fn is_new(&self) -> bool

Is the underlying storage new?
source§

fn rollback(&mut self)

Undo changes since last save ( but set_page/renumber cannot be undone, only new_page and drop_page can be undone ).
source§

fn save(&mut self)

Save pages to underlying storage.
source§

fn wait_complete(&self)

Wait until save is complete.
source§

fn get_free(&mut self) -> (FxHashSet<u64>, u64)

Get set of free pages and number of pages ever allocated ( for VERIFY builtin function ).
source§

fn load_free_pages(&mut self) -> Option<u64>

Load free pages in preparation for page renumbering. Returns number of used pages or None if there are no free pages.
source§

fn renumber(&mut self, lpnum: u64) -> u64

Renumber page.
source§

fn set_alloc_pn(&mut self, target: u64)

Final part of page renumber operation.

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.