@@ -176,6 +176,9 @@ struct TurboTasksBackendInner<B: BackingStorage> {
176176
177177 storage : Storage ,
178178
179+ /// When true, the backing_storage has data that is not in the local storage.
180+ local_is_partial : AtomicBool ,
181+
179182 /// Number of executing operations + Highest bit is set when snapshot is
180183 /// requested. When that bit is set, operations should pause until the
181184 /// snapshot is completed. When the bit is set and in progress counter
@@ -231,16 +234,17 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
231234 options. active_tracking = false ;
232235 }
233236 let small_preallocation = options. small_preallocation ;
237+ let next_task_id = backing_storage
238+ . next_free_task_id ( )
239+ . expect ( "Failed to get task id" ) ;
234240 Self {
235241 options,
236242 start_time : Instant :: now ( ) ,
237243 session_id : backing_storage
238244 . next_session_id ( )
239245 . expect ( "Failed get session id" ) ,
240246 persisted_task_id_factory : IdFactoryWithReuse :: new (
241- backing_storage
242- . next_free_task_id ( )
243- . expect ( "Failed to get task id" ) ,
247+ next_task_id,
244248 TaskId :: try_from ( TRANSIENT_TASK_BIT - 1 ) . unwrap ( ) ,
245249 ) ,
246250 transient_task_id_factory : IdFactoryWithReuse :: new (
@@ -250,6 +254,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
250254 persisted_task_cache_log : need_log. then ( || Sharded :: new ( shard_amount) ) ,
251255 task_cache : BiMap :: new ( ) ,
252256 transient_tasks : FxDashMap :: default ( ) ,
257+ local_is_partial : AtomicBool :: new ( next_task_id != TaskId :: MIN ) ,
253258 storage : Storage :: new ( small_preallocation) ,
254259 in_progress_operations : AtomicUsize :: new ( 0 ) ,
255260 snapshot_request : Mutex :: new ( SnapshotRequest :: new ( ) ) ,
@@ -910,6 +915,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
910915 return Some ( task_type) ;
911916 }
912917 if self . should_restore ( )
918+ && self . local_is_partial . load ( Ordering :: Acquire )
913919 && !task_id. is_transient ( )
914920 && let Some ( task_type) = unsafe {
915921 self . backing_storage
@@ -1271,16 +1277,21 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
12711277 return task_id;
12721278 }
12731279
1274- let tx = self
1275- . should_restore ( )
1280+ let check_backing_storage =
1281+ self . should_restore ( ) && self . local_is_partial . load ( Ordering :: Acquire ) ;
1282+ let tx = check_backing_storage
12761283 . then ( || self . backing_storage . start_read_transaction ( ) )
12771284 . flatten ( ) ;
12781285 let task_id = {
12791286 // Safety: `tx` is a valid transaction from `self.backend.backing_storage`.
12801287 if let Some ( task_id) = unsafe {
1281- self . backing_storage
1282- . forward_lookup_task_cache ( tx. as_ref ( ) , & task_type)
1283- . expect ( "Failed to lookup task id" )
1288+ check_backing_storage
1289+ . then ( || {
1290+ self . backing_storage
1291+ . forward_lookup_task_cache ( tx. as_ref ( ) , & task_type)
1292+ . expect ( "Failed to lookup task id" )
1293+ } )
1294+ . flatten ( )
12841295 } {
12851296 self . track_cache_hit ( & task_type) ;
12861297 let _ = self . task_cache . try_insert ( Arc :: new ( task_type) , task_id) ;
0 commit comments