AcctIdx: disk bucket cleanup (#21520)
This commit is contained in:
parent
f5b0764795
commit
f598ee696c
|
@ -185,7 +185,6 @@ impl<T: Clone + Copy> Bucket<T> {
|
|||
key: &Pubkey,
|
||||
elem_uid: Uid,
|
||||
random: u64,
|
||||
ref_count: u64,
|
||||
) -> Result<u64, BucketMapError> {
|
||||
let ix = Self::bucket_index_ix(index, key, random);
|
||||
for i in ix..ix + index.max_search() {
|
||||
|
@ -196,7 +195,9 @@ impl<T: Clone + Copy> Bucket<T> {
|
|||
index.allocate(ii, elem_uid).unwrap();
|
||||
let mut elem: &mut IndexEntry = index.get_mut(ii);
|
||||
elem.key = *key;
|
||||
elem.ref_count = ref_count;
|
||||
// These will be overwritten after allocation by callers.
|
||||
// Since this part of the mmapped file could have previously been used by someone else, there can be garbage here.
|
||||
elem.ref_count = 0;
|
||||
elem.storage_offset = 0;
|
||||
elem.storage_capacity_when_created_pow2 = 0;
|
||||
elem.num_slots = 0;
|
||||
|
@ -218,14 +219,8 @@ impl<T: Clone + Copy> Bucket<T> {
|
|||
Some(elem.ref_count)
|
||||
}
|
||||
|
||||
fn create_key(&self, key: &Pubkey, ref_count: u64) -> Result<u64, BucketMapError> {
|
||||
Self::bucket_create_key(
|
||||
&self.index,
|
||||
key,
|
||||
IndexEntry::key_uid(key),
|
||||
self.random,
|
||||
ref_count,
|
||||
)
|
||||
fn create_key(&self, key: &Pubkey) -> Result<u64, BucketMapError> {
|
||||
Self::bucket_create_key(&self.index, key, IndexEntry::key_uid(key), self.random)
|
||||
}
|
||||
|
||||
pub fn read_value(&self, key: &Pubkey) -> Option<(&[T], RefCount)> {
|
||||
|
@ -248,17 +243,13 @@ impl<T: Clone + Copy> Bucket<T> {
|
|||
let index_entry = self.find_entry_mut(key);
|
||||
let (elem, elem_ix) = match index_entry {
|
||||
None => {
|
||||
let ii = self.create_key(key, ref_count)?;
|
||||
let elem = self.index.get_mut(ii); // get_mut here is right?
|
||||
let ii = self.create_key(key)?;
|
||||
let elem: &mut IndexEntry = self.index.get_mut(ii);
|
||||
(elem, ii)
|
||||
}
|
||||
Some(res) => {
|
||||
if ref_count != res.0.ref_count {
|
||||
res.0.ref_count = ref_count;
|
||||
}
|
||||
res
|
||||
}
|
||||
Some(res) => res,
|
||||
};
|
||||
elem.ref_count = ref_count;
|
||||
let elem_uid = self.index.uid(elem_ix);
|
||||
let bucket_ix = elem.data_bucket_ix();
|
||||
let current_bucket = &self.data[bucket_ix as usize];
|
||||
|
@ -266,7 +257,6 @@ impl<T: Clone + Copy> Bucket<T> {
|
|||
// in place update
|
||||
let elem_loc = elem.data_loc(current_bucket);
|
||||
let slice: &mut [T] = current_bucket.get_mut_cell_slice(elem_loc, data.len() as u64);
|
||||
//let elem: &mut IndexEntry = self.index.get_mut(elem_ix);
|
||||
assert!(current_bucket.uid(elem_loc) == elem_uid);
|
||||
elem.num_slots = data.len() as u64;
|
||||
slice.clone_from_slice(data);
|
||||
|
@ -284,7 +274,6 @@ impl<T: Clone + Copy> Bucket<T> {
|
|||
if elem.num_slots > 0 {
|
||||
current_bucket.free(elem_loc, elem_uid);
|
||||
}
|
||||
// elem: &mut IndexEntry = self.index.get_mut(elem_ix);
|
||||
elem.storage_offset = ix;
|
||||
elem.storage_capacity_when_created_pow2 = best_bucket.capacity_pow2;
|
||||
elem.num_slots = data.len() as u64;
|
||||
|
@ -339,9 +328,7 @@ impl<T: Clone + Copy> Bucket<T> {
|
|||
let uid = self.index.uid(ix);
|
||||
if UID_UNLOCKED != uid {
|
||||
let elem: &IndexEntry = self.index.get(ix);
|
||||
let ref_count = 0; // ??? TODO
|
||||
let new_ix =
|
||||
Self::bucket_create_key(&index, &elem.key, uid, random, ref_count);
|
||||
let new_ix = Self::bucket_create_key(&index, &elem.key, uid, random);
|
||||
if new_ix.is_err() {
|
||||
valid = false;
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue