pub struct BufferPool {
pub stats: BufferPoolStats,
/* private fields */
}Expand description
The buffer pool - caches pages in memory
Fields§
§stats: BufferPoolStatsStatistics
Implementations§
Source§impl BufferPool
impl BufferPool
Sourcepub fn new(capacity: usize, file_manager: Arc<FileManager>) -> Self
pub fn new(capacity: usize, file_manager: Arc<FileManager>) -> Self
Create a new buffer pool with default Clock eviction
Sourcepub fn with_policy(
capacity: usize,
file_manager: Arc<FileManager>,
policy_type: EvictionPolicyType,
) -> Self
pub fn with_policy( capacity: usize, file_manager: Arc<FileManager>, policy_type: EvictionPolicyType, ) -> Self
Create a new buffer pool with specified eviction policy
Sourcepub fn eviction_policy_type(&self) -> EvictionPolicyType
pub fn eviction_policy_type(&self) -> EvictionPolicyType
Get the eviction policy type
Sourcepub fn eviction_policy_name(&self) -> &'static str
pub fn eviction_policy_name(&self) -> &'static str
Get the eviction policy name
Sourcepub fn get_page_for_write(&self, page_id: PageId) -> Result<PageGuardMut>
pub fn get_page_for_write(&self, page_id: PageId) -> Result<PageGuardMut>
Get a page for writing
Sourcepub fn allocate_page(
&self,
page_type: PageType,
) -> Result<(PageId, PageGuardMut)>
pub fn allocate_page( &self, page_type: PageType, ) -> Result<(PageId, PageGuardMut)>
Allocate a new page
Sourcepub fn copy_page(&self, page_id: PageId) -> Result<(PageId, PageGuardMut)>
pub fn copy_page(&self, page_id: PageId) -> Result<(PageId, PageGuardMut)>
Copy a page for modification (copy-on-write)
Sourcepub fn flush_all(&self) -> Result<()>
pub fn flush_all(&self) -> Result<()>
Flush all dirty pages
Skips pages owned by active (uncommitted) transactions to prevent uncommitted data from being persisted.
Sourcepub fn flush_page(&self, page_id: PageId) -> Result<()>
pub fn flush_page(&self, page_id: PageId) -> Result<()>
Flush a specific page
Sourcepub fn register_active_txn(&self, txn_id: TransactionId)
pub fn register_active_txn(&self, txn_id: TransactionId)
Register a transaction as active (its dirty pages can’t be evicted)
Sourcepub fn unregister_active_txn(&self, txn_id: TransactionId)
pub fn unregister_active_txn(&self, txn_id: TransactionId)
Unregister a transaction (called on commit or abort)
Sourcepub fn get_page_for_write_in_txn(
&self,
page_id: PageId,
txn_id: TransactionId,
) -> Result<PageGuardMut>
pub fn get_page_for_write_in_txn( &self, page_id: PageId, txn_id: TransactionId, ) -> Result<PageGuardMut>
Get a page for write within a transaction context
This marks the page as dirty and records the transaction that modified it. Pages owned by uncommitted transactions cannot be evicted.
Sourcepub fn allocate_page_in_txn(
&self,
page_type: PageType,
txn_id: TransactionId,
) -> Result<(PageId, PageGuardMut)>
pub fn allocate_page_in_txn( &self, page_type: PageType, txn_id: TransactionId, ) -> Result<(PageId, PageGuardMut)>
Allocate a new page within a transaction context
Sourcepub fn flush_transaction(&self, txn_id: TransactionId) -> Result<()>
pub fn flush_transaction(&self, txn_id: TransactionId) -> Result<()>
Flush only pages dirtied by a specific transaction
Called during commit to persist the transaction’s changes. After flushing, clears the transaction ownership from the pages.
Sourcepub fn discard_transaction(&self, txn_id: TransactionId) -> Result<()>
pub fn discard_transaction(&self, txn_id: TransactionId) -> Result<()>
Discard dirty pages from an aborted transaction
This clears the dirty flag and transaction ownership for pages that were modified by the aborted transaction, effectively discarding their uncommitted changes.
Note: The in-memory page data still contains the aborted writes, but since the dirty flag is cleared, they won’t be persisted. When the page is evicted and re-read, the original data is restored.
Sourcepub fn stats_snapshot(&self) -> BufferPoolStatsSnapshot
pub fn stats_snapshot(&self) -> BufferPoolStatsSnapshot
Get a snapshot of current statistics
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for BufferPool
impl !RefUnwindSafe for BufferPool
impl Send for BufferPool
impl Sync for BufferPool
impl Unpin for BufferPool
impl UnsafeUnpin for BufferPool
impl !UnwindSafe for BufferPool
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> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.