Skip to content

Commit

Permalink
storage-bigtable: Return error if attempting to write to table NotFou…
Browse files Browse the repository at this point in the history
…nd (#34098)

* Add helper fn to stop retrying if table not found

* Use helper in put_cells_with_retry methods

* Review suggestions
  • Loading branch information
CriesofCarrots authored Nov 16, 2023
1 parent e790f09 commit 6fc6a49
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions storage-bigtable/src/bigtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
compression::{compress_best, decompress},
root_ca_certificate, CredentialType,
},
backoff::{future::retry, ExponentialBackoff},
backoff::{future::retry, Error as BackoffError, ExponentialBackoff},
log::*,
std::{
str::FromStr,
Expand Down Expand Up @@ -84,6 +84,15 @@ pub enum Error {
Timeout,
}

fn to_backoff_err(err: Error) -> BackoffError<Error> {
if let Error::Rpc(ref status) = err {
if status.code() == tonic::Code::NotFound && status.message().starts_with("table") {
return BackoffError::Permanent(err);
}
}
err.into()
}

impl std::convert::From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self {
Self::Io(err)
Expand Down Expand Up @@ -265,7 +274,8 @@ impl BigTableConnection {
{
retry(ExponentialBackoff::default(), || async {
let mut client = self.client();
Ok(client.put_bincode_cells(table, cells).await?)
let result = client.put_bincode_cells(table, cells).await;
result.map_err(to_backoff_err)
})
.await
}
Expand Down Expand Up @@ -303,7 +313,8 @@ impl BigTableConnection {
{
retry(ExponentialBackoff::default(), || async {
let mut client = self.client();
Ok(client.put_protobuf_cells(table, cells).await?)
let result = client.put_protobuf_cells(table, cells).await;
result.map_err(to_backoff_err)
})
.await
}
Expand Down

0 comments on commit 6fc6a49

Please sign in to comment.