Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(batch): ensure user-facing context is always present for external system errors #18982

Merged
merged 6 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
30 changes: 13 additions & 17 deletions src/batch/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::sync::Arc;
pub use anyhow::anyhow;
use parquet::errors::ParquetError;
use risingwave_common::array::ArrayError;
use risingwave_common::error::BoxedError;
use risingwave_common::error::{def_anyhow_newtype, def_anyhow_variant, BoxedError};
use risingwave_common::util::value_encoding::error::ValueEncodingError;
use risingwave_connector::error::ConnectorError;
use risingwave_dml::error::DmlError;
Expand Down Expand Up @@ -115,24 +115,10 @@ pub enum BatchError {
),

#[error(transparent)]
Iceberg(
ExternalSystemError(
#[from]
#[backtrace]
iceberg::Error,
),

#[error(transparent)]
Parquet(
#[from]
#[backtrace]
ParquetError,
),

#[error(transparent)]
Postgres(
#[from]
#[backtrace]
tokio_postgres::Error,
BatchExternalSystemError,
),

// Make the ref-counted type to be a variant for easier code structuring.
Expand Down Expand Up @@ -200,3 +186,13 @@ impl From<ConnectorError> for BatchError {
Self::Connector(value.into())
}
}

// Define a external system error
def_anyhow_variant! {
pub BatchExternalSystemError,
BatchError ExternalSystemError,

tokio_postgres::Error => "Postgres Batch Query Error",
kwannoel marked this conversation as resolved.
Show resolved Hide resolved
iceberg::Error => "Iceberg Batch Query Error",
ParquetError => "Parquet Batch Query Error",
}
22 changes: 7 additions & 15 deletions src/batch/src/executor/iceberg_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,10 @@ impl IcebergScanExecutor {
.build();
let file_scan_stream = tokio_stream::once(Ok(data_file_scan_task));

let mut record_batch_stream = reader
.read(Box::pin(file_scan_stream))
.map_err(BatchError::Iceberg)?
.enumerate();
let mut record_batch_stream = reader.read(Box::pin(file_scan_stream))?.enumerate();

while let Some((index, record_batch)) = record_batch_stream.next().await {
let record_batch = record_batch.map_err(BatchError::Iceberg)?;
let record_batch = record_batch?;

let chunk = IcebergArrowConvert.chunk_from_record_batch(&record_batch)?;
// position delete
Expand Down Expand Up @@ -195,8 +192,7 @@ impl BoxedExecutorBuilder for IcebergScanExecutorBuilder {
source_node.with_properties.clone(),
source_node.secret_refs.clone(),
);
let config = ConnectorProperties::extract(options_with_secret.clone(), false)
.map_err(BatchError::connector)?;
let config = ConnectorProperties::extract(options_with_secret.clone(), false)?;

let split_list = source_node
.split
Expand Down Expand Up @@ -279,12 +275,10 @@ impl PositionDeleteFilter {

let reader = table.reader_builder().with_batch_size(batch_size).build();

let mut record_batch_stream = reader
.read(Box::pin(position_delete_file_scan_stream))
.map_err(BatchError::Iceberg)?;
let mut record_batch_stream = reader.read(Box::pin(position_delete_file_scan_stream))?;

while let Some(record_batch) = record_batch_stream.next().await {
let record_batch = record_batch.map_err(BatchError::Iceberg)?;
let record_batch = record_batch?;
let chunk = IcebergArrowConvert.chunk_from_record_batch(&record_batch)?;
for row in chunk.rows() {
// The schema is fixed. `0` must be `file_path`, `1` must be `pos`.
Expand Down Expand Up @@ -382,12 +376,10 @@ impl EqualityDeleteFilter {
let reader = table.reader_builder().with_batch_size(batch_size).build();
let delete_file_scan_stream = tokio_stream::once(Ok(equality_delete_file_scan_task));

let mut delete_record_batch_stream = reader
.read(Box::pin(delete_file_scan_stream))
.map_err(BatchError::Iceberg)?;
let mut delete_record_batch_stream = reader.read(Box::pin(delete_file_scan_stream))?;

while let Some(record_batch) = delete_record_batch_stream.next().await {
let record_batch = record_batch.map_err(BatchError::Iceberg)?;
let record_batch = record_batch?;

let chunk = IcebergArrowConvert.chunk_from_record_batch(&record_batch)?;
for row in chunk.rows() {
Expand Down
2 changes: 1 addition & 1 deletion src/batch/src/executor/s3_file_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl S3FileScanExecutor {

#[for_await]
for record_batch in record_batch_stream {
let record_batch = record_batch.map_err(BatchError::Parquet)?;
let record_batch = record_batch?;
let chunk = IcebergArrowConvert.chunk_from_record_batch(&record_batch)?;
debug_assert_eq!(chunk.data_types(), self.schema.data_types());
yield chunk;
Expand Down
28 changes: 27 additions & 1 deletion src/error/src/anyhow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,30 @@ macro_rules! def_anyhow_newtype {
)*
};
}
pub use def_anyhow_newtype;

/// Define a newtype + it's variant in the specified type.
/// This is useful when you want to define a new error type,
/// but also want to define a variant for it in another enum.
#[macro_export]
macro_rules! def_anyhow_variant {
(
$(#[$attr:meta])* $vis:vis $name:ident,
$enum_name:ident $variant_name:ident
$(, $from:ty => $context:tt)* $(,)?
) => {
def_anyhow_newtype! {
$(#[$attr])* $vis $name
$(, $from => $context)*
}

$(
impl From<$from> for $enum_name {
fn from(error: $from) -> Self {
todo!()
}
}
)*
kwannoel marked this conversation as resolved.
Show resolved Hide resolved
}
}

pub use {def_anyhow_newtype, def_anyhow_variant};
Loading