Skip to content

Commit

Permalink
Refactors BucketStorage::map_open_file() (#2141)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Jul 19, 2024
1 parent 0d191c2 commit b0ec23d
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions bucket_map/src/bucket_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,17 +396,16 @@ impl<O: BucketOccupied> BucketStorage<O> {
.read(true)
.write(true)
.create(create)
.open(path.clone());
if let Err(e) = data {
.open(&path);
if let Err(err) = data {
if !create {
// we can't load this file, so bail without error
return None;
}
panic!(
"Unable to create data file {:?} in current dir({:?}): {:?}",
path,
"Unable to create data file '{}' in current dir ({:?}): {err}",
path.as_ref().display(),
std::env::current_dir(),
e
);
}
let mut data = data.unwrap();
Expand All @@ -427,23 +426,21 @@ impl<O: BucketOccupied> BucketStorage<O> {
.fetch_add(measure_flush.end_as_us(), Ordering::Relaxed);
}
let mut measure_mmap = Measure::start("measure_mmap");
let res = unsafe { MmapMut::map_mut(&data) };
if let Err(e) = res {
let mmap = unsafe { MmapMut::map_mut(&data) }.unwrap_or_else(|err| {
panic!(
"Unable to mmap file {:?} in current dir({:?}): {:?}",
path,
"Unable to mmap file '{}' in current dir ({:?}): {err}",
path.as_ref().display(),
std::env::current_dir(),
e
);
}
});
measure_mmap.stop();
stats
.new_file_us
.fetch_add(measure_new_file.as_us(), Ordering::Relaxed);
stats
.mmap_us
.fetch_add(measure_mmap.as_us(), Ordering::Relaxed);
res.ok()
Some(mmap)
}

/// allocate a new memory mapped file of size `bytes` on one of `drives`
Expand Down

0 comments on commit b0ec23d

Please sign in to comment.