Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

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

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 check_table_not_found<T>(result: Result<T>) -> std::result::Result<T, BackoffError<Error>> {
CriesofCarrots marked this conversation as resolved.
Show resolved Hide resolved
if let Err(Error::Rpc(ref err)) = result {
CriesofCarrots marked this conversation as resolved.
Show resolved Hide resolved
if err.code() == tonic::Code::NotFound && err.message().starts_with("table") {
return Err(BackoffError::Permanent(Error::Rpc(err.clone())));
}
}
Ok(result?)
}

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;
check_table_not_found(result)
CriesofCarrots marked this conversation as resolved.
Show resolved Hide resolved
})
.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;
check_table_not_found(result)
})
.await
}
Expand Down