Skip to content

Commit

Permalink
adapt to new oio::Read
Browse files Browse the repository at this point in the history
  • Loading branch information
George-Miao committed Jun 5, 2024
1 parent 4308c6a commit 45ee5c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions core/src/services/compfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ impl Access for CompfsBackend {
am
}

async fn read(&self, path: &str, _: OpRead) -> Result<(RpRead, Self::Reader)> {
async fn read(&self, path: &str, op: OpRead) -> Result<(RpRead, Self::Reader)> {
let path = self.core.root.join(path.trim_end_matches('/'));

let file = self
.core
.exec(|| async move { compio::fs::OpenOptions::new().read(true).open(&path).await })
.await?;

let r = CompfsReader::new(self.core.clone(), file);
let r = CompfsReader::new(self.core.clone(), file, op.range());
Ok((RpRead::new(), r))
}

Expand Down
18 changes: 10 additions & 8 deletions core/src/services/compfs/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,27 @@ use crate::*;
#[derive(Debug)]
pub struct CompfsReader {
core: Arc<CompfsCore>,
f: compio::fs::File,
file: compio::fs::File,
range: BytesRange,
}

impl CompfsReader {
pub fn new(core: Arc<CompfsCore>, f: compio::fs::File) -> Self {
Self { core, f }
pub fn new(core: Arc<CompfsCore>, file: compio::fs::File, range: BytesRange) -> Self {
Self { core, file, range }
}
}

impl oio::Read for CompfsReader {
async fn read_at(&self, offset: u64, limit: usize) -> Result<Buffer> {
async fn read(&mut self) -> Result<Buffer> {
let mut bs = self.core.buf_pool.get();
bs.reserve(limit);
let f = self.f.clone();

let len = self.range.size().expect("range size is always Some");
bs.reserve(len as _);
let f = self.file.clone();
let mut bs = self
.core
.exec(move || async move {
let (_, bs) = buf_try!(@try f.read_at(bs, offset).await);

let (_, bs) = buf_try!(@try f.read_at(bs, len).await);
Ok(bs)
})
.await?;
Expand Down

0 comments on commit 45ee5c6

Please sign in to comment.