disk index: correctly keep track of count during batch add (#31133)

This commit is contained in:
Jeff Washington (jwash) 2023-04-10 16:01:25 -05:00 committed by GitHub
parent 861bca87f9
commit 4f0adcde89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -329,6 +329,10 @@ impl<'b, T: Clone + Copy + 'static> Bucket<T> {
Ok(_result) => {
// everything added
self.set_anticipated_count(0);
self.index.count.fetch_add(
count.saturating_sub(duplicates.len()) as u64,
Ordering::Relaxed,
);
return duplicates;
}
Err(error) => {

View File

@ -400,9 +400,14 @@ mod tests {
};
let verify = || {
let expected_count = hash_map.read().unwrap().len();
let mut maps = maps
.iter()
.map(|map| {
let total_entries = (0..map.num_buckets())
.map(|bucket| map.get_bucket_from_index(bucket).bucket_len() as usize)
.sum::<usize>();
assert_eq!(total_entries, expected_count);
let mut r = vec![];
for bin in 0..map.num_buckets() {
r.append(