Unverified Commit 0a21e7dd authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

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.
parent a3048c63
...@@ -204,6 +204,8 @@ pub fn create_turbo_tasks( ...@@ -204,6 +204,8 @@ pub fn create_turbo_tasks(
BackendOptions { BackendOptions {
storage_mode: Some(if std::env::var("TURBO_ENGINE_READ_ONLY").is_ok() { storage_mode: Some(if std::env::var("TURBO_ENGINE_READ_ONLY").is_ok() {
turbo_tasks_backend::StorageMode::ReadOnly turbo_tasks_backend::StorageMode::ReadOnly
} else if is_ci {
turbo_tasks_backend::StorageMode::ReadWriteOnShutdown
} else { } else {
turbo_tasks_backend::StorageMode::ReadWrite turbo_tasks_backend::StorageMode::ReadWrite
}), }),
......
...@@ -122,8 +122,11 @@ pub enum StorageMode { ...@@ -122,8 +122,11 @@ pub enum StorageMode {
/// Queries the storage for cache entries that don't exist locally. /// Queries the storage for cache entries that don't exist locally.
ReadOnly, ReadOnly,
/// Queries the storage for cache entries that don't exist locally. /// Queries the storage for cache entries that don't exist locally.
/// Keeps a log of all changes and regularly push them to the backing storage. /// Regularly pushes changes to the backing storage.
ReadWrite, ReadWrite,
/// Queries the storage for cache entries that don't exist locally.
/// On shutdown, pushes all changes to the backing storage.
ReadWriteOnShutdown,
} }
pub struct BackendOptions { pub struct BackendOptions {
...@@ -242,7 +245,10 @@ impl<B: BackingStorage> TurboTasksBackend<B> { ...@@ -242,7 +245,10 @@ impl<B: BackingStorage> TurboTasksBackend<B> {
impl<B: BackingStorage> TurboTasksBackendInner<B> { impl<B: BackingStorage> TurboTasksBackendInner<B> {
pub fn new(mut options: BackendOptions, backing_storage: B) -> Self { pub fn new(mut options: BackendOptions, backing_storage: B) -> Self {
let shard_amount = compute_shard_amount(options.num_workers, options.small_preallocation); let shard_amount = compute_shard_amount(options.num_workers, options.small_preallocation);
let need_log = matches!(options.storage_mode, Some(StorageMode::ReadWrite)); let need_log = matches!(
options.storage_mode,
Some(StorageMode::ReadWrite) | Some(StorageMode::ReadWriteOnShutdown)
);
if !options.dependency_tracking { if !options.dependency_tracking {
options.active_tracking = false; options.active_tracking = false;
} }
...@@ -369,7 +375,10 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -369,7 +375,10 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
} }
fn should_persist(&self) -> bool { fn should_persist(&self) -> bool {
matches!(self.options.storage_mode, Some(StorageMode::ReadWrite)) matches!(
self.options.storage_mode,
Some(StorageMode::ReadWrite) | Some(StorageMode::ReadWriteOnShutdown)
)
} }
fn should_restore(&self) -> bool { fn should_restore(&self) -> bool {
...@@ -1262,7 +1271,9 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -1262,7 +1271,9 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
} }
} }
if self.should_persist() { // Only when it should write regularly to the storage, we schedule the initial snapshot
// job.
if matches!(self.options.storage_mode, Some(StorageMode::ReadWrite)) {
// Schedule the snapshot job // Schedule the snapshot job
let _span = trace_span!("persisting background job").entered(); let _span = trace_span!("persisting background job").entered();
let _span = tracing::info_span!("thread").entered(); let _span = tracing::info_span!("thread").entered();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment