kparisa commented on code in PR #4394: URL: https://github.com/apache/iggy/pull/4394#discussion_r4175754498
########## core/connectors/sinks/bigquery_sink/src/error.rs: ########## @@ -0,0 +1,207 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Failure classification for BigQuery calls. +//! +//! Only transient failures are retried. Retrying a permanent one (bad +//! schema, missing permission) cannot succeed and only delays the error. + +use crate::schema::SchemaError; +use gcloud_gax::grpc::{Code, Status}; +use iggy_connector_sdk::Error; +use std::fmt; + +/// An `AppendRows` call that did not append. Row-level errors are not part +/// of this type: they are an expected outcome the caller handles by +/// dropping the reported rows. +#[derive(Debug, Clone, PartialEq, Eq)] +pub(crate) enum AppendError { + /// The call failed, or the response carried an error status. + Rpc { code: Code, message: String }, + /// The response stream closed without a response. + NoResponse, +} + +/// A `tables.get` call that did not return a usable schema. +#[derive(Debug, Clone, PartialEq, Eq)] +pub(crate) enum TableError { + Http { status: u16, body: String }, + Transport(String), + Token(String), + Schema(SchemaError), +} + +impl AppendError { + pub(crate) fn is_retryable(&self) -> bool { + match self { + AppendError::Rpc { code, .. } => is_retryable_code(*code), + // The append may or may not have landed. Retrying risks a + // duplicate, which the delivery guarantees allow. + AppendError::NoResponse => true, + } + } +} + +impl TableError { + pub(crate) fn is_retryable(&self) -> bool { + match self { + TableError::Http { status, .. } => *status == 429 || *status >= 500, + TableError::Transport(_) => true, + TableError::Token(_) | TableError::Schema(_) => false, Review Comment: fixed -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
