diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index 507aef2386..5ae1c5ce65 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -1358,16 +1358,16 @@ mod tests { let map = map.read().unwrap(); assert_eq!( map.cache_ranges_held.read().unwrap().to_vec(), - vec![Some(range.clone())] + vec![range.clone()] ); }); accts.hold_range_in_memory(&range2, true); idx.account_maps.iter().enumerate().for_each(|(bin, map)| { let map = map.read().unwrap(); let expected = if bin == 0 { - vec![Some(range.clone()), Some(range2_inclusive.clone())] + vec![range.clone(), range2_inclusive.clone()] } else { - vec![Some(range.clone())] + vec![range.clone()] }; assert_eq!( map.cache_ranges_held.read().unwrap().to_vec(), diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index 1f9169f598..e3e6fbef20 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -25,7 +25,7 @@ use { }, }; type K = Pubkey; -type CacheRangesHeld = RwLock>>>; +type CacheRangesHeld = RwLock>>; pub type SlotT = (Slot, T); type InMemMap = HashMap>; @@ -648,27 +648,18 @@ impl InMemAccountsIndex { // this becomes inclusive - that is ok - we are just roughly holding a range of items. // inclusive is bigger than exclusive so we may hold 1 extra item worst case - let inclusive_range = Some(start..=end); + let inclusive_range = start..=end; let mut ranges = self.cache_ranges_held.write().unwrap(); if start_holding { ranges.push(inclusive_range); } else { // find the matching range and delete it since we don't want to hold it anymore - let none = inclusive_range.is_none(); for (i, r) in ranges.iter().enumerate() { - if r.is_none() != none { - continue; - } - if !none { - // neither are none, so check values - if let (Bound::Included(start_found), Bound::Included(end_found)) = r - .as_ref() - .map(|r| (r.start_bound(), r.end_bound())) - .unwrap() - { - if start_found != &start || end_found != &end { - continue; - } + if let (Bound::Included(start_found), Bound::Included(end_found)) = + (r.start_bound(), r.end_bound()) + { + if start_found != &start || end_found != &end { + continue; } } // found a match. There may be dups, that's ok, we expect another call to remove the dup. @@ -900,9 +891,6 @@ impl InMemAccountsIndex { } let ranges = self.cache_ranges_held.read().unwrap().clone(); - if ranges.iter().any(|range| range.is_none()) { - return false; // range said to hold 'all', so not completed - } let mut removed = 0; // consider chunking these so we don't hold the write lock too long @@ -926,12 +914,7 @@ impl InMemAccountsIndex { continue; } - if ranges.iter().any(|range| { - range - .as_ref() - .map(|range| range.contains(&k)) - .unwrap_or(true) // None means 'full range', so true - }) { + if ranges.iter().any(|range| range.contains(&k)) { // this item is held in mem by range, so don't remove completed_scan = false; continue; @@ -1090,38 +1073,34 @@ mod tests { bucket.hold_range_in_memory(&range, true); assert_eq!( bucket.cache_ranges_held.read().unwrap().to_vec(), - vec![Some(range.clone())] + vec![range.clone()] ); bucket.hold_range_in_memory(&range, false); assert!(bucket.cache_ranges_held.read().unwrap().is_empty()); bucket.hold_range_in_memory(&range, true); assert_eq!( bucket.cache_ranges_held.read().unwrap().to_vec(), - vec![Some(range.clone())] + vec![range.clone()] ); bucket.hold_range_in_memory(&range, true); assert_eq!( bucket.cache_ranges_held.read().unwrap().to_vec(), - vec![Some(range.clone()), Some(range.clone())] + vec![range.clone(), range.clone()] ); bucket.hold_range_in_memory(&ranges[0], true); assert_eq!( bucket.cache_ranges_held.read().unwrap().to_vec(), - vec![ - Some(range.clone()), - Some(range.clone()), - Some(ranges[0].clone()) - ] + vec![range.clone(), range.clone(), ranges[0].clone()] ); bucket.hold_range_in_memory(&range, false); assert_eq!( bucket.cache_ranges_held.read().unwrap().to_vec(), - vec![Some(range.clone()), Some(ranges[0].clone())] + vec![range.clone(), ranges[0].clone()] ); bucket.hold_range_in_memory(&range, false); assert_eq!( bucket.cache_ranges_held.read().unwrap().to_vec(), - vec![Some(ranges[0].clone())] + vec![ranges[0].clone()] ); bucket.hold_range_in_memory(&ranges[0].clone(), false); assert!(bucket.cache_ranges_held.read().unwrap().is_empty());