From 6fc6a49c05405df1408a36453966e42cbf00e47e Mon Sep 17 00:00:00 2001 From: Tyera Date: Wed, 15 Nov 2023 23:15:57 -0700 Subject: [PATCH] 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 --- storage-bigtable/src/bigtable.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/storage-bigtable/src/bigtable.rs b/storage-bigtable/src/bigtable.rs index fd17cfa8dd2568..c43ada4fabe047 100644 --- a/storage-bigtable/src/bigtable.rs +++ b/storage-bigtable/src/bigtable.rs @@ -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 { + 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 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 }