storage-bigtable: Return error if attempting to write to table NotFound (#34098)

* Add helper fn to stop retrying if table not found

* Use helper in put_cells_with_retry methods

* Review suggestions
This commit is contained in:
Tyera 2023-11-15 23:15:57 -07:00 committed by GitHub
parent e790f098b8
commit 6fc6a49c05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 3 deletions

View File

@ -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,
@ -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)
@ -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
}
@ -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
}