Skip to content

Commit

Permalink
disk index handles empty slot list more correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Mar 16, 2023
1 parent 62fe6ea commit a820f7b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bucket_map/src/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct Bucket<T> {
pub reallocated: Reallocated,
}

impl<'b, T: Clone + Copy + 'b> Bucket<T> {
impl<'b, T: Clone + Copy + 'static> Bucket<T> {
pub fn new(
drives: Arc<Vec<PathBuf>>,
max_search: MaxSearch,
Expand Down
2 changes: 1 addition & 1 deletion bucket_map/src/bucket_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use {

type LockedBucket<T> = RwLock<Option<Bucket<T>>>;

pub struct BucketApi<T: Clone + Copy> {
pub struct BucketApi<T: Clone + Copy + 'static> {
drives: Arc<Vec<PathBuf>>,
max_search: MaxSearch,
pub stats: Arc<BucketMapStats>,
Expand Down
2 changes: 1 addition & 1 deletion bucket_map/src/bucket_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl BucketMapConfig {
}
}

pub struct BucketMap<T: Clone + Copy + Debug> {
pub struct BucketMap<T: Clone + Copy + Debug + 'static> {
buckets: Vec<Arc<BucketApi<T>>>,
drives: Arc<Vec<PathBuf>>,
max_buckets_pow2: u8,
Expand Down
9 changes: 2 additions & 7 deletions bucket_map/src/bucket_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,8 @@ impl BucketStorage {
}
}

pub fn get_empty_cell_slice<T: Sized>(&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<T: Sized + 'static>() -> &'static [T] {
&[]
}

pub fn get_cell_slice<T: Sized>(&self, ix: u64, len: u64) -> &[T] {
Expand Down
13 changes: 6 additions & 7 deletions bucket_map/src/index_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,17 @@ impl IndexEntry {
self.storage_offset() << (storage.capacity_pow2 - self.storage_capacity_when_created_pow2())
}

pub fn read_value<'a, T>(&self, bucket: &'a Bucket<T>) -> Option<(&'a [T], RefCount)> {
let data_bucket_ix = self.data_bucket_ix();
let data_bucket = &bucket.data[data_bucket_ix as usize];
pub fn read_value<'a, T: 'static>(&self, bucket: &'a Bucket<T>) -> Option<(&'a [T], RefCount)> {
let slice = if self.num_slots > 0 {
let data_bucket_ix = self.data_bucket_ix();
let data_bucket = &bucket.data[data_bucket_ix as usize];
let loc = self.data_loc(data_bucket);
let uid = Self::key_uid(&self.key);
assert_eq!(Some(uid), bucket.data[data_bucket_ix as usize].uid(loc));
bucket.data[data_bucket_ix as usize].get_cell_slice(loc, self.num_slots)
assert_eq!(Some(uid), data_bucket.uid(loc));
data_bucket.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))
}
Expand Down

0 comments on commit a820f7b

Please sign in to comment.