reduce lock contention on latest_root (#16306)
This commit is contained in:
committed by
GitHub
parent
7a997759fa
commit
95dc7b5449
@ -752,30 +752,35 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
|
|||||||
) -> Option<usize> {
|
) -> Option<usize> {
|
||||||
let mut current_max = 0;
|
let mut current_max = 0;
|
||||||
let mut rv = None;
|
let mut rv = None;
|
||||||
|
if let Some(ancestors) = ancestors {
|
||||||
|
if !ancestors.is_empty() {
|
||||||
for (i, (slot, _t)) in slice.iter().rev().enumerate() {
|
for (i, (slot, _t)) in slice.iter().rev().enumerate() {
|
||||||
if *slot >= current_max && self.is_ancestor_or_root(*slot, ancestors, max_root) {
|
if *slot >= current_max && ancestors.contains_key(slot) {
|
||||||
rv = Some((slice.len() - 1) - i);
|
rv = Some(i);
|
||||||
current_max = *slot;
|
current_max = *slot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
rv
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks that the given slot is either:
|
let max_root = max_root.unwrap_or(Slot::MAX);
|
||||||
// 1) in the `ancestors` set
|
let mut tracker = None;
|
||||||
// 2) or is a root
|
|
||||||
fn is_ancestor_or_root(
|
for (i, (slot, _t)) in slice.iter().rev().enumerate() {
|
||||||
&self,
|
if *slot >= current_max && *slot <= max_root {
|
||||||
slot: Slot,
|
let lock = match tracker {
|
||||||
ancestors: Option<&Ancestors>,
|
Some(inner) => inner,
|
||||||
max_root: Option<Slot>,
|
None => self.roots_tracker.read().unwrap(),
|
||||||
) -> bool {
|
};
|
||||||
ancestors.map_or(false, |ancestors| ancestors.contains_key(&slot)) ||
|
if lock.roots.contains(&slot) {
|
||||||
// If the slot is a root, it must be less than the maximum root specified. This
|
rv = Some(i);
|
||||||
// allows scans on non-rooted slots to specify and read data from
|
current_max = *slot;
|
||||||
// ancestors > max_root, while not seeing rooted data update during the scan
|
}
|
||||||
(max_root.map_or(true, |max_root| slot <= max_root) && (self.is_root(slot)))
|
tracker = Some(lock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rv.map(|index| slice.len() - 1 - index)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an account
|
/// Get an account
|
||||||
|
Reference in New Issue
Block a user