Skip to content

Commit bb62e31

Browse files
authored
[ENH] Explicitly convert SlowDown from S3 to StorageError::Backoff (#5377)
## Description of changes Amazon periodically tells us to slow down and that manifests as a gruesome error trace. Make a specific error type so callers can handle the error. ## Test plan CI ## Migration plan N/A ## Observability plan N/A ## Documentation Changes N/A
1 parent 9c4e772 commit bb62e31

File tree

2 files changed

+50
-28
lines changed

2 files changed

+50
-28
lines changed

rust/storage/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ pub enum StorageError {
145145
/// The configuration key used
146146
key: String,
147147
},
148+
149+
// Back off and retry---usually indicates an explicit 429/SlowDown.
150+
#[error("Back off and retry---usually indicates an explicit 429/SlowDown.")]
151+
Backoff,
148152
}
149153

150154
impl ChromaError for StorageError {
@@ -163,6 +167,7 @@ impl ChromaError for StorageError {
163167
StorageError::PermissionDenied { .. } => ErrorCodes::PermissionDenied,
164168
StorageError::Unauthenticated { .. } => ErrorCodes::Unauthenticated,
165169
StorageError::UnknownConfigurationKey { .. } => ErrorCodes::InvalidArgument,
170+
StorageError::Backoff { .. } => ErrorCodes::ResourceExhausted,
166171
}
167172
}
168173
}

rust/storage/src/s3.rs

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -238,36 +238,40 @@ impl S3Storage {
238238
res.e_tag.map(ETag),
239239
))
240240
}
241-
Err(e) => {
242-
match e {
243-
SdkError::ServiceError(err) => {
244-
let inner = err.into_err();
245-
match &inner {
246-
aws_sdk_s3::operation::get_object::GetObjectError::NoSuchKey(_) => {
247-
Err(StorageError::NotFound {
248-
path: key.to_string(),
249-
source: Arc::new(inner),
250-
})
251-
}
252-
aws_sdk_s3::operation::get_object::GetObjectError::InvalidObjectState(msg) => {
253-
tracing::error!("invalid object state: {}", msg);
254-
Err(StorageError::Generic {
255-
source: Arc::new(inner),
256-
})
257-
}
258-
_ => {
241+
Err(e) => match e {
242+
SdkError::ServiceError(err) => {
243+
let inner = err.into_err();
244+
match &inner {
245+
aws_sdk_s3::operation::get_object::GetObjectError::NoSuchKey(_) => {
246+
Err(StorageError::NotFound {
247+
path: key.to_string(),
248+
source: Arc::new(inner),
249+
})
250+
}
251+
aws_sdk_s3::operation::get_object::GetObjectError::InvalidObjectState(
252+
msg,
253+
) => {
254+
tracing::error!("invalid object state: {}", msg);
255+
Err(StorageError::Generic {
256+
source: Arc::new(inner),
257+
})
258+
}
259+
_ => {
260+
if inner.code() == Some("SlowDown") {
261+
Err(StorageError::Backoff)
262+
} else {
259263
tracing::error!("error: {}", inner.to_string());
260264
Err(StorageError::Generic {
261265
source: Arc::new(inner),
262266
})
263267
}
264268
}
265269
}
266-
_ => Err(StorageError::Generic {
267-
source: Arc::new(e),
268-
}),
269270
}
270-
}
271+
_ => Err(StorageError::Generic {
272+
source: Arc::new(e),
273+
}),
274+
},
271275
}
272276
}
273277

@@ -350,9 +354,13 @@ impl S3Storage {
350354
})
351355
}
352356
_ => {
353-
Err(StorageError::Generic {
354-
source: Arc::new(inner),
355-
})
357+
if inner.code() == Some("SlowDown") {
358+
Err(StorageError::Backoff)
359+
} else {
360+
Err(StorageError::Generic {
361+
source: Arc::new(inner),
362+
})
363+
}
356364
}
357365
}
358366
}
@@ -602,6 +610,8 @@ impl S3Storage {
602610
path: key.to_string(),
603611
source: Arc::new(err),
604612
}
613+
} else if err.meta().code() == Some("SlowDown") {
614+
StorageError::Backoff
605615
} else {
606616
StorageError::Generic {
607617
source: Arc::new(err),
@@ -793,6 +803,7 @@ impl S3Storage {
793803
path: key.to_string(),
794804
source: Arc::new(inner),
795805
}),
806+
Some("SlowDown") => Err(StorageError::Backoff),
796807
_ => {
797808
tracing::error!(error = %inner, key = %key, "Failed to delete object from S3");
798809
Err(StorageError::Generic {
@@ -864,9 +875,15 @@ impl S3Storage {
864875
tracing::trace!("Successfully deleted objects from S3");
865876
Ok(out)
866877
}
867-
Err(e) => Err(StorageError::Generic {
868-
source: Arc::new(e),
869-
}),
878+
Err(e) => {
879+
if e.code() == Some("SlowDown") {
880+
Err(StorageError::Backoff)
881+
} else {
882+
Err(StorageError::Generic {
883+
source: Arc::new(e),
884+
})
885+
}
886+
}
870887
}
871888
}
872889

0 commit comments

Comments
 (0)