disk buckets: refactor (#21972)
This commit is contained in:
committed by
GitHub
parent
8ed7ad5fa7
commit
70f96bda25
@ -198,14 +198,10 @@ impl<T: Clone + Copy> Bucket<T> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
index.allocate(ii, elem_uid, is_resizing).unwrap();
|
index.allocate(ii, elem_uid, is_resizing).unwrap();
|
||||||
let mut elem: &mut IndexEntry = index.get_mut(ii);
|
let elem: &mut IndexEntry = index.get_mut(ii);
|
||||||
elem.key = *key;
|
// These fields will be overwritten after allocation by callers.
|
||||||
// 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.
|
// 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.init(key);
|
||||||
elem.storage_offset = 0;
|
|
||||||
elem.storage_capacity_when_created_pow2 = 0;
|
|
||||||
elem.num_slots = 0;
|
|
||||||
//debug!( "INDEX ALLOC {:?} {} {} {}", key, ii, index.capacity, elem_uid );
|
//debug!( "INDEX ALLOC {:?} {} {} {}", key, ii, index.capacity, elem_uid );
|
||||||
return Ok(ii);
|
return Ok(ii);
|
||||||
}
|
}
|
||||||
@ -285,8 +281,8 @@ impl<T: Clone + Copy> Bucket<T> {
|
|||||||
if elem.num_slots > 0 {
|
if elem.num_slots > 0 {
|
||||||
current_bucket.free(elem_loc, elem_uid);
|
current_bucket.free(elem_loc, elem_uid);
|
||||||
}
|
}
|
||||||
elem.storage_offset = ix;
|
elem.set_storage_offset(ix);
|
||||||
elem.storage_capacity_when_created_pow2 = best_bucket.capacity_pow2;
|
elem.set_storage_capacity_when_created_pow2(best_bucket.capacity_pow2);
|
||||||
elem.num_slots = data.len() as u64;
|
elem.num_slots = data.len() as u64;
|
||||||
//debug!( "DATA ALLOC {:?} {} {} {}", key, elem.data_location, best_bucket.capacity, elem_uid );
|
//debug!( "DATA ALLOC {:?} {} {} {}", key, elem.data_location, best_bucket.capacity, elem_uid );
|
||||||
if elem.num_slots > 0 {
|
if elem.num_slots > 0 {
|
||||||
|
@ -19,13 +19,32 @@ use {
|
|||||||
pub struct IndexEntry {
|
pub struct IndexEntry {
|
||||||
pub key: Pubkey, // can this be smaller if we have reduced the keys into buckets already?
|
pub key: Pubkey, // can this be smaller if we have reduced the keys into buckets already?
|
||||||
pub ref_count: RefCount, // can this be smaller? Do we ever need more than 4B refcounts?
|
pub ref_count: RefCount, // can this be smaller? Do we ever need more than 4B refcounts?
|
||||||
pub storage_offset: u64, // smaller? since these are variably sized, this could get tricky. well, actually accountinfo is not variable sized...
|
storage_offset: u64, // smaller? since these are variably sized, this could get tricky. well, actually accountinfo is not variable sized...
|
||||||
// if the bucket doubled, the index can be recomputed using create_bucket_capacity_pow2
|
// if the bucket doubled, the index can be recomputed using create_bucket_capacity_pow2
|
||||||
pub storage_capacity_when_created_pow2: u8, // see data_location
|
storage_capacity_when_created_pow2: u8, // see data_location
|
||||||
pub num_slots: Slot, // can this be smaller? epoch size should ~ be the max len. this is the num elements in the slot list
|
pub num_slots: Slot, // can this be smaller? epoch size should ~ be the max len. this is the num elements in the slot list
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IndexEntry {
|
impl IndexEntry {
|
||||||
|
pub fn init(&mut self, pubkey: &Pubkey) {
|
||||||
|
self.key = *pubkey;
|
||||||
|
self.ref_count = 0;
|
||||||
|
self.storage_offset = 0;
|
||||||
|
self.storage_capacity_when_created_pow2 = 0;
|
||||||
|
self.num_slots = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_storage_capacity_when_created_pow2(
|
||||||
|
&mut self,
|
||||||
|
storage_capacity_when_created_pow2: u8,
|
||||||
|
) {
|
||||||
|
self.storage_capacity_when_created_pow2 = storage_capacity_when_created_pow2;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_storage_offset(&mut self, storage_offset: u64) {
|
||||||
|
self.storage_offset = storage_offset;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn data_bucket_from_num_slots(num_slots: Slot) -> u64 {
|
pub fn data_bucket_from_num_slots(num_slots: Slot) -> u64 {
|
||||||
(num_slots as f64).log2().ceil() as u64 // use int log here?
|
(num_slots as f64).log2().ceil() as u64 // use int log here?
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user