Skip to content

Commit

Permalink
disk index: move fn data_loc to MultipleSlots (#30993)
Browse files Browse the repository at this point in the history
disk index: move fn `data_loc` to `MultipleSlots`
  • Loading branch information
jeffwashington authored Mar 30, 2023
1 parent 399b7ba commit 3278035
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
6 changes: 3 additions & 3 deletions bucket_map/src/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl<'b, T: Clone + Copy + 'static> Bucket<T> {
if best_fit_bucket == bucket_ix && current_multiple_slots.num_slots() > 0 {
let current_bucket = &mut self.data[bucket_ix as usize];
// in place update
let elem_loc = elem.data_loc(&self.index, current_bucket);
let elem_loc = current_multiple_slots.data_loc(current_bucket);
assert!(!current_bucket.is_free(elem_loc));
let slice: &mut [T] = current_bucket.get_mut_cell_slice(elem_loc, data_len as u64);
let current_multiple_slots = elem.get_multiple_slots_mut(&mut self.index);
Expand Down Expand Up @@ -321,7 +321,7 @@ impl<'b, T: Clone + Copy + 'static> Bucket<T> {
for i in pos..pos + (max_search * 10).min(cap) {
let ix = i % cap;
if best_bucket.is_free(ix) {
let elem_loc = elem.data_loc(&self.index, current_bucket);
let elem_loc = current_multiple_slots.data_loc(current_bucket);
let old_slots = current_multiple_slots.num_slots();
let multiple_slots = elem.get_multiple_slots_mut(&mut self.index);
multiple_slots.set_storage_offset(ix);
Expand Down Expand Up @@ -354,7 +354,7 @@ impl<'b, T: Clone + Copy + 'static> Bucket<T> {
if multiple_slots.num_slots() > 0 {
let ix = multiple_slots.data_bucket_ix() as usize;
let data_bucket = &self.data[ix];
let loc = elem.data_loc(&self.index, data_bucket);
let loc = multiple_slots.data_loc(data_bucket);
let data_bucket = &mut self.data[ix];
//debug!( "DATA FREE {:?} {} {} {}", key, elem.data_location, data_bucket.capacity, elem_uid );
data_bucket.free(loc);
Expand Down
20 changes: 7 additions & 13 deletions bucket_map/src/index_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ impl MultipleSlots {
(Slot::BITS - (num_slots - 1).leading_zeros()) as u64
}
}

/// This function maps the original data location into an index in the current bucket storage.
/// This is coupled with how we resize bucket storages.
pub(crate) fn data_loc(&self, storage: &BucketStorage<DataBucket>) -> u64 {
self.storage_offset() << (storage.capacity_pow2 - self.storage_capacity_when_created_pow2())
}
}

/// Pack the storage offset and capacity-when-crated-pow2 fields into a single u64
Expand Down Expand Up @@ -191,18 +197,6 @@ impl<T> IndexEntryPlaceInBucket<T> {
index_entry.ref_count
}

/// This function maps the original data location into an index in the current bucket storage.
/// This is coupled with how we resize bucket storages.
pub fn data_loc(
&self,
index_bucket: &BucketStorage<IndexBucket<T>>,
storage: &BucketStorage<DataBucket>,
) -> u64 {
let multiple_slots = self.get_multiple_slots(index_bucket);
multiple_slots.storage_offset()
<< (storage.capacity_pow2 - multiple_slots.storage_capacity_when_created_pow2())
}

pub fn read_value<'a>(
&self,
index_bucket: &BucketStorage<IndexBucket<T>>,
Expand All @@ -213,7 +207,7 @@ impl<T> IndexEntryPlaceInBucket<T> {
let slice = if num_slots > 0 {
let data_bucket_ix = multiple_slots.data_bucket_ix();
let data_bucket = &data_buckets[data_bucket_ix as usize];
let loc = self.data_loc(index_bucket, data_bucket);
let loc = multiple_slots.data_loc(data_bucket);
assert!(!data_bucket.is_free(loc));
data_bucket.get_cell_slice(loc, num_slots)
} else {
Expand Down

0 comments on commit 3278035

Please sign in to comment.