[pbs-devel] [PATCH proxmox v9 3/3] s3 client: wrap upload with retry into dedicated methods
Christian Ebner
c.ebner at proxmox.com
Sat Jul 19 14:49:49 CEST 2025
The `replace` boolean flag in the upload_with_retry() method
signature unfortunately is not very ergonomic and hinders code
readability.
Therefore, wrap the method into helpers covering both variants,
encoding their behaviour in the method name instead.
As the client is currently only used by the Proxmox Backup Server's
s3 backend, the code not being applied just yet, it is fine to drop
the previous public method althogehter without much further adaptions.
Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
changes since version 8:
- not present in previous version
proxmox-s3-client/src/client.rs | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/proxmox-s3-client/src/client.rs b/proxmox-s3-client/src/client.rs
index 08e45ebf..5e9d7cb2 100644
--- a/proxmox-s3-client/src/client.rs
+++ b/proxmox-s3-client/src/client.rs
@@ -585,8 +585,36 @@ impl S3Client {
Ok(delete_errors)
}
- /// Upload the given object via the S3 api, retrying up to 3 times in case of error.
- pub async fn upload_with_retry(
+ /// Upload the given object via the S3 api, not replacing it if already present in the object
+ /// store.
+ /// Retrying up to 3 times in case of error.
+ #[inline(always)]
+ pub async fn upload_no_replace_with_retry(
+ &self,
+ object_key: S3ObjectKey,
+ object_data: Bytes,
+ ) -> Result<bool, Error> {
+ let replace = false;
+ self.do_upload_with_retry(object_key, object_data, replace)
+ .await
+ }
+
+ /// Upload the given object via the S3 api, replacing it if already present in the object store.
+ /// Retrying up to 3 times in case of error.
+ #[inline(always)]
+ pub async fn upload_replace_with_retry(
+ &self,
+ object_key: S3ObjectKey,
+ object_data: Bytes,
+ ) -> Result<bool, Error> {
+ let replace = true;
+ self.do_upload_with_retry(object_key, object_data, replace)
+ .await
+ }
+
+ /// Helper to perform the object upload and retry, wrapped by the corresponding methods
+ /// to mask the `replace` flag.
+ async fn do_upload_with_retry(
&self,
object_key: S3ObjectKey,
object_data: Bytes,
--
2.47.2
More information about the pbs-devel
mailing list