HomePhabricator
Diffusion Comm 70fe71c01bb0

[services-lib] Add methods to manage blob holders

Description

[services-lib] Add methods to manage blob holders

Summary:
Part of ENG-4597.

Added functions to add / revoke blob holders for a blob. Also, added a simple utility function to create a holder and upload a blob if it doesn't exist - this is the most common usecase.

Depends on D8779

Test Plan:
Test code

let client = BlobServiceClient::new("http://localhost:50053".parse()?);

let blob_hash = "hello".to_string();
let holder = "world".to_string();

let stream = async_stream::stream! {
  yield Result::<Vec<u8>, std::io::Error>::Ok(vec![1, 2, 3]);
  yield Ok(vec![4, 5, 6]);
  yield Err(std::io::Error::new(std::io::ErrorKind::Other, "test"));
};

client.assign_holder(&blob_hash, &holder).await?;
client.upload_blob(&blob_hash, stream).await.map_err(|e| {
  println!("Error: {0:?} --- {0}", e);
  e
})?;

let mut stream = client.get("hello").await?;
while let Some(data) = stream.try_next().await? {
  println!("Got data: {:?}", data);
}

client.revoke_holder(&blob_hash, &holder).await?;

Reviewers: michal, jon

Reviewed By: michal

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D8780

Details

Provenance
bartekAuthored on Aug 10 2023, 9:38 AM
Reviewer
michal
Differential Revision
D8780: [services-lib] Add methods to manage blob holders
Parents
rCOMMbff4ab0fddbf: [services-lib] Add method to upload blobs
Branches
Unknown
Tags
Unknown