Skip to content

Commit

Permalink
fix up refcounts on disk bucket test (#31001)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored Mar 31, 2023
1 parent 8a96b91 commit fc2bcdf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 13 additions & 1 deletion bucket_map/src/bucket_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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)
};

Expand Down
3 changes: 3 additions & 0 deletions bucket_map/src/index_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit fc2bcdf

Please sign in to comment.