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 {
|
if let Some(mut discovery) = discovery {
|
||||||
discovery.init_node_list(self.nodes.read().unordered_entries());
|
discovery.init_node_list(self.nodes.read().entries());
|
||||||
discovery.add_node_list(self.nodes.read().unordered_entries());
|
discovery.add_node_list(self.nodes.read().entries());
|
||||||
*self.discovery.lock() = Some(discovery);
|
*self.discovery.lock() = Some(discovery);
|
||||||
io.register_stream(DISCOVERY)?;
|
io.register_stream(DISCOVERY)?;
|
||||||
io.register_timer(DISCOVERY_REFRESH, DISCOVERY_REFRESH_TIMEOUT)?;
|
io.register_timer(DISCOVERY_REFRESH, DISCOVERY_REFRESH_TIMEOUT)?;
|
||||||
|
@ -241,24 +241,33 @@ impl NodeTable {
|
|||||||
self.nodes.insert(node.id.clone(), node);
|
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
|
fn ordered_entries(&self) -> Vec<&Node> {
|
||||||
/// failures is considered.
|
|
||||||
pub fn nodes(&self, filter: IpFilter) -> Vec<NodeId> {
|
|
||||||
let mut refs: Vec<&Node> = self.nodes.values()
|
let mut refs: Vec<&Node> = self.nodes.values()
|
||||||
.filter(|n| !self.useless_nodes.contains(&n.id))
|
.filter(|n| !self.useless_nodes.contains(&n.id))
|
||||||
.filter(|n| n.endpoint.is_allowed(&filter))
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
refs.sort_by(|a, b| {
|
refs.sort_by(|a, b| {
|
||||||
a.failure_percentage().cmp(&b.failure_percentage())
|
a.failure_percentage().cmp(&b.failure_percentage())
|
||||||
.then_with(|| a.failures.cmp(&b.failures))
|
.then_with(|| a.failures.cmp(&b.failures))
|
||||||
.then_with(|| b.attempts.cmp(&a.attempts)) // we use reverse ordering for number of attempts
|
.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
|
/// Returns node ids sorted by failure percentage, for nodes with the same failure percentage the absolute number of
|
||||||
pub fn unordered_entries(&self) -> Vec<NodeEntry> {
|
/// failures is considered.
|
||||||
self.nodes.values().map(|n| NodeEntry {
|
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(),
|
endpoint: n.endpoint.clone(),
|
||||||
id: n.id.clone(),
|
id: n.id.clone(),
|
||||||
}).collect()
|
}).collect()
|
||||||
|
Loading…
Reference in New Issue
Block a user