Skip to content

Commit 0a21e7d

Browse files
authored
Turbopack: In CI only persist at the end (#87316)
### What? Usually we persist the database every 2 minutes inside of `next build`, so you can continue from a partial build. But in CI that doesn't make sense, so this changes it to only persist on shutdown.
1 parent a3048c6 commit 0a21e7d

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

crates/napi/src/next_api/turbopack_ctx.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ pub fn create_turbo_tasks(
204204
BackendOptions {
205205
storage_mode: Some(if std::env::var("TURBO_ENGINE_READ_ONLY").is_ok() {
206206
turbo_tasks_backend::StorageMode::ReadOnly
207+
} else if is_ci {
208+
turbo_tasks_backend::StorageMode::ReadWriteOnShutdown
207209
} else {
208210
turbo_tasks_backend::StorageMode::ReadWrite
209211
}),

turbopack/crates/turbo-tasks-backend/src/backend/mod.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

129132
pub struct BackendOptions {
@@ -242,7 +245,10 @@ impl<B: BackingStorage> TurboTasksBackend<B> {
242245
impl<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

Comments
 (0)