From 4788a4f775d8083a77d6bb296c3d72adba106456 Mon Sep 17 00:00:00 2001 From: Sagar Dhawan Date: Tue, 11 Dec 2018 15:51:47 -0800 Subject: [PATCH] Correctly describe repair and retransmit peers (#2110) --- src/cluster_info.rs | 26 ++++++++++++++++++++++++-- src/db_window.rs | 2 +- src/window.rs | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/cluster_info.rs b/src/cluster_info.rs index f4f906efc4..5a7694c15f 100644 --- a/src/cluster_info.rs +++ b/src/cluster_info.rs @@ -263,6 +263,20 @@ impl ClusterInfo { /// compute broadcast table pub fn tvu_peers(&self) -> Vec { + let me = self.my_data().id; + self.gossip + .crds + .table + .values() + .filter_map(|x| x.value.contact_info()) + .filter(|x| x.id != me) + .filter(|x| ContactInfo::is_valid_address(&x.tvu)) + .cloned() + .collect() + } + + /// all peers that have a valid tvu except the leader + pub fn retransmit_peers(&self) -> Vec { let me = self.my_data().id; self.gossip .crds @@ -275,6 +289,14 @@ impl ClusterInfo { .collect() } + /// all tvu peers with valid gossip addrs + pub fn repair_peers(&self) -> Vec { + ClusterInfo::tvu_peers(self) + .into_iter() + .filter(|x| ContactInfo::is_valid_address(&x.gossip)) + .collect() + } + /// compute broadcast table pub fn tpu_peers(&self) -> Vec { let me = self.my_data().id; @@ -354,7 +376,7 @@ impl ClusterInfo { let (me, orders): (NodeInfo, Vec) = { // copy to avoid locking during IO let s = obj.read().expect("'obj' read lock in pub fn retransmit"); - (s.my_data().clone(), s.tvu_peers()) + (s.my_data().clone(), s.retransmit_peers()) }; blob.write() .unwrap() @@ -513,7 +535,7 @@ impl ClusterInfo { pub fn window_index_request(&self, ix: u64) -> Result<(SocketAddr, Vec)> { // find a peer that appears to be accepting replication, as indicated // by a valid tvu port location - let valid: Vec<_> = self.gossip_peers(); + let valid: Vec<_> = self.repair_peers(); if valid.is_empty() { Err(ClusterInfoError::NoPeers)?; } diff --git a/src/db_window.rs b/src/db_window.rs index c1c6859a31..4e3c743555 100644 --- a/src/db_window.rs +++ b/src/db_window.rs @@ -74,7 +74,7 @@ pub fn repair( } } - let num_peers = rcluster_info.tvu_peers().len() as u64; + let num_peers = rcluster_info.repair_peers().len() as u64; // Check if there's a max_entry_height limitation let max_repair_entry_height = if max_entry_height == 0 { diff --git a/src/window.rs b/src/window.rs index 448c20c57f..24cdfcc5b2 100644 --- a/src/window.rs +++ b/src/window.rs @@ -176,7 +176,7 @@ impl WindowUtil for Window { } } - let num_peers = rcluster_info.tvu_peers().len() as u64; + let num_peers = rcluster_info.repair_peers().len() as u64; let max_repair = if max_entry_height == 0 { calculate_max_repair( num_peers,