fix: avoid panic when no region found in table (#1359)

This commit is contained in:
Lei, HUANG
2023-04-11 16:58:18 +08:00
committed by GitHub
parent a90798a2c1
commit 3e8ec8b73a
2 changed files with 17 additions and 2 deletions

View File

@@ -39,7 +39,9 @@ use store_api::storage::{
RegionMeta, RegionNumber, ScanRequest, SchemaRef, Snapshot, WriteContext, WriteRequest,
};
use table::error as table_error;
use table::error::{RegionSchemaMismatchSnafu, Result as TableResult, TableOperationSnafu};
use table::error::{
InvalidTableSnafu, RegionSchemaMismatchSnafu, Result as TableResult, TableOperationSnafu,
};
use table::metadata::{
FilterPushDownType, RawTableInfo, TableInfo, TableInfoRef, TableMeta, TableType,
};
@@ -193,7 +195,10 @@ impl<R: Region> Table for MitoTable<R> {
// TODO(hl): we assume table contains at least one region, but with region migration this
// assumption may become invalid.
let stream_schema = first_schema.unwrap();
let stream_schema = first_schema.context(InvalidTableSnafu {
table_id: table_info.ident.table_id,
})?;
let schema = stream_schema.clone();
let stream = Box::pin(async_stream::try_stream! {
for mut reader in readers {

View File

@@ -20,6 +20,8 @@ use datafusion::error::DataFusionError;
use datatypes::arrow::error::ArrowError;
use snafu::Location;
use crate::metadata::TableId;
pub type Result<T> = std::result::Result<T, Error>;
/// Default error implementation of table.
@@ -106,6 +108,7 @@ pub enum Error {
column_name: String,
location: Location,
},
#[snafu(display("Regions schemas mismatch in table: {}", table))]
RegionSchemaMismatch { table: String, location: Location },
@@ -121,6 +124,12 @@ pub enum Error {
value: String,
location: Location,
},
#[snafu(display("Invalid table state: {}", table_id))]
InvalidTable {
table_id: TableId,
location: Location,
},
}
impl ErrorExt for Error {
@@ -143,6 +152,7 @@ impl ErrorExt for Error {
Error::ParseTableOption { .. }
| Error::EngineNotFound { .. }
| Error::EngineExist { .. } => StatusCode::InvalidArguments,
Error::InvalidTable { .. } => StatusCode::Internal,
}
}