From b0ec23d38473a03796052ca16c5ed8612082d7b5 Mon Sep 17 00:00:00 2001 From: Brooks Date: Fri, 19 Jul 2024 09:58:05 -0400 Subject: [PATCH] Refactors BucketStorage::map_open_file() (#2141) --- bucket_map/src/bucket_storage.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/bucket_map/src/bucket_storage.rs b/bucket_map/src/bucket_storage.rs index dbddbc169db321..165ffe5c65ed08 100644 --- a/bucket_map/src/bucket_storage.rs +++ b/bucket_map/src/bucket_storage.rs @@ -396,17 +396,16 @@ impl BucketStorage { .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(); @@ -427,15 +426,13 @@ impl BucketStorage { .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 @@ -443,7 +440,7 @@ impl BucketStorage { 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`