Skip to content

Commit

Permalink
create dir and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Aug 13, 2024
1 parent 5437179 commit 18cad24
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::{
collections::{hash_map::Entry, HashMap},
error::Error,
fs::create_dir_all,
path::Path,
sync::Arc,
thread::available_parallelism,
time::Instant,
};

use anyhow::Result;
Expand Down Expand Up @@ -50,6 +52,7 @@ pub struct LmdbBackingStorage {

impl LmdbBackingStorage {
pub fn new(path: &Path) -> Result<Self> {
create_dir_all(path)?;
println!("opening lmdb {:?}", path);
let env = Environment::new()
.set_flags(EnvironmentFlags::WRITE_MAP | EnvironmentFlags::NO_META_SYNC)
Expand Down Expand Up @@ -100,6 +103,14 @@ impl BackingStorage for LmdbBackingStorage {
task_cache_updates: ChunkedVec<(Arc<CachedTaskType>, TaskId)>,
data_updates: ChunkedVec<CachedDataUpdate>,
) -> Result<()> {
println!(
"Persisting {} operations, {} task cache updates, {} data updates...",
operations.len(),
task_cache_updates.len(),
data_updates.len()
);
let start = Instant::now();
let mut op_count = 0;
let mut tx = self.env.begin_rw_txn()?;
let mut next_task_id =
as_u32(tx.get(self.meta_db, &IntKey::new(META_KEY_NEXT_FREE_TASK_ID))).unwrap_or(1);
Expand All @@ -118,6 +129,7 @@ impl BackingStorage for LmdbBackingStorage {
&task_type,
WriteFlags::empty(),
)?;
op_count += 2;
next_task_id = next_task_id.max(task_id + 1);
}
tx.put(
Expand All @@ -133,6 +145,8 @@ impl BackingStorage for LmdbBackingStorage {
&operations,
WriteFlags::empty(),
)?;
op_count += 2;

let mut updated_items: HashMap<TaskId, HashMap<CachedDataItemKey, CachedDataItemValue>> =
HashMap::new();
for CachedDataUpdate { task, key, value } in data_updates.into_iter() {
Expand Down Expand Up @@ -168,8 +182,13 @@ impl BackingStorage for LmdbBackingStorage {
&value,
WriteFlags::empty(),
)?;
op_count += 1;
}
tx.commit()?;
println!(
"Persisted {op_count} db entries after {:?}",
start.elapsed()
);
Ok(())
}

Expand Down

0 comments on commit 18cad24

Please sign in to comment.