From 508dd4340b4e4e7595f4d6c340f38805cbeefa12 Mon Sep 17 00:00:00 2001 From: asonix Date: Thu, 6 Jul 2023 16:06:37 -0500 Subject: [PATCH] Fix panic when migrating < 100 files, improve resumed migration messaging --- src/lib.rs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b6990cd..b47a728 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1496,21 +1496,26 @@ where S2: Store, R: IdentifierRepo + HashRepo + SettingsRepo + QueueRepo, { - let repo_size = repo.size().await?; + let mut repo_size = repo.size().await?; - tracing::warn!("{repo_size} Hashes will be migrated"); + let mut progress_opt = repo.get(STORE_MIGRATION_PROGRESS).await?; + + if progress_opt.is_some() { + tracing::warn!("Continuing previous migration of {repo_size} total hashes"); + } else { + tracing::warn!("{repo_size} hashes will be migrated"); + } if repo_size == 0 { return Ok(()); } - let pct = repo_size / 100; + let mut pct = repo_size / 100; + // Hashes are read in a consistent order let stream = repo.hashes().await; let mut stream = Box::pin(stream); - let mut progress_opt = repo.get(STORE_MIGRATION_PROGRESS).await?; - let now = Instant::now(); let mut index = 0; while let Some(hash) = stream.next().await { @@ -1519,8 +1524,21 @@ where let hash = hash?; if let Some(progress) = &progress_opt { + // we've reached the most recently migrated hash. if progress.as_ref() == hash.as_ref() { progress_opt.take(); + + // update repo size to remaining size + repo_size = repo_size.saturating_sub(index); + // update pct to be proportional to remainging size + pct = repo_size / 100; + + // reset index to 0 for proper percent scaling + index = 0; + + tracing::warn!( + "Caught up to previous migration's end. {repo_size} hashes will be migrated" + ); } continue; } @@ -1615,7 +1633,7 @@ where repo.remove(STORE_MIGRATION_VARIANT).await?; repo.remove(STORE_MIGRATION_MOTION).await?; - if index % pct == 0 { + if pct > 0 && index % pct == 0 { let percent = u32::try_from(index / pct).expect("values 0-100 are always in u32 range"); if percent == 0 { continue;