@@ -63,7 +63,7 @@ use crate::storage::TARGETS_ROOT_DIRECTORY;
6363use crate :: storage:: field_stats:: DATASET_STATS_STREAM_NAME ;
6464use crate :: storage:: field_stats:: calculate_field_stats;
6565use crate :: storage:: field_stats:: extract_datetime_from_parquet_path_regex;
66- use crate :: sync:: ACTIVE_OBJECT_STORE_SYNC_FILES ;
66+ use crate :: sync:: { ACTIVE_OBJECT_STORE_SYNC_FILES , SyncFileEntry } ;
6767
6868use super :: {
6969 ALERTS_ROOT_DIRECTORY , MANIFEST_FILE , ObjectStorageError , ObjectStoreFormat ,
@@ -1078,12 +1078,20 @@ async fn process_parquet_files(
10781078 . stream
10791079 . parquet_files ( )
10801080 . into_par_iter ( )
1081- . filter ( |p| !guard. contains ( p) )
1081+ . filter ( |p| !guard. contains_key ( p) )
10821082 . collect ( ) ;
10831083
10841084 let mut ret = Vec :: with_capacity ( parquet_paths. len ( ) ) ;
10851085 ret. clone_from ( & parquet_paths) ;
1086- guard. extend ( parquet_paths) ;
1086+ for path in parquet_paths {
1087+ guard. insert (
1088+ path,
1089+ SyncFileEntry {
1090+ tracked_instant : Instant :: now ( ) ,
1091+ tracked_utc : Utc :: now ( ) ,
1092+ } ,
1093+ ) ;
1094+ }
10871095 ret
10881096 } ;
10891097
@@ -1212,11 +1220,23 @@ async fn collect_upload_results(
12121220 guard. remove ( path) ;
12131221 }
12141222
1215- // check if file has been in hashset for more than 5 minutes
1216- let now = Utc :: now ( ) ;
1217- guard. retain ( |f| {
1218- !extract_datetime_from_parquet_path_regex ( f)
1219- . is_ok_and ( |ts| ( now - ts) . num_minutes ( ) >= 5 )
1223+ // Use monotonic time to ensure the 5-minute eviction window is immune to system clock adjustments.
1224+ let now = Instant :: now ( ) ;
1225+ guard. retain ( |path, entry| {
1226+ let elapsed = now. duration_since ( entry. tracked_instant ) ;
1227+ // 5 min eviction window
1228+ if elapsed >= Duration :: from_secs ( 300 ) {
1229+ // Added log for observability and debugging
1230+ warn ! (
1231+ "Removing stale sync file: {} (elapsed: {}s, tracked_at: {})" ,
1232+ path. display( ) ,
1233+ elapsed. as_secs( ) ,
1234+ entry. tracked_utc. to_rfc3339( ) ,
1235+ ) ;
1236+ false
1237+ } else {
1238+ true
1239+ }
12201240 } ) ;
12211241 }
12221242 let manifest_files: Vec < _ > = uploaded_files
0 commit comments