Page MenuHomePhabricator

D5702.id18726.diff
No OneTemporary

D5702.id18726.diff

diff --git a/services/blob/src/service.rs b/services/blob/src/service.rs
--- a/services/blob/src/service.rs
+++ b/services/blob/src/service.rs
@@ -153,8 +153,67 @@
async fn remove(
&self,
- _request: Request<blob::RemoveRequest>,
+ request: Request<blob::RemoveRequest>,
) -> Result<Response<()>, Status> {
- Err(Status::unimplemented("Not implemented yet"))
+ let message = request.into_inner();
+ let holder = message.holder.as_str();
+ let reverse_index_item = self
+ .db
+ .find_reverse_index_by_holder(holder)
+ .await
+ .map_err(|e| {
+ Status::internal(format!("Failed to find holder: {}", e.to_string()))
+ })?
+ .ok_or_else(|| {
+ Status::not_found(format!("Blob for holder [{}] doesn't exist", holder))
+ })?;
+ let blob_hash = &reverse_index_item.blob_hash;
+
+ if let Err(err) = self.db.remove_reverse_index_item(holder).await {
+ return Err(Status::internal(format!(
+ "Failed to remove holder from db: {}",
+ err.to_string()
+ )));
+ }
+
+ // TODO handle cleanup here properly
+ // for now the object's being removed right away
+ // after the last holder was removed
+ if self
+ .db
+ .find_reverse_index_by_hash(blob_hash)
+ .await
+ .map_err(|e| {
+ Status::internal(format!("Failed to list holders: {}", e.to_string()))
+ })?
+ .is_empty()
+ {
+ let s3_path = self
+ .find_s3_path_by_reverse_index(&reverse_index_item)
+ .await?;
+
+ self
+ .s3
+ .delete_object()
+ .bucket(&s3_path.bucket_name)
+ .key(&s3_path.object_name)
+ .send()
+ .await
+ .map_err(|e| {
+ Status::internal(format!(
+ "Failed to delete blob from S3: {}",
+ e.to_string()
+ ))
+ })?;
+
+ if let Err(err) = self.db.remove_blob_item(blob_hash).await {
+ return Err(Status::internal(format!(
+ "Failed to remove blob entry from db: {}",
+ err.to_string()
+ )));
+ }
+ }
+
+ Ok(Response::new(()))
}
}

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 21, 2:38 PM (20 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2688047
Default Alt Text
D5702.id18726.diff (2 KB)

Event Timeline