network: init discovery using healthy nodes (#8061)
* network: init discovery using healthy nodes * network: fix style grumble * network: fix typo
This commit is contained in:
parent
ed296312aa
commit
373036bb7a
@ -467,8 +467,8 @@ impl Host {
|
||||
};
|
||||
|
||||
if let Some(mut discovery) = discovery {
|
||||
discovery.init_node_list(self.nodes.read().unordered_entries());
|
||||
discovery.add_node_list(self.nodes.read().unordered_entries());
|
||||
discovery.init_node_list(self.nodes.read().entries());
|
||||
discovery.add_node_list(self.nodes.read().entries());
|
||||
*self.discovery.lock() = Some(discovery);
|
||||
io.register_stream(DISCOVERY)?;
|
||||
io.register_timer(DISCOVERY_REFRESH, DISCOVERY_REFRESH_TIMEOUT)?;
|
||||
|
@ -241,24 +241,33 @@ impl NodeTable {
|
||||
self.nodes.insert(node.id.clone(), node);
|
||||
}
|
||||
|
||||
/// Returns node ids sorted by failure percentage, for nodes with the same failure percentage the absolute number of
|
||||
/// failures is considered.
|
||||
pub fn nodes(&self, filter: IpFilter) -> Vec<NodeId> {
|
||||
fn ordered_entries(&self) -> Vec<&Node> {
|
||||
let mut refs: Vec<&Node> = self.nodes.values()
|
||||
.filter(|n| !self.useless_nodes.contains(&n.id))
|
||||
.filter(|n| n.endpoint.is_allowed(&filter))
|
||||
.collect();
|
||||
|
||||
refs.sort_by(|a, b| {
|
||||
a.failure_percentage().cmp(&b.failure_percentage())
|
||||
.then_with(|| a.failures.cmp(&b.failures))
|
||||
.then_with(|| b.attempts.cmp(&a.attempts)) // we use reverse ordering for number of attempts
|
||||
});
|
||||
refs.into_iter().map(|n| n.id).collect()
|
||||
|
||||
refs
|
||||
}
|
||||
|
||||
/// Unordered list of all entries
|
||||
pub fn unordered_entries(&self) -> Vec<NodeEntry> {
|
||||
self.nodes.values().map(|n| NodeEntry {
|
||||
/// Returns node ids sorted by failure percentage, for nodes with the same failure percentage the absolute number of
|
||||
/// failures is considered.
|
||||
pub fn nodes(&self, filter: IpFilter) -> Vec<NodeId> {
|
||||
self.ordered_entries().iter()
|
||||
.filter(|n| n.endpoint.is_allowed(&filter))
|
||||
.map(|n| n.id)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Ordered list of all entries by failure percentage, for nodes with the same failure percentage the absolute
|
||||
/// number of failures is considered.
|
||||
pub fn entries(&self) -> Vec<NodeEntry> {
|
||||
self.ordered_entries().iter().map(|n| NodeEntry {
|
||||
endpoint: n.endpoint.clone(),
|
||||
id: n.id.clone(),
|
||||
}).collect()
|
||||
|
Loading…
Reference in New Issue
Block a user