From 71b16bf6cb25a427d2b85403edce1de9cb45a8eb Mon Sep 17 00:00:00 2001 From: sky <3374614481@qq.com> Date: Mon, 22 Jul 2024 14:29:35 +0800 Subject: [PATCH] fix overflow --- src/query/storages/common/table_meta/src/meta/utils.rs | 6 ++++++ src/query/storages/fuse/src/io/locations.rs | 6 ++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/query/storages/common/table_meta/src/meta/utils.rs b/src/query/storages/common/table_meta/src/meta/utils.rs index 1a1e2a99351c..fddbded82382 100644 --- a/src/query/storages/common/table_meta/src/meta/utils.rs +++ b/src/query/storages/common/table_meta/src/meta/utils.rs @@ -53,6 +53,12 @@ pub fn monotonically_increased_timestamp( pub fn uuid_from_date_time(ts: DateTime) -> 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) + .unwrap(); let uuid_ts = uuid::Timestamp::from_unix(NoContext, seconds as u64, nanos); Uuid::new_v7(uuid_ts) } diff --git a/src/query/storages/fuse/src/io/locations.rs b/src/query/storages/fuse/src/io/locations.rs index 41464be60879..073257784c06 100644 --- a/src/query/storages/fuse/src/io/locations.rs +++ b/src/query/storages/fuse/src/io/locations.rs @@ -80,8 +80,7 @@ impl TableMetaLocationGenerator { &self, base_snapshot_timestamp: Option>, ) -> (Location, Uuid) { - let part_uuid = - uuid_from_date_time(base_snapshot_timestamp.unwrap_or(DateTime::::MIN_UTC)); + let part_uuid = uuid_from_date_time(base_snapshot_timestamp.unwrap_or_default()); let location_path = format!( "{}/{}/g{}{}_v{}.parquet", &self.prefix, @@ -111,8 +110,7 @@ impl TableMetaLocationGenerator { &self, base_snapshot_timestamp: Option>, ) -> String { - let segment_uuid = - uuid_from_date_time(base_snapshot_timestamp.unwrap_or(DateTime::::MIN_UTC)); + let segment_uuid = uuid_from_date_time(base_snapshot_timestamp.unwrap_or_default()); format!( "{}/{}/g{}_v{}.mpk", &self.prefix,