fix up refcounts on disk bucket test (#31001)

This commit is contained in:
Jeff Washington (jwash) 2023-03-31 14:37:21 -05:00 committed by GitHub
parent 8a96b91515
commit fc2bcdffe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -170,6 +170,7 @@ fn read_be_u64(input: &[u8]) -> u64 {
mod tests {
use {
super::*,
crate::index_entry::MAX_LEGAL_REFCOUNT,
rand::{thread_rng, Rng},
std::{collections::HashMap, sync::RwLock},
};
@ -365,7 +366,18 @@ mod tests {
let v = (0..count)
.map(|x| (x as usize, x as usize /*thread_rng().gen::<usize>()*/))
.collect::<Vec<_>>();
let rc = thread_rng().gen_range(0, RefCount::MAX >> 2);
let range = thread_rng().gen_range(0, 100);
// pick ref counts that are useful and common
let rc = if range < 50 {
1
} else if range < 60 {
0
} else if range < 70 {
2
} else {
thread_rng().gen_range(0, MAX_LEGAL_REFCOUNT)
};
(v, rc)
};

View File

@ -93,6 +93,9 @@ pub struct IndexEntry<T: 'static> {
_phantom: PhantomData<&'static T>,
}
/// 62 bits available for ref count
pub(crate) const MAX_LEGAL_REFCOUNT: RefCount = RefCount::MAX >> 2;
/// hold a big `RefCount` while leaving room for extra bits to be used for things like 'Occupied'
#[bitfield(bits = 64)]
#[repr(C)]