Struct rustdb::compact::CompactFile

source ·
pub struct CompactFile {
    pub stg: Box<dyn Storage>,
    pub trace: bool,
    /* 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 it’s containing 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.

If the starter page array needs to be enlarged, the first extension page is relocated 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.

Note: for a free logical page a link to the next free logical page is stored after the page size, then a special value.

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

Fields§

§stg: Box<dyn Storage>

Underlying storage.

§trace: bool

Output tracing.

Implementations§

source§

impl CompactFile

source

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

Construct a new CompactFile.

source

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

Get the current size of the specified logical page.

source

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

Set the contents of the page.

source

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

Get logical page contents.

source

pub fn alloc_page(&mut self) -> u64

Allocate logical page number. Pages are numbered 0,1,2…

source

pub fn free_page(&mut self, pnum: u64)

Free a logical page number.

source

pub fn is_new(&self) -> bool

Is this a new file?

source

pub fn rollback(&mut self)

Resets logical page allocation to last save.

source

pub fn save(&mut self)

Process the temporary sets of free pages and write the file header.

source

pub fn compress( sp_size: usize, ep_size: usize, size: usize, saving: usize ) -> bool

Check whether compressing a page is worthwhile.

source

pub fn get_info(&self) -> (FxHashSet<u64>, u64)

Get the set of free logical pages ( also verifies free chain is ok ).

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.