pub struct FreeList { /* private fields */ }Expand description
In-memory freelist tracking
Maintains a fast in-memory list of free pages, with persistence through trunk pages.
Implementations§
Source§impl FreeList
impl FreeList
Sourcepub fn from_header(trunk_head: u32, total_free: u32) -> FreeList
pub fn from_header(trunk_head: u32, total_free: u32) -> FreeList
Create freelist from header page info
Sourcepub fn trunk_head(&self) -> u32
pub fn trunk_head(&self) -> u32
Get trunk head page ID
Sourcepub fn total_free(&self) -> u32
pub fn total_free(&self) -> u32
Get total count of free pages
Sourcepub fn mark_clean(&mut self)
pub fn mark_clean(&mut self)
Mark freelist as clean
Sourcepub fn allocate(&mut self) -> Option<u32>
pub fn allocate(&mut self) -> Option<u32>
Allocate a free page
Returns None if no free pages available.
Sourcepub fn free_batch(&mut self, page_ids: &[u32])
pub fn free_batch(&mut self, page_ids: &[u32])
Add multiple pages to freelist
Sourcepub fn in_memory_count(&self) -> usize
pub fn in_memory_count(&self) -> usize
Get count of pages in memory (not including trunk pages)
Sourcepub fn load_from_trunk(
&mut self,
trunk: &Page,
) -> Result<Option<u32>, FreeListError>
pub fn load_from_trunk( &mut self, trunk: &Page, ) -> Result<Option<u32>, FreeListError>
Load free pages from a trunk page
Sourcepub fn create_trunk(&mut self, trunk_page_id: u32, next_trunk: u32) -> Page
pub fn create_trunk(&mut self, trunk_page_id: u32, next_trunk: u32) -> Page
Create a trunk page from current free pages
Moves pages from in-memory list to a trunk page. Returns the trunk page and remaining pages.
Sourcepub fn flush_to_trunks(
&mut self,
threshold: usize,
allocate_page: impl FnMut() -> u32,
) -> Vec<Page>
pub fn flush_to_trunks( &mut self, threshold: usize, allocate_page: impl FnMut() -> u32, ) -> Vec<Page>
Flush excess free pages to trunk pages
If we have more than threshold pages in memory, create trunk pages.
Returns trunk pages that need to be written.
Sourcepub fn merge_all_trunks(
&mut self,
load_page: impl Fn(u32) -> Option<Page>,
) -> Result<Vec<u32>, FreeListError>
pub fn merge_all_trunks( &mut self, load_page: impl Fn(u32) -> Option<Page>, ) -> Result<Vec<u32>, FreeListError>
Merge all trunk pages into memory
Used during compaction to reclaim trunk pages.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FreeList
impl RefUnwindSafe for FreeList
impl Send for FreeList
impl Sync for FreeList
impl Unpin for FreeList
impl UnsafeUnpin for FreeList
impl UnwindSafe for FreeList
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> 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