From 32d13996925f36c639b5efa63316c62f4874a497 Mon Sep 17 00:00:00 2001 From: Au Date: Sat, 16 Sep 2023 11:51:26 +0800 Subject: [PATCH] feat(services/azblob): Rewrite azblob methods signature using OpRead/OpStat (#3072) * feat(services/azblob)!: rewrite azblob methods signature using OpRead/OpStat * chore(services/azblob): remove redundant code * feat(services/azblob): use OpStat instead of OpRead in azblob_get_blob_properties --- core/src/services/azblob/backend.rs | 29 +++----------------- core/src/services/azblob/core.rs | 41 +++++++++-------------------- core/src/services/azblob/writer.rs | 2 +- 3 files changed, 17 insertions(+), 55 deletions(-) diff --git a/core/src/services/azblob/backend.rs b/core/src/services/azblob/backend.rs index 967cdd7127b0..627d6fb02c49 100644 --- a/core/src/services/azblob/backend.rs +++ b/core/src/services/azblob/backend.rs @@ -580,16 +580,7 @@ impl Accessor for AzblobBackend { } async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> { - let resp = self - .core - .azblob_get_blob( - path, - args.range(), - args.if_none_match(), - args.if_match(), - args.override_content_disposition(), - ) - .await?; + let resp = self.core.azblob_get_blob(path, &args).await?; let status = resp.status(); @@ -634,10 +625,7 @@ impl Accessor for AzblobBackend { return Ok(RpStat::new(Metadata::new(EntryMode::DIR))); } - let resp = self - .core - .azblob_get_blob_properties(path, args.if_none_match(), args.if_match()) - .await?; + let resp = self.core.azblob_get_blob_properties(path, &args).await?; let status = resp.status(); @@ -674,17 +662,8 @@ impl Accessor for AzblobBackend { async fn presign(&self, path: &str, args: OpPresign) -> Result { let mut req = match args.operation() { - PresignOperation::Stat(v) => { - self.core - .azblob_head_blob_request(path, v.if_none_match(), v.if_match())? - } - PresignOperation::Read(v) => self.core.azblob_get_blob_request( - path, - v.range(), - v.if_none_match(), - v.if_match(), - v.override_content_disposition(), - )?, + PresignOperation::Stat(v) => self.core.azblob_head_blob_request(path, v)?, + PresignOperation::Read(v) => self.core.azblob_get_blob_request(path, v)?, PresignOperation::Write(_) => self.core.azblob_put_blob_request( path, None, diff --git a/core/src/services/azblob/core.rs b/core/src/services/azblob/core.rs index e493ff1abe2f..7db0556602e3 100644 --- a/core/src/services/azblob/core.rs +++ b/core/src/services/azblob/core.rs @@ -157,14 +157,7 @@ impl AzblobCore { } impl AzblobCore { - pub fn azblob_get_blob_request( - &self, - path: &str, - range: BytesRange, - if_none_match: Option<&str>, - if_match: Option<&str>, - override_content_disposition: Option<&str>, - ) -> Result> { + pub fn azblob_get_blob_request(&self, path: &str, args: &OpRead) -> Result> { let p = build_abs_path(&self.root, path); let mut url = format!( @@ -175,7 +168,7 @@ impl AzblobCore { ); let mut query_args = Vec::new(); - if let Some(override_content_disposition) = override_content_disposition { + if let Some(override_content_disposition) = args.override_content_disposition() { query_args.push(format!( "rscd={}", percent_encode_path(override_content_disposition) @@ -191,6 +184,7 @@ impl AzblobCore { // Set SSE headers. req = self.insert_sse_headers(req); + let range = args.range(); if !range.is_full() { // azblob doesn't support read with suffix range. // @@ -205,11 +199,11 @@ impl AzblobCore { req = req.header(http::header::RANGE, range.to_header()); } - if let Some(if_none_match) = if_none_match { + if let Some(if_none_match) = args.if_none_match() { req = req.header(IF_NONE_MATCH, if_none_match); } - if let Some(if_match) = if_match { + if let Some(if_match) = args.if_match() { req = req.header(IF_MATCH, if_match); } @@ -223,18 +217,9 @@ impl AzblobCore { pub async fn azblob_get_blob( &self, path: &str, - range: BytesRange, - if_none_match: Option<&str>, - if_match: Option<&str>, - override_content_disposition: Option<&str>, + args: &OpRead, ) -> Result> { - let mut req = self.azblob_get_blob_request( - path, - range, - if_none_match, - if_match, - override_content_disposition, - )?; + let mut req = self.azblob_get_blob_request(path, args)?; self.sign(&mut req).await?; @@ -387,8 +372,7 @@ impl AzblobCore { pub fn azblob_head_blob_request( &self, path: &str, - if_none_match: Option<&str>, - if_match: Option<&str>, + args: &OpStat, ) -> Result> { let p = build_abs_path(&self.root, path); @@ -404,11 +388,11 @@ impl AzblobCore { // Set SSE headers. req = self.insert_sse_headers(req); - if let Some(if_none_match) = if_none_match { + if let Some(if_none_match) = args.if_none_match() { req = req.header(IF_NONE_MATCH, if_none_match); } - if let Some(if_match) = if_match { + if let Some(if_match) = args.if_match() { req = req.header(IF_MATCH, if_match); } @@ -422,10 +406,9 @@ impl AzblobCore { pub async fn azblob_get_blob_properties( &self, path: &str, - if_none_match: Option<&str>, - if_match: Option<&str>, + args: &OpStat, ) -> Result> { - let mut req = self.azblob_head_blob_request(path, if_none_match, if_match)?; + let mut req = self.azblob_head_blob_request(path, args)?; self.sign(&mut req).await?; self.send(req).await diff --git a/core/src/services/azblob/writer.rs b/core/src/services/azblob/writer.rs index bfcde2007d46..d78ae8dc7f9b 100644 --- a/core/src/services/azblob/writer.rs +++ b/core/src/services/azblob/writer.rs @@ -75,7 +75,7 @@ impl oio::AppendObjectWrite for AzblobWriter { async fn offset(&self) -> Result { let resp = self .core - .azblob_get_blob_properties(&self.path, None, None) + .azblob_get_blob_properties(&self.path, &OpStat::default()) .await?; let status = resp.status();