Skip to content

Commit

Permalink
[blob-service] Add S3 helpers, improve logs
Browse files Browse the repository at this point in the history
Summary:
Minor convenience functions for S3 path type conversioons and some more logs

Depends on D8440

Test Plan: Will be tested later in the stack

Reviewers: michal, jon, varun, patryk

Reviewed By: varun

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D8441
  • Loading branch information
barthap committed Jul 21, 2023
1 parent 168a79a commit 548b55a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions services/blob/src/database/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub enum Error {
#[display(...)]
Attribute(DBItemError),
#[display(...)]
#[from(ignore)]
Blob(BlobDBError),
#[display(...)]
ItemAlreadyExists,
Expand All @@ -37,3 +38,9 @@ impl Display for BlobDBError {
}

impl std::error::Error for BlobDBError {}

impl From<S3PathError> for Error {
fn from(err: S3PathError) -> Self {
Error::Blob(BlobDBError::InvalidS3Path(err))
}
}
23 changes: 22 additions & 1 deletion services/blob/src/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
ops::{Bound, RangeBounds},
sync::Arc,
};
use tracing::error;
use tracing::{debug, error, trace};

#[derive(
Debug, derive_more::Display, derive_more::From, derive_more::Error,
Expand Down Expand Up @@ -85,6 +85,19 @@ impl S3Path {
}
}

impl From<&S3Path> for String {
fn from(s3_path: &S3Path) -> Self {
s3_path.to_full_path()
}
}

impl TryFrom<&str> for S3Path {
type Error = S3PathError;
fn try_from(full_path: &str) -> Result<Self, Self::Error> {
Self::from_full_path(full_path)
}
}

#[derive(Clone)]
pub struct S3Client {
client: Arc<aws_sdk_s3::Client>,
Expand Down Expand Up @@ -220,6 +233,7 @@ impl MultiPartUploadSession {
error!("Upload ID expected to be present");
Error::MissingUploadID
})?;
debug!("Started multipart upload session with ID: {}", upload_id);

Ok(MultiPartUploadSession {
client: client.clone(),
Expand Down Expand Up @@ -253,6 +267,12 @@ impl MultiPartUploadSession {
.e_tag(upload_result.e_tag.unwrap_or_default())
.part_number(part_number)
.build();
trace!(
upload_id = self.upload_id,
e_tag = completed_part.e_tag.as_deref().unwrap_or("N/A"),
"Uploaded part {}.",
part_number
);
self.upload_parts.push(completed_part);
Ok(())
}
Expand Down Expand Up @@ -281,6 +301,7 @@ impl MultiPartUploadSession {
Error::AwsSdk(e.into())
})?;

debug!(upload_id = self.upload_id, "Multipart upload complete");
Ok(())
}
}
Expand Down

0 comments on commit 548b55a

Please sign in to comment.