coalesces vote packets into one Packets (#15566)
This commit is contained in:
parent
8399851d11
commit
f7a049f87f
|
@ -397,7 +397,7 @@ impl ClusterInfoVoteListener {
|
||||||
if let Some(bank) = bank {
|
if let Some(bank) = bank {
|
||||||
let last_version = bank.last_vote_sync.load(Ordering::Relaxed);
|
let last_version = bank.last_vote_sync.load(Ordering::Relaxed);
|
||||||
let (new_version, msgs) = verified_vote_packets.get_latest_votes(last_version);
|
let (new_version, msgs) = verified_vote_packets.get_latest_votes(last_version);
|
||||||
verified_packets_sender.send(msgs)?;
|
verified_packets_sender.send(vec![msgs])?;
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
bank.last_vote_sync.compare_and_swap(
|
bank.last_vote_sync.compare_and_swap(
|
||||||
last_version,
|
last_version,
|
||||||
|
|
|
@ -33,22 +33,18 @@ impl VerifiedVotePackets {
|
||||||
self.0.get(key)
|
self.0.get(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_latest_votes(&self, last_update_version: u64) -> (u64, Vec<Packets>) {
|
pub fn get_latest_votes(&self, last_update_version: u64) -> (u64, Packets) {
|
||||||
let mut new_update_version = last_update_version;
|
let mut new_update_version = last_update_version;
|
||||||
let msgs: Vec<_> = self
|
let packets = self
|
||||||
.0
|
.0
|
||||||
.iter()
|
.values()
|
||||||
.filter_map(|(_, (msg_update_version, msg))| {
|
.filter(|(v, _)| *v > last_update_version)
|
||||||
if *msg_update_version > last_update_version {
|
.flat_map(|(v, packets)| {
|
||||||
new_update_version = std::cmp::max(*msg_update_version, new_update_version);
|
new_update_version = std::cmp::max(*v, new_update_version);
|
||||||
Some(msg)
|
packets.packets.clone()
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.cloned()
|
|
||||||
.collect();
|
.collect();
|
||||||
(new_update_version, msgs)
|
(new_update_version, Packets::new(packets))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,13 +82,12 @@ mod tests {
|
||||||
// Both updates have timestamps greater than 0, so both should be returned
|
// Both updates have timestamps greater than 0, so both should be returned
|
||||||
let (new_update_version, updates) = verified_vote_packets.get_latest_votes(0);
|
let (new_update_version, updates) = verified_vote_packets.get_latest_votes(0);
|
||||||
assert_eq!(new_update_version, 2);
|
assert_eq!(new_update_version, 2);
|
||||||
assert_eq!(updates.len(), 2);
|
assert_eq!(updates.packets.len(), 2);
|
||||||
|
|
||||||
// Only the nonempty packet had a timestamp greater than 1
|
// Only the nonempty packet had a timestamp greater than 1
|
||||||
let (new_update_version, updates) = verified_vote_packets.get_latest_votes(1);
|
let (new_update_version, updates) = verified_vote_packets.get_latest_votes(1);
|
||||||
assert_eq!(new_update_version, 2);
|
assert_eq!(new_update_version, 2);
|
||||||
assert_eq!(updates.len(), 1);
|
assert_eq!(updates.packets.is_empty(), false);
|
||||||
assert_eq!(updates[0].packets.is_empty(), false);
|
|
||||||
|
|
||||||
// If the given timestamp is greater than all timestamps in any update,
|
// If the given timestamp is greater than all timestamps in any update,
|
||||||
// returned timestamp should be the same as the given timestamp, and
|
// returned timestamp should be the same as the given timestamp, and
|
||||||
|
|
Loading…
Reference in New Issue