Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions turbopack/crates/turbo-tasks-backend/src/database/turbo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl KeyValueDatabase for TurboKeyValueDatabase {
batch: self.db.write_batch()?,
db: &self.db,
compact_join_handle: &self.compact_join_handle,
initial_write: self.db.is_empty(),
}))
}

Expand All @@ -106,6 +107,7 @@ pub struct TurboWriteBatch<'a> {
batch: turbo_persistence::WriteBatch<WriteBuffer<'static>, 5>,
db: &'a Arc<TurboPersistence>,
compact_join_handle: &'a Mutex<Option<JoinHandle<Result<()>>>>,
initial_write: bool,
}

impl<'a> BaseWriteBatch<'a> for TurboWriteBatch<'a> {
Expand All @@ -126,10 +128,13 @@ impl<'a> BaseWriteBatch<'a> for TurboWriteBatch<'a> {
// Commit the write batch
self.db.commit_write_batch(self.batch)?;

// Start a new compaction in the background
let db = self.db.clone();
let handle = spawn(move || db.compact(COMPACT_MAX_COVERAGE, COMPACT_MAX_MERGE_SEQUENCE));
self.compact_join_handle.lock().replace(handle);
if !self.initial_write {
// Start a new compaction in the background
let db = self.db.clone();
let handle =
spawn(move || db.compact(COMPACT_MAX_COVERAGE, COMPACT_MAX_MERGE_SEQUENCE));
self.compact_join_handle.lock().replace(handle);
}

Ok(())
}
Expand Down
Loading