Skip to content

Commit

Permalink
Use fs::rename which is much faster than move_items (#8579)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakridge authored Mar 3, 2020
1 parent 0c76b89 commit 4f05f08
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
&copy_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,
&copy_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);
Expand Down

0 comments on commit 4f05f08

Please sign in to comment.