Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ zerocopy = { version = "0.8.24", features = ["derive"] }
parking_lot = { version = "0.12.4", features = ["send_guard"] }
fxhash = "0.2.1"
static_assertions = "1.1.0"
evict = "0.3.1"
dashmap = "6.1.0"
libc = "0.2.174"

[dev-dependencies]
criterion = "0.6.0"
Expand Down
4 changes: 2 additions & 2 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ mod tests {
assert_eq!(
db.storage_engine
.page_manager
.get(1, *page_id)
.get(*page_id)
.unwrap_or_else(|err| panic!("page {page_id} not found: {err:?}"))
.snapshot_id(),
1
Expand Down Expand Up @@ -497,7 +497,7 @@ mod tests {
let page = db
.storage_engine
.page_manager
.get(1, *page_id)
.get(*page_id)
.unwrap_or_else(|err| panic!("page {page_id} not found: {err:?}"));
if old_page_ids.contains(page_id) {
assert_eq!(page.snapshot_id(), 1);
Expand Down
5 changes: 4 additions & 1 deletion src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ mod page;
mod slotted_page;
mod state;

pub use manager::{mmap::PageManager, options::PageManagerOptions, PageError};
pub use manager::{
buffer_pool::BufferPoolManager, mmap::PageManager, options::PageManagerOptions, PageError,
PageManagerTrait,
};
pub use page::{Page, PageMut};
pub use slotted_page::{SlottedPage, SlottedPageMut, CELL_POINTER_SIZE};

Expand Down
34 changes: 33 additions & 1 deletion src/page/manager.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
use crate::page::PageId;
use std::io;

use crate::{
page::{Page, PageId, PageMut},
snapshot::SnapshotId,
};

pub(super) mod buffer_pool;
pub(super) mod cache_evict;
pub(super) mod mmap;
pub(super) mod options;

Expand All @@ -18,5 +25,30 @@ pub enum PageError {
IO(std::io::Error),
InvalidValue,
InvalidPageContents(PageId),
OutOfMemory,
EvictionPolicy,
// TODO: add more errors here for other cases.
}

pub trait PageManagerTrait: Send + Sync + std::fmt::Debug {
/// Retrieves a read-only page from the page manager
fn get(&self, page_id: PageId) -> Result<Page<'_>, PageError>;

/// Retrieves a mutable page from the page manager
fn get_mut(&self, snapshot_id: SnapshotId, page_id: PageId) -> Result<PageMut<'_>, PageError>;

/// Allocates a new page
fn allocate(&self, snapshot_id: SnapshotId) -> Result<PageMut<'_>, PageError>;

/// Returns the number of pages currently stored
fn size(&self) -> u32;

/// Returns the maximum number of pages that can be allocated
fn capacity(&self) -> u32;

/// Syncs pages to the backing store
fn sync(&self) -> io::Result<()>;

/// Syncs and closes the page manager
fn close(&self) -> io::Result<()>;
}
Loading