Skip to content

Commit

Permalink
fix overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyFan2002 committed Jul 22, 2024
1 parent 2854424 commit d03d30d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/query/storages/common/table_meta/src/meta/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ pub fn monotonically_increased_timestamp(
pub fn uuid_from_date_time(ts: DateTime<Utc>) -> Uuid {
let seconds = ts.timestamp();
let nanos = ts.timestamp_subsec_nanos();
// avoid overflow silently in release mode
let _ = seconds
.checked_mul(1000)
.unwrap()
.checked_add(nanos as i64 / 1_000);
let uuid_ts = uuid::Timestamp::from_unix(NoContext, seconds as u64, nanos);
Uuid::new_v7(uuid_ts)
}
6 changes: 2 additions & 4 deletions src/query/storages/fuse/src/io/locations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ impl TableMetaLocationGenerator {
&self,
base_snapshot_timestamp: Option<DateTime<Utc>>,
) -> (Location, Uuid) {
let part_uuid =
uuid_from_date_time(base_snapshot_timestamp.unwrap_or(DateTime::<Utc>::MIN_UTC));
let part_uuid = uuid_from_date_time(base_snapshot_timestamp.unwrap_or_default());
let location_path = format!(
"{}/{}/g{}{}_v{}.parquet",
&self.prefix,
Expand Down Expand Up @@ -111,8 +110,7 @@ impl TableMetaLocationGenerator {
&self,
base_snapshot_timestamp: Option<DateTime<Utc>>,
) -> String {
let segment_uuid =
uuid_from_date_time(base_snapshot_timestamp.unwrap_or(DateTime::<Utc>::MIN_UTC));
let segment_uuid = uuid_from_date_time(base_snapshot_timestamp.unwrap_or_default());
format!(
"{}/{}/g{}_v{}.mpk",
&self.prefix,
Expand Down

0 comments on commit d03d30d

Please sign in to comment.