From 4f05f08f5d0d537b66f135e7e16ab1a65073a126 Mon Sep 17 00:00:00 2001 From: sakridge Date: Tue, 3 Mar 2020 10:03:17 -0800 Subject: [PATCH] Use fs::rename which is much faster than move_items (#8579) --- runtime/src/accounts_db.rs | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index c862e8e4ee..1c70ba31b7 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -552,23 +552,26 @@ impl AccountsDB { AppendVec::new_relative_path(slot_id, storage_entry.id); let append_vec_abs_path = append_vecs_path.as_ref().join(&append_vec_relative_path); - let mut copy_options = CopyOptions::new(); - copy_options.overwrite = true; - let e = fs_extra::move_items( - &vec![&append_vec_abs_path], - &local_dir, - ©_options, - ) - .map_err(|e| { - AccountsDB::get_io_error(&format!( - "Unable to move {:?} to {:?}: {}", - append_vec_abs_path, local_dir, e - )) - }); - if e.is_err() { - info!("{:?}", e); - continue; - } + let target = local_dir.join(append_vec_abs_path.file_name().unwrap()); + if std::fs::rename(append_vec_abs_path.clone(), target).is_err() { + let mut copy_options = CopyOptions::new(); + copy_options.overwrite = true; + let e = fs_extra::move_items( + &vec![&append_vec_abs_path], + &local_dir, + ©_options, + ) + .map_err(|e| { + AccountsDB::get_io_error(&format!( + "Unable to move {:?} to {:?}: {}", + append_vec_abs_path, local_dir, e + )) + }); + if e.is_err() { + info!("{:?}", e); + continue; + } + }; // Notify the AppendVec of the new file location let local_path = local_dir.join(append_vec_relative_path);