From 14b90bdef22ad5af1aa8966c761c87a025e485aa Mon Sep 17 00:00:00 2001 From: "Lei, HUANG" Date: Sat, 2 Nov 2024 19:52:11 -0700 Subject: [PATCH] fix/database-base-ttl: Refactor error handling and update documentation comments - Update comment to reflect retrieval of schema options instead of metadata - Introduce new error type `GetSchemaMetadataSnafu` for schema metadata retrieval failures - Implement error handling for schema metadata retrieval in `find_ttl` function --- src/common/meta/src/key/schema_metadata_manager.rs | 2 +- src/mito2/src/compaction.rs | 7 ++++--- src/mito2/src/error.rs | 8 ++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/common/meta/src/key/schema_metadata_manager.rs b/src/common/meta/src/key/schema_metadata_manager.rs index 8557114348c3..fc6172041d05 100644 --- a/src/common/meta/src/key/schema_metadata_manager.rs +++ b/src/common/meta/src/key/schema_metadata_manager.rs @@ -47,7 +47,7 @@ impl SchemaMetadataManager { } } - /// Gets schema metadata by table id. + /// Gets schema options by table id. pub async fn get_schema_options_by_table_id( &self, table_id: TableId, diff --git a/src/mito2/src/compaction.rs b/src/mito2/src/compaction.rs index e1cf1c6c4ceb..2c2a8f092af8 100644 --- a/src/mito2/src/compaction.rs +++ b/src/mito2/src/compaction.rs @@ -49,8 +49,8 @@ use crate::compaction::picker::{new_picker, CompactionTask}; use crate::compaction::task::CompactionTaskImpl; use crate::config::MitoConfig; use crate::error::{ - CompactRegionSnafu, Error, RegionClosedSnafu, RegionDroppedSnafu, RegionTruncatedSnafu, - RemoteCompactionSnafu, Result, TimeRangePredicateOverflowSnafu, + CompactRegionSnafu, Error, GetSchemaMetadataSnafu, RegionClosedSnafu, RegionDroppedSnafu, + RegionTruncatedSnafu, RemoteCompactionSnafu, Result, TimeRangePredicateOverflowSnafu, }; use crate::metrics::COMPACTION_STAGE_ELAPSED; use crate::read::projection::ProjectionMapper; @@ -434,6 +434,7 @@ impl PendingCompaction { } } +/// Finds TTL of table by first examine table options then database options. async fn find_ttl( table_id: TableId, table_ttl: Option, @@ -446,7 +447,7 @@ async fn find_ttl( let ttl = schema_metadata_manager .get_schema_options_by_table_id(table_id) .await - .expect("Failed to get table ") + .context(GetSchemaMetadataSnafu)? .and_then(|options| options.ttl); Ok(ttl) } diff --git a/src/mito2/src/error.rs b/src/mito2/src/error.rs index 8aa799cbb913..6cb4f8abdd7a 100644 --- a/src/mito2/src/error.rs +++ b/src/mito2/src/error.rs @@ -870,6 +870,13 @@ pub enum Error { #[snafu(implicit)] location: Location, }, + + #[snafu(display("Failed to get schema metadata"))] + GetSchemaMetadata { + source: common_meta::error::Error, + #[snafu(implicit)] + location: Location, + }, } pub type Result = std::result::Result; @@ -1002,6 +1009,7 @@ impl ErrorExt for Error { | ApplyFulltextIndex { source, .. } => source.status_code(), DecodeStats { .. } | StatsNotPresent { .. } => StatusCode::Internal, RegionBusy { .. } => StatusCode::RegionBusy, + GetSchemaMetadata { source, .. } => source.status_code(), } }