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.
Note: for a free logical page a link to the next free logical page is stored after the page size, then a special value.
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
impl CompactFile
sourcepub fn new(stg: Box<dyn Storage>, sp_size: usize, ep_size: usize) -> Self
pub fn new(stg: Box<dyn Storage>, sp_size: usize, ep_size: usize) -> Self
Construct a new CompactFile.
sourcepub fn lp_size(&self, lpnum: u64) -> usize
pub fn lp_size(&self, lpnum: u64) -> usize
Get the current size of the specified logical page. Note: not valid for a newly allocated page until it is first written.
sourcepub fn alloc_page(&mut self) -> u64
pub fn alloc_page(&mut self) -> u64
Allocate logical page number. Pages are numbered 0,1,2…
sourcepub fn compress(
sp_size: usize,
ep_size: usize,
size: usize,
saving: usize
) -> bool
pub fn compress( sp_size: usize, ep_size: usize, size: usize, saving: usize ) -> bool
Check whether compressing a page is worthwhile.
sourcepub fn get_info(&self) -> (FxHashSet<u64>, u64)
pub fn get_info(&self) -> (FxHashSet<u64>, u64)
Get the set of free logical pages ( also verifies free chain is ok ).
sourcepub fn load_free_pages(&mut self) -> u64
pub fn load_free_pages(&mut self) -> u64
Load free pages into lp_free, preparation for page renumbering. Returns number of used pages.
sourcepub fn renumber(&mut self, lpnum: u64) -> u64
pub fn renumber(&mut self, lpnum: u64) -> u64
Efficiently move the data associated with lpnum to new logical page.
sourcepub fn set_lpalloc(&mut self, target: u64)
pub fn set_lpalloc(&mut self, target: u64)
All lpnums >= target must have been renumbered to be < target at this point.