Skip to content

Commit

Permalink
WIP: logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Sep 4, 2024
1 parent bca8a3e commit 673df9b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions turbopack/crates/turbo-tasks-backend/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ impl TurboTasksBackend {

impl Backend for TurboTasksBackend {
fn startup(&self, turbo_tasks: &dyn TurboTasksBackendApi<Self>) {
self.backing_storage.startup();

// Continue all uncompleted operations
// They can't be interrupted by a snapshot since the snapshotting job has not been scheduled
// yet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
};

pub trait BackingStorage {
fn startup(&self);
fn next_free_task_id(&self) -> TaskId;
fn uncompleted_operations(&self) -> Vec<AnyOperation>;
fn save_snapshot(
Expand Down
26 changes: 25 additions & 1 deletion turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use std::{
};

use anyhow::{anyhow, Context, Result};
use lmdb::{Database, DatabaseFlags, Environment, EnvironmentFlags, Transaction, WriteFlags};
use bincode::Options;

Check failure on line 14 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / stable - x86_64-unknown-linux-gnu - node@16

unresolved import `bincode`

Check failure on line 14 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / stable - aarch64-unknown-linux-gnu - node@16

unresolved import `bincode`

Check failure on line 14 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / build / build

unresolved import `bincode`

Check failure on line 14 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / rustdoc check / build

unresolved import `bincode`

Check failure on line 14 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / rust check / build

unresolved import `bincode`

Check failure on line 14 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / test unit (20) / build

unresolved import `bincode`

Check failure on line 14 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / test unit (18) / build

unresolved import `bincode`

Check failure on line 14 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / build-native / build

unresolved import `bincode`

Check failure on line 14 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / test cargo unit / build

unresolved import `bincode`

Check failure on line 14 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / stable - x86_64-pc-windows-msvc - node@16

unresolved import `bincode`

Check failure on line 14 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / stable - aarch64-apple-darwin - node@16

unresolved import `bincode`

Check failure on line 14 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / stable - x86_64-apple-darwin - node@16

unresolved import `bincode`
use lmdb::{
Cursor, Database, DatabaseFlags, Environment, EnvironmentFlags, Transaction, WriteFlags,
};
use tracing::Span;
use turbo_tasks::{backend::CachedTaskType, KeyValuePair, TaskId};

Expand Down Expand Up @@ -85,9 +88,29 @@ impl LmdbBackingStorage {
restored_cache_entries: AtomicUsize::new(0),
})
}

fn display_db(&self) -> Result<String> {
use std::fmt::Write;
let mut result = String::new();
let tx = self.env.begin_ro_txn()?;
let mut cursor = tx.open_ro_cursor(self.data_db)?;
for (key, value) in cursor.iter() {

Check failure on line 97 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / stable - x86_64-unknown-linux-gnu - node@16

mismatched types

Check failure on line 97 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / stable - aarch64-unknown-linux-gnu - node@16

mismatched types

Check failure on line 97 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / build / build

mismatched types

Check failure on line 97 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / rustdoc check / build

mismatched types

Check failure on line 97 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / rust check / build

mismatched types

Check failure on line 97 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / test unit (20) / build

mismatched types

Check failure on line 97 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / test unit (18) / build

mismatched types

Check failure on line 97 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / build-native / build

mismatched types

Check failure on line 97 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / test cargo unit / build

mismatched types

Check failure on line 97 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / stable - x86_64-pc-windows-msvc - node@16

mismatched types

Check failure on line 97 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / stable - aarch64-apple-darwin - node@16

mismatched types

Check failure on line 97 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / stable - x86_64-apple-darwin - node@16

mismatched types
let task_id = u32::from_be_bytes(key.try_into()?);
let data: Vec<CachedDataItem> = bincode::deserialize(value)?;

Check failure on line 99 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / stable - x86_64-unknown-linux-gnu - node@16

failed to resolve: use of undeclared crate or module `bincode`

Check failure on line 99 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / stable - aarch64-unknown-linux-gnu - node@16

failed to resolve: use of undeclared crate or module `bincode`

Check failure on line 99 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / build / build

failed to resolve: use of undeclared crate or module `bincode`

Check failure on line 99 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / rustdoc check / build

failed to resolve: use of undeclared crate or module `bincode`

Check failure on line 99 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / rust check / build

failed to resolve: use of undeclared crate or module `bincode`

Check failure on line 99 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / test unit (20) / build

failed to resolve: use of undeclared crate or module `bincode`

Check failure on line 99 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / test unit (18) / build

failed to resolve: use of undeclared crate or module `bincode`

Check failure on line 99 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / build-native / build

failed to resolve: use of undeclared crate or module `bincode`

Check failure on line 99 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / test cargo unit / build

failed to resolve: use of undeclared crate or module `bincode`

Check failure on line 99 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / stable - x86_64-pc-windows-msvc - node@16

failed to resolve: use of undeclared crate or module `bincode`

Check failure on line 99 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / stable - aarch64-apple-darwin - node@16

failed to resolve: use of undeclared crate or module `bincode`

Check failure on line 99 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

View workflow job for this annotation

GitHub Actions / stable - x86_64-apple-darwin - node@16

failed to resolve: use of undeclared crate or module `bincode`
write!(result, "### Task {task_id}\n{data:#?}\n\n")?;
}
Ok(result)
}
}

impl BackingStorage for LmdbBackingStorage {
fn startup(&self) {
println!(
"Database content:\n{}",
self.display_db().unwrap_or_default()
);
}

fn next_free_task_id(&self) -> TaskId {
fn get(this: &LmdbBackingStorage) -> Result<u32> {
let tx = this.env.begin_rw_txn()?;
Expand Down Expand Up @@ -388,6 +411,7 @@ impl BackingStorage for LmdbBackingStorage {
.inspect_err(|err| println!("Looking up data for {task_id} failed: {err:?}"))
.unwrap_or_default();
if !result.is_empty() {
println!("restored {task_id}");
self.restored_tasks
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
}
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbo-tasks/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ impl<B: Backend + 'static> TurboTasks<B> {
event_background: Event::new(|| "TurboTasks::event_background".to_string()),
program_start: Instant::now(),
});
this.backend.startup(&*this);
TURBO_TASKS.sync_scope(this.pin(), || this.backend.startup(&*this));
this
}

Expand Down

0 comments on commit 673df9b

Please sign in to comment.