Skip to content

Commit

Permalink
save work
Browse files Browse the repository at this point in the history
  • Loading branch information
wcy-fdu committed Feb 14, 2024
1 parent dd250c3 commit 98c0597
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 40 deletions.
49 changes: 18 additions & 31 deletions core/src/services/azblob/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,45 +426,32 @@ impl AzblobCore {
block_ids: Vec<Uuid>,
) -> Result<Request<AsyncBody>> {
let p = build_abs_path(&self.root, path);
let first_block_id = format!("{}{}", p, block_ids[0].clone());

let sources: Vec<String> = block_ids[1..]
.iter()
.map(|s| format!("{}{}", p, s))
.collect();
// concat blocks
let req = self.concat_block_list_request(&first_block_id, sources)?;
Ok(req)
// self.sign(&mut req).await?;

// let resp = self.send(req).await?;
// let status = resp.status();
}

/// CONCAT will concat sources to the path
pub fn concat_block_list_request(
&self,
path: &str,
sources: Vec<String>,
) -> Result<Request<AsyncBody>> {
let p = build_abs_path(&self.root, path);

let sources = sources
.iter()
.map(|p| build_rooted_abs_path(&self.root, p))
.collect::<Vec<String>>()
.join(",");

let url = format!(
"{}/{}/{}?comp=blocklist",
self.endpoint,
self.container,
percent_encode_path(&p)
);

let req = Request::post(url);
let req = Request::post(&url);

// Set SSE headers.
let req = self.insert_sse_headers(req);

// Set body
let mut req_body = "".to_string();
req_body.push_str("<BlockList>\n");

req.body(AsyncBody::Empty).map_err(new_request_build_error)
for block_id in block_ids {
req_body.push_str("<Uncommitted>");
req_body.push_str(&block_id.to_string());
req_body.push_str("</Uncommitted>\n");
}

req_body.push_str("</BlockList>");
let body = AsyncBody::Bytes(Bytes::from(req_body.to_string()));
let req = req.body(body).map_err(new_request_build_error)?;
Ok(req)
}

pub async fn azblob_complete_put_block_list(
Expand Down
10 changes: 1 addition & 9 deletions core/src/services/azblob/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,14 @@ impl oio::BlockWrite for AzblobWriter {
}

async fn complete_block(&self, block_ids: Vec<Uuid>) -> Result<()> {
if block_ids.len() < 2 {
return Err(Error::new(
ErrorKind::ConditionNotMatch,
"block list length is less than 2",
));
}
let resp = self
.core
.azblob_complete_put_block_list(&self.path, block_ids)
.await?;

let status = resp.status();

let status = resp.status();
match status {
StatusCode::OK => {
StatusCode::CREATED | StatusCode::OK => {
resp.into_body().consume().await?;
Ok(())
}
Expand Down

0 comments on commit 98c0597

Please sign in to comment.