You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by te...@apache.org on 2026/04/30 14:57:11 UTC

(opendal) branch main updated: fix(layers/concurrent-limit): limit copy and rename (#7452)

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

TennyZhuang 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 cd17e931a fix(layers/concurrent-limit): limit copy and rename (#7452)
cd17e931a is described below

commit cd17e931a7522af1aace46309d4846d69675ca7f
Author: TennyZhuang <zt...@gmail.com>
AuthorDate: Thu Apr 30 22:57:04 2026 +0800

    fix(layers/concurrent-limit): limit copy and rename (#7452)
    
    Co-authored-by: TennyZhuang <91...@users.noreply.github.com>
---
 core/layers/concurrent-limit/src/lib.rs | 73 +++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/core/layers/concurrent-limit/src/lib.rs b/core/layers/concurrent-limit/src/lib.rs
index bc0e2ebcd..305f68fb2 100644
--- a/core/layers/concurrent-limit/src/lib.rs
+++ b/core/layers/concurrent-limit/src/lib.rs
@@ -278,6 +278,18 @@ where
             .map(|(rp, w)| (rp, ConcurrentLimitWrapper::new(w, permit)))
     }
 
+    async fn copy(&self, from: &str, to: &str, args: OpCopy) -> Result<RpCopy> {
+        let _permit = self.semaphore.acquire().await;
+
+        self.inner.copy(from, to, args).await
+    }
+
+    async fn rename(&self, from: &str, to: &str, args: OpRename) -> Result<RpRename> {
+        let _permit = self.semaphore.acquire().await;
+
+        self.inner.rename(from, to, args).await
+    }
+
     async fn stat(&self, path: &str, args: OpStat) -> Result<RpStat> {
         let _permit = self.semaphore.acquire().await;
 
@@ -398,6 +410,67 @@ mod tests {
         );
     }
 
+    #[tokio::test]
+    async fn operation_semaphore_limits_copy_and_rename() {
+        #[derive(Clone, Debug)]
+        struct CopyRenameBackend {
+            info: Arc<AccessorInfo>,
+        }
+
+        impl Access for CopyRenameBackend {
+            type Reader = ();
+            type Writer = ();
+            type Lister = ();
+            type Deleter = ();
+
+            fn info(&self) -> Arc<AccessorInfo> {
+                self.info.clone()
+            }
+
+            async fn copy(&self, _: &str, _: &str, _: OpCopy) -> Result<RpCopy> {
+                Ok(RpCopy::default())
+            }
+
+            async fn rename(&self, _: &str, _: &str, _: OpRename) -> Result<RpRename> {
+                Ok(RpRename::default())
+            }
+        }
+
+        let semaphore = Arc::new(Semaphore::new(1));
+        let layer = ConcurrentLimitLayer::with_semaphore(semaphore.clone());
+        let info = Arc::new(AccessorInfo::default());
+        info.set_native_capability(Capability {
+            copy: true,
+            rename: true,
+            ..Default::default()
+        });
+        let op = OperatorBuilder::new(CopyRenameBackend { info })
+            .layer(layer)
+            .finish();
+
+        let permit = semaphore.clone().acquire_owned(1).await;
+
+        let copy = timeout(Duration::from_millis(50), op.copy("from", "to")).await;
+        assert!(copy.is_err(), "copy should wait for the operation permit");
+
+        let rename = timeout(Duration::from_millis(50), op.rename("from", "to")).await;
+        assert!(
+            rename.is_err(),
+            "rename should wait for the operation permit"
+        );
+
+        drop(permit);
+
+        timeout(Duration::from_millis(50), op.copy("from", "to"))
+            .await
+            .expect("copy should proceed once permit is released")
+            .expect("copy should succeed");
+        timeout(Duration::from_millis(50), op.rename("from", "to"))
+            .await
+            .expect("rename should proceed once permit is released")
+            .expect("rename should succeed");
+    }
+
     #[tokio::test]
     async fn concurrent_chunked_read_with_http_limit() {
         use opendal_core::raw::*;