From 9fe7410dd67301c5e39e18852e4b4802a5949b07 Mon Sep 17 00:00:00 2001 From: asonix Date: Tue, 15 Aug 2023 19:33:19 -0500 Subject: [PATCH] Add logging to migration --- dev.toml | 5 +++-- src/repo/migrate.rs | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/dev.toml b/dev.toml index 947c2d1..762fe74 100644 --- a/dev.toml +++ b/dev.toml @@ -14,8 +14,9 @@ buffer_capacity = 102400 service_name = 'pict-rs' targets = 'info' -[old_db] -path = 'data/' +[old_repo] +path = 'data/sled-repo-local' +cache_capacity = 67108864 [media] max_file_size = 40 diff --git a/src/repo/migrate.rs b/src/repo/migrate.rs index 58f21a9..c106070 100644 --- a/src/repo/migrate.rs +++ b/src/repo/migrate.rs @@ -11,6 +11,7 @@ use crate::{ stream::IntoStreamer, }; +#[tracing::instrument(skip_all)] pub(crate) async fn migrate_04( old_repo: OldSledRepo, new_repo: &ArcRepo, @@ -31,17 +32,27 @@ pub(crate) async fn migrate_04( return Err(e.into()); } + let total_size = old_repo.size().await?; + let pct = (total_size / 100).max(1); tracing::warn!("Checks complete, migrating repo"); - tracing::warn!("{} hashes will be migrated", old_repo.size().await?); + tracing::warn!("{total_size} hashes will be migrated"); let mut hash_stream = old_repo.hashes().await.into_streamer(); + let mut index = 0; while let Some(res) = hash_stream.next().await { + index += 1; if let Ok(hash) = res { let _ = migrate_hash_04(&old_repo, new_repo, store, config, hash).await; } else { tracing::warn!("Failed to read hash, skipping"); } + + if index % pct == 0 { + let percent = index / pct; + + tracing::warn!("Migration {percent}% complete - {index}/{total_size}"); + } } if let Some(generator_state) = old_repo.get("last-path").await? { @@ -84,6 +95,7 @@ async fn migrate_hash_04( Ok(()) } +#[tracing::instrument(skip_all)] async fn do_migrate_hash_04( old_repo: &OldSledRepo, new_repo: &ArcRepo, @@ -156,6 +168,7 @@ async fn do_migrate_hash_04( Ok(()) } +#[tracing::instrument(skip_all)] async fn details( old_repo: &OldSledRepo, store: &S,