mod local;
mod uring;
pub use local::LocalPageStore;
#[cfg(target_os = "linux")]
pub use uring::UringPageStore;
pub use uring::{init_uring_config, is_uring_available};
use bytes::Bytes;
use crate::cache::page_id::PageId;
use crate::error::Result;
use std::path::Path;
#[async_trait::async_trait]
pub trait PageStore: Send + Sync {
async fn put(&self, page_id: &PageId, page: &[u8]) -> Result<()>;
async fn get(&self, page_id: &PageId, offset: usize, dst: &mut [u8]) -> Result<usize>;
async fn get_bytes(&self, page_id: &PageId, offset: usize, len: usize) -> Result<Bytes> {
if len == 0 {
return Ok(Bytes::new());
}
let mut dst = vec![0u8; len];
let n = self.get(page_id, offset, &mut dst).await?;
if n == 0 {
Ok(Bytes::new())
} else {
dst.truncate(n);
Ok(Bytes::from(dst))
}
}
async fn delete(&self, page_id: &PageId) -> Result<()>;
fn root_dir(&self) -> &Path;
async fn write_identity(&self, file_id: &str, length: i64, mtime: i64) -> Result<()>;
async fn read_identity(&self, file_id: &str) -> Option<(i64, i64)>;
async fn delete_identity(&self, file_id: &str) -> Result<()>;
}