From c1bc0d3fc3f40fb8eccf783bb9419e2461908629 Mon Sep 17 00:00:00 2001 From: jeff washington Date: Thu, 16 Mar 2023 09:58:31 -0500 Subject: [PATCH] disk index handles empty slot list more correctly --- bucket_map/src/bucket.rs | 2 +- bucket_map/src/bucket_api.rs | 2 +- bucket_map/src/bucket_map.rs | 2 +- bucket_map/src/bucket_storage.rs | 9 ++------- bucket_map/src/index_entry.rs | 5 ++--- 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/bucket_map/src/bucket.rs b/bucket_map/src/bucket.rs index e4ec015c142909..943c79483822cb 100644 --- a/bucket_map/src/bucket.rs +++ b/bucket_map/src/bucket.rs @@ -76,7 +76,7 @@ pub struct Bucket { pub reallocated: Reallocated, } -impl<'b, T: Clone + Copy + 'b> Bucket { +impl<'b, T: Clone + Copy + 'static> Bucket { pub fn new( drives: Arc>, max_search: MaxSearch, diff --git a/bucket_map/src/bucket_api.rs b/bucket_map/src/bucket_api.rs index 4f33f6e71384f8..695d6836b9aeb4 100644 --- a/bucket_map/src/bucket_api.rs +++ b/bucket_map/src/bucket_api.rs @@ -16,7 +16,7 @@ use { type LockedBucket = RwLock>>; -pub struct BucketApi { +pub struct BucketApi { drives: Arc>, max_search: MaxSearch, pub stats: Arc, diff --git a/bucket_map/src/bucket_map.rs b/bucket_map/src/bucket_map.rs index bad5cec5a2ed44..86ceef7e84fd2b 100644 --- a/bucket_map/src/bucket_map.rs +++ b/bucket_map/src/bucket_map.rs @@ -25,7 +25,7 @@ impl BucketMapConfig { } } -pub struct BucketMap { +pub struct BucketMap { buckets: Vec>>, drives: Arc>, max_buckets_pow2: u8, diff --git a/bucket_map/src/bucket_storage.rs b/bucket_map/src/bucket_storage.rs index 69e3eecd23cb38..b69166eb8467c9 100644 --- a/bucket_map/src/bucket_storage.rs +++ b/bucket_map/src/bucket_storage.rs @@ -214,13 +214,8 @@ impl BucketStorage { } } - pub fn get_empty_cell_slice(&self) -> &[T] { - let len = 0; - let item_slice: &[u8] = &self.mmap[0..0]; - unsafe { - let item = item_slice.as_ptr() as *const T; - std::slice::from_raw_parts(item, len as usize) - } + pub fn get_empty_cell_slice() -> &'static [T] { + &[] } pub fn get_cell_slice(&self, ix: u64, len: u64) -> &[T] { diff --git a/bucket_map/src/index_entry.rs b/bucket_map/src/index_entry.rs index 91e77ac8c78c93..d87cee118261fe 100644 --- a/bucket_map/src/index_entry.rs +++ b/bucket_map/src/index_entry.rs @@ -94,7 +94,7 @@ impl IndexEntry { self.storage_offset() << (storage.capacity_pow2 - self.storage_capacity_when_created_pow2()) } - pub fn read_value<'a, T>(&self, bucket: &'a Bucket) -> Option<(&'a [T], RefCount)> { + pub fn read_value<'a, T: 'static>(&self, bucket: &'a Bucket) -> Option<(&'a [T], RefCount)> { let data_bucket_ix = self.data_bucket_ix(); let data_bucket = &bucket.data[data_bucket_ix as usize]; let slice = if self.num_slots > 0 { @@ -104,8 +104,7 @@ impl IndexEntry { bucket.data[data_bucket_ix as usize].get_cell_slice(loc, self.num_slots) } else { // num_slots is 0. This means we don't have an actual allocation. - // can we trust that the data_bucket is even safe? - bucket.data[data_bucket_ix as usize].get_empty_cell_slice() + BucketStorage::get_empty_cell_slice() }; Some((slice, self.ref_count)) }