-
Notifications
You must be signed in to change notification settings - Fork 26
chore: Create page manager interface #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🟡 Heimdall Review Status
|
| #[derive(Debug)] | ||
| pub struct StorageEngine { | ||
| pub(crate) page_manager: PageManager, | ||
| pub(crate) page_manager: Box<dyn PageManagerTrait>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll probably want to use a generic type here, but this is fine for a first pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could use generic type, but that generic type will be bubbled to higher structs. I cannot find a good way to avoid <P: PageManagerTrait> at Database and at the struct that uses Database. Any suggestion for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically we could encapsulate P by using a PageManager enum type containing each of the possible page manager implementations. This may be the right thing to do in order to hide the PageManager concept entirely from clients.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really need a trait for this, unless you want to be able to run multiple implementations in parallel. I would just use a Cargo feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@and-cb i just want to run one implementation at one time, and want an easy way to configure (benchmark program, reth). I am not sure with cargo flag, we have any better way than this?
#[cfg(feature = "mmap-backend")]
let db = Database::open(...)?;
#[cfg(feature = "bufferpool-backend")]
let db = Database::open(...)?;
cargo test --features mmap-backend
cargo test --features bufferpool-backend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BrianBland would the use of enum need a swithching like this for every common fn
fn get(&self, page_id: PageId) -> Result<Page<'_>, PageError> {
match self {
Self::Mmap(manager) => manager.get(page_id),
...
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cargo test --features xyz part is correct; the #[cfg(feature = "xyz")] needs to be put above the PageManager implementations. Example:
// in src/page/manager.rs
#[cfg(feature = "mmap-backend")]
mod mmap;
#[cfg(feature = "bufferpool-backend")]
mod bufferpool;// in src/page.rs
#[cfg(feature = "mmap-backend")]
pub use manager::mmap::PageManager;
#[cfg(feature = "bufferpool-backend")]
pub use manager::bufferpool::PageManager;Now every code that does use crate::page::PageManager will get the one specified through --features
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think i will go with features from cargo. Thanks for suggestions
Approved review 3086183780 from BrianBland is now dismissed due to new commit. Re-request for approval.
Create a page manager trait so that we can experiment with different implementations, such as mmap or a buffer pool.