From 4f68b1f7a18b76e63b311edd468795acdc1c8e84 Mon Sep 17 00:00:00 2001 From: peilun-conflux <48905552+peilun-conflux@users.noreply.github.com> Date: Tue, 28 Apr 2020 20:45:49 +0800 Subject: [PATCH] Release temp full sync snapshot before renaming. (#1369) * Release temp full sync snapshot before renaming. Otherwise, it will report `PermissionDenied` on Windows. * Fix. --- core/src/sync/state/restore.rs | 10 ++++++++-- core/src/sync/state/snapshot_chunk_sync.rs | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/src/sync/state/restore.rs b/core/src/sync/state/restore.rs index 4665c03a18..d6dad19d33 100644 --- a/core/src/sync/state/restore.rs +++ b/core/src/sync/state/restore.rs @@ -64,8 +64,14 @@ impl Restorer { /// Start to restore chunks asynchronously. pub fn finalize_restoration( - &self, state_manager: Arc, snapshot_info: SnapshotInfo, - ) -> StorageResult<()> { + &mut self, state_manager: Arc, + snapshot_info: SnapshotInfo, + ) -> StorageResult<()> + { + // Release temp snapshot db so it can be renamed on Windows. + // `self.verifier` is never unwrapped, so it's safe to set it to None, + self.verifier = None; + state_manager .get_storage_manager() .get_snapshot_manager() diff --git a/core/src/sync/state/snapshot_chunk_sync.rs b/core/src/sync/state/snapshot_chunk_sync.rs index 7cfefe52b3..768529ae3f 100644 --- a/core/src/sync/state/snapshot_chunk_sync.rs +++ b/core/src/sync/state/snapshot_chunk_sync.rs @@ -526,10 +526,11 @@ impl SnapshotChunkSync { download_start_time.elapsed() ); + let snapshot_info = inner.snapshot_info.clone(); // start to restore and update status inner.restorer.finalize_restoration( ctx.manager.graph.data_man.storage_manager.clone(), - inner.snapshot_info.clone(), + snapshot_info, )?; inner.status = Status::Completed; }