@@ -122,8 +122,11 @@ pub enum StorageMode {
122122 /// Queries the storage for cache entries that don't exist locally.
123123 ReadOnly ,
124124 /// Queries the storage for cache entries that don't exist locally.
125- /// Keeps a log of all changes and regularly push them to the backing storage.
125+ /// Regularly pushes changes to the backing storage.
126126 ReadWrite ,
127+ /// Queries the storage for cache entries that don't exist locally.
128+ /// On shutdown, pushes all changes to the backing storage.
129+ ReadWriteOnShutdown ,
127130}
128131
129132pub struct BackendOptions {
@@ -242,7 +245,10 @@ impl<B: BackingStorage> TurboTasksBackend<B> {
242245impl < B : BackingStorage > TurboTasksBackendInner < B > {
243246 pub fn new ( mut options : BackendOptions , backing_storage : B ) -> Self {
244247 let shard_amount = compute_shard_amount ( options. num_workers , options. small_preallocation ) ;
245- let need_log = matches ! ( options. storage_mode, Some ( StorageMode :: ReadWrite ) ) ;
248+ let need_log = matches ! (
249+ options. storage_mode,
250+ Some ( StorageMode :: ReadWrite ) | Some ( StorageMode :: ReadWriteOnShutdown )
251+ ) ;
246252 if !options. dependency_tracking {
247253 options. active_tracking = false ;
248254 }
@@ -369,7 +375,10 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
369375 }
370376
371377 fn should_persist ( & self ) -> bool {
372- matches ! ( self . options. storage_mode, Some ( StorageMode :: ReadWrite ) )
378+ matches ! (
379+ self . options. storage_mode,
380+ Some ( StorageMode :: ReadWrite ) | Some ( StorageMode :: ReadWriteOnShutdown )
381+ )
373382 }
374383
375384 fn should_restore ( & self ) -> bool {
@@ -1262,7 +1271,9 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
12621271 }
12631272 }
12641273
1265- if self . should_persist ( ) {
1274+ // Only when it should write regularly to the storage, we schedule the initial snapshot
1275+ // job.
1276+ if matches ! ( self . options. storage_mode, Some ( StorageMode :: ReadWrite ) ) {
12661277 // Schedule the snapshot job
12671278 let _span = trace_span ! ( "persisting background job" ) . entered ( ) ;
12681279 let _span = tracing:: info_span!( "thread" ) . entered ( ) ;
0 commit comments