You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by ho...@apache.org on 2024/06/27 03:50:00 UTC

(opendal) branch fs-concurrent-write updated (d1a114918f -> 4c1e5a2f6f)

This is an automated email from the ASF dual-hosted git repository.

hoslo pushed a change to branch fs-concurrent-write
in repository https://gitbox.apache.org/repos/asf/opendal.git


 discard d1a114918f feat: fs add concurrent write
     new 4c1e5a2f6f feat: fs add concurrent write

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (d1a114918f)
            \
             N -- N -- N   refs/heads/fs-concurrent-write (4c1e5a2f6f)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 core/src/services/fs/writer.rs | 2 --
 1 file changed, 2 deletions(-)


(opendal) 01/01: feat: fs add concurrent write

Posted by ho...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hoslo pushed a commit to branch fs-concurrent-write
in repository https://gitbox.apache.org/repos/asf/opendal.git

commit 4c1e5a2f6f194d83aa75b32c2de6fc04e02daf72
Author: hoslo <ys...@gmail.com>
AuthorDate: Wed Jun 26 22:14:51 2024 +0800

    feat: fs add concurrent write
---
 core/src/services/fs/backend.rs | 18 ++++++++++++++++--
 core/src/services/fs/writer.rs  | 26 ++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/core/src/services/fs/backend.rs b/core/src/services/fs/backend.rs
index 89f2c1ca68..c0457e55fa 100644
--- a/core/src/services/fs/backend.rs
+++ b/core/src/services/fs/backend.rs
@@ -28,6 +28,7 @@ use super::core::*;
 use super::lister::FsLister;
 use super::reader::FsReader;
 use super::writer::FsWriter;
+use super::writer::FsWriters;
 use crate::raw::*;
 use crate::*;
 
@@ -169,7 +170,7 @@ pub struct FsBackend {
 
 impl Access for FsBackend {
     type Reader = FsReader<tokio::fs::File>;
-    type Writer = FsWriter<tokio::fs::File>;
+    type Writer = FsWriters;
     type Lister = Option<FsLister<tokio::fs::ReadDir>>;
     type BlockingReader = FsReader<std::fs::File>;
     type BlockingWriter = FsWriter<std::fs::File>;
@@ -313,7 +314,20 @@ impl Access for FsBackend {
             .await
             .map_err(new_std_io_error)?;
 
-        Ok((RpWrite::new(), FsWriter::new(target_path, tmp_path, f)))
+        let w = FsWriter::new(target_path, tmp_path, f);
+
+        let w = if op.append() {
+            FsWriters::One(w)
+        } else {
+            debug!("write with concurrent: {}", op.concurrent());
+            FsWriters::Two(oio::PositionWriter::new(
+                w,
+                op.executor().cloned(),
+                op.concurrent(),
+            ))
+        };
+
+        Ok((RpWrite::default(), w))
     }
 
     async fn delete(&self, path: &str, _: OpDelete) -> Result<RpDelete> {
diff --git a/core/src/services/fs/writer.rs b/core/src/services/fs/writer.rs
index c0d0688750..4d4d6820c0 100644
--- a/core/src/services/fs/writer.rs
+++ b/core/src/services/fs/writer.rs
@@ -16,6 +16,7 @@
 // under the License.
 
 use std::io::Write;
+use std::os::unix::fs::FileExt;
 use std::path::PathBuf;
 
 use bytes::Buf;
@@ -24,6 +25,9 @@ use tokio::io::AsyncWriteExt;
 use crate::raw::*;
 use crate::*;
 
+pub type FsWriters =
+    TwoWays<FsWriter<tokio::fs::File>, oio::PositionWriter<FsWriter<tokio::fs::File>>>;
+
 pub struct FsWriter<F> {
     target_path: PathBuf,
     tmp_path: Option<PathBuf>,
@@ -101,3 +105,25 @@ impl oio::BlockingWrite for FsWriter<std::fs::File> {
         Ok(())
     }
 }
+
+impl oio::PositionWrite for FsWriter<tokio::fs::File> {
+    async fn write_all_at(&self, offset: u64, buf: Buffer) -> Result<()> {
+        let f = self.f.as_ref().expect("FsWriter must be initialized");
+
+        let f = f
+            .try_clone()
+            .await
+            .map_err(new_std_io_error)?
+            .into_std()
+            .await;
+
+        tokio::task::spawn_blocking(move || {
+            std::thread::sleep(Duration::from_secs(1));
+            debug!("write_all_at: offset={}, len={}", offset, buf.len());
+            f.write_all_at(buf.chunk(), offset)
+                .map_err(new_std_io_error)
+        })
+        .await
+        .map_err(new_task_join_error)?
+    }
+}