locks crds only once in ClusterInfo::repair_peers (#18752)
ClusterInfo::repair_peers locks crds table twice, and shows performance regression if the RwLock is not reader-preferred: https://github.com/solana-labs/solana/blob/269028360/gossip/src/cluster_info.rs#L1188-L1210
This commit is contained in:
parent
269028360c
commit
8da261cf5c
|
@ -1187,26 +1187,24 @@ impl ClusterInfo {
|
||||||
|
|
||||||
/// all tvu peers with valid gossip addrs that likely have the slot being requested
|
/// all tvu peers with valid gossip addrs that likely have the slot being requested
|
||||||
pub fn repair_peers(&self, slot: Slot) -> Vec<ContactInfo> {
|
pub fn repair_peers(&self, slot: Slot) -> Vec<ContactInfo> {
|
||||||
let mut time = Measure::start("repair_peers");
|
let _st = ScopedTimer::from(&self.stats.repair_peers);
|
||||||
// self.tvu_peers() already filters on:
|
let self_pubkey = self.id();
|
||||||
// node.id != self.id() &&
|
let self_shred_version = self.my_shred_version();
|
||||||
// node.shred_verion == self.my_shred_version()
|
|
||||||
let nodes = self.tvu_peers();
|
|
||||||
let nodes = {
|
|
||||||
let gossip_crds = self.gossip.crds.read().unwrap();
|
let gossip_crds = self.gossip.crds.read().unwrap();
|
||||||
nodes
|
gossip_crds
|
||||||
.into_iter()
|
.get_nodes_contact_info()
|
||||||
.filter(|node| {
|
.filter(|node| {
|
||||||
ContactInfo::is_valid_address(&node.serve_repair)
|
node.id != self_pubkey
|
||||||
|
&& node.shred_version == self_shred_version
|
||||||
|
&& ContactInfo::is_valid_tvu_address(&node.tvu)
|
||||||
|
&& ContactInfo::is_valid_address(&node.serve_repair)
|
||||||
&& match gossip_crds.get_lowest_slot(node.id) {
|
&& match gossip_crds.get_lowest_slot(node.id) {
|
||||||
None => true, // fallback to legacy behavior
|
None => true, // fallback to legacy behavior
|
||||||
Some(lowest_slot) => lowest_slot.lowest <= slot,
|
Some(lowest_slot) => lowest_slot.lowest <= slot,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.cloned()
|
||||||
.collect()
|
.collect()
|
||||||
};
|
|
||||||
self.stats.repair_peers.add_measure(&mut time);
|
|
||||||
nodes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_spy_node(contact_info: &ContactInfo) -> bool {
|
fn is_spy_node(contact_info: &ContactInfo) -> bool {
|
||||||
|
|
Loading…
Reference in New Issue