You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2026/06/17 15:17:49 UTC
(opendal) branch main updated: fix(services/fs): cache fs reader (#7782)
This is an automated email from the ASF dual-hosted git repository.
Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 79ad8194d fix(services/fs): cache fs reader (#7782)
79ad8194d is described below
commit 79ad8194df1df4c2614723ef16c1a5aa78145b61
Author: dentiny <de...@gmail.com>
AuthorDate: Wed Jun 17 08:17:42 2026 -0700
fix(services/fs): cache fs reader (#7782)
---
core/services/fs/Cargo.toml | 2 +-
core/services/fs/src/backend.rs | 19 +++++++++++++------
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/core/services/fs/Cargo.toml b/core/services/fs/Cargo.toml
index 6e66f250d..a6e69d27d 100644
--- a/core/services/fs/Cargo.toml
+++ b/core/services/fs/Cargo.toml
@@ -37,7 +37,7 @@ opendal-core = { path = "../../core", version = "0.57.0", default-features = fal
"internal-tokio-rt",
] }
serde = { workspace = true, features = ["derive"] }
-tokio = { workspace = true, features = ["fs", "rt-multi-thread"] }
+tokio = { workspace = true, features = ["fs", "rt-multi-thread", "sync"] }
[target.'cfg(unix)'.dependencies]
xattr = "1"
diff --git a/core/services/fs/src/backend.rs b/core/services/fs/src/backend.rs
index 3c321f08c..322537198 100644
--- a/core/services/fs/src/backend.rs
+++ b/core/services/fs/src/backend.rs
@@ -219,6 +219,8 @@ impl oio::PositionRead for FsReader {
pub struct FsLazyReader {
core: Arc<FsCore>,
path: String,
+ // Open the file once and reuse the same handle across every read operation
+ reader: tokio::sync::OnceCell<oio::PositionReader<FsReader>>,
}
impl FsLazyReader {
@@ -226,15 +228,20 @@ impl FsLazyReader {
Self {
core,
path: path.to_string(),
+ reader: tokio::sync::OnceCell::new(),
}
}
- async fn reader(&self) -> Result<oio::PositionReader<FsReader>> {
- let file = self.core.fs_open(&self.path).await?;
- Ok(oio::PositionReader::new(FsReader::new(
- self.core.clone(),
- file,
- )))
+ async fn reader(&self) -> Result<&oio::PositionReader<FsReader>> {
+ self.reader
+ .get_or_try_init(|| async {
+ let file = self.core.fs_open(&self.path).await?;
+ Ok(oio::PositionReader::new(FsReader::new(
+ self.core.clone(),
+ file,
+ )))
+ })
+ .await
}
}