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

fix: throw errors instead of panic #3391

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 21 additions & 9 deletions src/common/meta/src/ddl/create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,24 @@ impl CreateTableProcedure {
self.table_info().ident.table_id
}

fn region_wal_options(&self) -> Option<&HashMap<RegionNumber, String>> {
self.creator.data.region_wal_options.as_ref()
fn region_wal_options(&self) -> Result<&HashMap<RegionNumber, String>> {
self.creator
.data
.region_wal_options
.as_ref()
.context(error::UnexpectedSnafu {
err_msg: "region_wal_options is not allocated",
})
}

fn table_route(&self) -> Option<&TableRouteValue> {
self.creator.data.table_route.as_ref()
fn table_route(&self) -> Result<&TableRouteValue> {
self.creator
.data
.table_route
.as_ref()
.context(error::UnexpectedSnafu {
err_msg: "table_route is not allocated",
})
}

#[cfg(any(test, feature = "testing"))]
Expand Down Expand Up @@ -181,7 +193,7 @@ impl CreateTableProcedure {
/// - [Code::Unavailable](tonic::status::Code::Unavailable)
pub async fn on_datanode_create_regions(&mut self) -> Result<Status> {
// Safety: the table route must be allocated.
match &self.creator.data.table_route.clone().unwrap() {
match self.table_route()?.clone() {
TableRouteValue::Physical(x) => {
let region_routes = x.region_routes.clone();
let request_builder = self.new_region_request_builder(None)?;
Expand Down Expand Up @@ -214,7 +226,7 @@ impl CreateTableProcedure {
request_builder: CreateRequestBuilder,
) -> Result<Status> {
// Safety: the table_route must be allocated.
if self.table_route().unwrap().is_physical() {
if self.table_route()?.is_physical() {
// Registers opening regions
let guards = self
.creator
Expand All @@ -226,7 +238,7 @@ impl CreateTableProcedure {

let create_table_data = &self.creator.data;
// Safety: the region_wal_options must be allocated
let region_wal_options = self.region_wal_options().unwrap();
let region_wal_options = self.region_wal_options()?;
let create_table_expr = &create_table_data.task.create_table;
let catalog = &create_table_expr.catalog_name;
let schema = &create_table_expr.schema_name;
Expand Down Expand Up @@ -291,9 +303,9 @@ impl CreateTableProcedure {

let raw_table_info = self.table_info().clone();
// Safety: the region_wal_options must be allocated.
let region_wal_options = self.region_wal_options().unwrap().clone();
let region_wal_options = self.region_wal_options()?.clone();
// Safety: the table_route must be allocated.
let table_route = self.table_route().unwrap().clone();
let table_route = self.table_route()?.clone();
manager
.create_table_metadata(raw_table_info, table_route, region_wal_options)
.await?;
Expand Down