disk index handles empty slot list more correctly (#30752)

This commit is contained in:
Jeff Washington (jwash) 2023-03-16 14:34:45 -05:00 committed by GitHub
parent 7a7b020580
commit d66d1f7a46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 17 deletions

View File

@ -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,

View File

@ -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>,

View File

@ -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,

View File

@ -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] {

View File

@ -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))
}