Skip to content

Commit

Permalink
fix/database-base-ttl:
Browse files Browse the repository at this point in the history
 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
  • Loading branch information
v0y4g3r committed Nov 3, 2024
1 parent ca78c1d commit 14b90bd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/common/meta/src/key/schema_metadata_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions src/mito2/src/compaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Duration>,
Expand All @@ -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)
}
Expand Down
8 changes: 8 additions & 0 deletions src/mito2/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, E = Error> = std::result::Result<T, E>;
Expand Down Expand Up @@ -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(),
}
}

Expand Down

0 comments on commit 14b90bd

Please sign in to comment.