Skip to content

Commit

Permalink
feat(services/azblob): Rewrite azblob methods signature using OpRead/…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
acehinnnqru authored Sep 16, 2023
1 parent 055e430 commit 32d1399
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 55 deletions.
29 changes: 4 additions & 25 deletions core/src/services/azblob/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -674,17 +662,8 @@ impl Accessor for AzblobBackend {

async fn presign(&self, path: &str, args: OpPresign) -> Result<RpPresign> {
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,
Expand Down
41 changes: 12 additions & 29 deletions core/src/services/azblob/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Request<AsyncBody>> {
pub fn azblob_get_blob_request(&self, path: &str, args: &OpRead) -> Result<Request<AsyncBody>> {
let p = build_abs_path(&self.root, path);

let mut url = format!(
Expand All @@ -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)
Expand All @@ -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.
//
Expand All @@ -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);
}

Expand All @@ -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<Response<IncomingAsyncBody>> {
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?;

Expand Down Expand Up @@ -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<Request<AsyncBody>> {
let p = build_abs_path(&self.root, path);

Expand All @@ -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);
}

Expand All @@ -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<Response<IncomingAsyncBody>> {
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
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/azblob/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl oio::AppendObjectWrite for AzblobWriter {
async fn offset(&self) -> Result<u64> {
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();
Expand Down

0 comments on commit 32d1399

Please sign in to comment.