disk index handles empty slot list more correctly (#30752)
This commit is contained in:
parent
7a7b020580
commit
d66d1f7a46
|
@ -76,7 +76,7 @@ pub struct Bucket<T> {
|
||||||
pub reallocated: Reallocated,
|
pub reallocated: Reallocated,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'b, T: Clone + Copy + 'b> Bucket<T> {
|
impl<'b, T: Clone + Copy + 'static> Bucket<T> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
drives: Arc<Vec<PathBuf>>,
|
drives: Arc<Vec<PathBuf>>,
|
||||||
max_search: MaxSearch,
|
max_search: MaxSearch,
|
||||||
|
|
|
@ -16,7 +16,7 @@ use {
|
||||||
|
|
||||||
type LockedBucket<T> = RwLock<Option<Bucket<T>>>;
|
type LockedBucket<T> = RwLock<Option<Bucket<T>>>;
|
||||||
|
|
||||||
pub struct BucketApi<T: Clone + Copy> {
|
pub struct BucketApi<T: Clone + Copy + 'static> {
|
||||||
drives: Arc<Vec<PathBuf>>,
|
drives: Arc<Vec<PathBuf>>,
|
||||||
max_search: MaxSearch,
|
max_search: MaxSearch,
|
||||||
pub stats: Arc<BucketMapStats>,
|
pub stats: Arc<BucketMapStats>,
|
||||||
|
|
|
@ -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>>>,
|
buckets: Vec<Arc<BucketApi<T>>>,
|
||||||
drives: Arc<Vec<PathBuf>>,
|
drives: Arc<Vec<PathBuf>>,
|
||||||
max_buckets_pow2: u8,
|
max_buckets_pow2: u8,
|
||||||
|
|
|
@ -214,13 +214,8 @@ impl BucketStorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_empty_cell_slice<T: Sized>(&self) -> &[T] {
|
pub fn get_empty_cell_slice<T: Sized + 'static>() -> &'static [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_cell_slice<T: Sized>(&self, ix: u64, len: u64) -> &[T] {
|
pub fn get_cell_slice<T: Sized>(&self, ix: u64, len: u64) -> &[T] {
|
||||||
|
|
|
@ -94,18 +94,17 @@ impl IndexEntry {
|
||||||
self.storage_offset() << (storage.capacity_pow2 - self.storage_capacity_when_created_pow2())
|
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)> {
|
pub fn read_value<'a, T: 'static>(&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];
|
|
||||||
let slice = if self.num_slots > 0 {
|
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 loc = self.data_loc(data_bucket);
|
||||||
let uid = Self::key_uid(&self.key);
|
let uid = Self::key_uid(&self.key);
|
||||||
assert_eq!(Some(uid), bucket.data[data_bucket_ix as usize].uid(loc));
|
assert_eq!(Some(uid), data_bucket.uid(loc));
|
||||||
bucket.data[data_bucket_ix as usize].get_cell_slice(loc, self.num_slots)
|
data_bucket.get_cell_slice(loc, self.num_slots)
|
||||||
} else {
|
} else {
|
||||||
// num_slots is 0. This means we don't have an actual allocation.
|
// num_slots is 0. This means we don't have an actual allocation.
|
||||||
// can we trust that the data_bucket is even safe?
|
BucketStorage::get_empty_cell_slice()
|
||||||
bucket.data[data_bucket_ix as usize].get_empty_cell_slice()
|
|
||||||
};
|
};
|
||||||
Some((slice, self.ref_count))
|
Some((slice, self.ref_count))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue