mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-18 05:50:41 +00:00
fix: avoid panic when no region found in table (#1359)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user