removes Crds::lookup and lookup_versioned (#17438)

This commit is contained in:
behzad nouri
2021-05-24 18:21:54 +00:00
committed by GitHub
parent a8dca3976b
commit e867d7f3b8
5 changed files with 42 additions and 87 deletions

View File

@ -683,14 +683,10 @@ impl ClusterInfo {
where
F: FnOnce(&ContactInfo) -> Y,
{
let entry = CrdsValueLabel::ContactInfo(*id);
self.gossip
.read()
.unwrap()
.crds
.lookup(&entry)
.and_then(CrdsValue::contact_info)
.map(map)
let label = CrdsValueLabel::ContactInfo(*id);
let gossip = self.gossip.read().unwrap();
let entry = gossip.crds.get(&label)?;
Some(map(entry.value.contact_info()?))
}
pub fn lookup_contact_info_by_gossip_addr(
@ -715,13 +711,11 @@ impl ClusterInfo {
}
pub fn lookup_epoch_slots(&self, ix: EpochSlotsIndex) -> EpochSlots {
let entry = CrdsValueLabel::EpochSlots(ix, self.id());
self.gossip
.read()
.unwrap()
.crds
.lookup(&entry)
.and_then(CrdsValue::epoch_slots)
let label = CrdsValueLabel::EpochSlots(ix, self.id());
let gossip = self.gossip.read().unwrap();
let entry = gossip.crds.get(&label);
entry
.and_then(|v| v.value.epoch_slots())
.cloned()
.unwrap_or_else(|| EpochSlots::new(self.id(), timestamp()))
}
@ -884,8 +878,8 @@ impl ClusterInfo {
.read()
.unwrap()
.crds
.lookup(&CrdsValueLabel::LowestSlot(self.id()))
.and_then(|x| x.lowest_slot())
.get(&CrdsValueLabel::LowestSlot(self.id()))
.and_then(|x| x.value.lowest_slot())
.map(|x| x.lowest)
.unwrap_or(0);
if min > last {
@ -1050,9 +1044,9 @@ impl ClusterInfo {
(0..MAX_LOCKOUT_HISTORY as u8)
.filter_map(|ix| {
let vote = CrdsValueLabel::Vote(ix, self_pubkey);
let vote = gossip.crds.lookup(&vote)?;
let vote = gossip.crds.get(&vote)?;
num_crds_votes += 1;
match &vote.data {
match &vote.value.data {
CrdsData::Vote(_, vote) if should_evict_vote(vote) => {
Some((vote.wallclock, ix))
}
@ -1073,8 +1067,8 @@ impl ClusterInfo {
self.time_gossip_read_lock("gossip_read_push_vote", &self.stats.push_vote_read);
(0..MAX_LOCKOUT_HISTORY as u8).find(|ix| {
let vote = CrdsValueLabel::Vote(*ix, self.id());
if let Some(vote) = gossip.crds.lookup(&vote) {
match &vote.data {
if let Some(vote) = gossip.crds.get(&vote) {
match &vote.value.data {
CrdsData::Vote(_, prev_vote) => match prev_vote.slot() {
Some(prev_vote_slot) => prev_vote_slot == vote_slot,
None => {
@ -3432,13 +3426,8 @@ mod tests {
let d = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), timestamp());
let label = CrdsValueLabel::ContactInfo(d.id);
cluster_info.insert_info(d);
assert!(cluster_info
.gossip
.read()
.unwrap()
.crds
.lookup(&label)
.is_some());
let gossip = cluster_info.gossip.read().unwrap();
assert!(gossip.crds.get(&label).is_some());
}
fn assert_in_range(x: u16, range: (u16, u16)) {
@ -3711,7 +3700,7 @@ mod tests {
let gossip = cluster_info.gossip.read().unwrap();
let mut vote_slots = HashSet::new();
for label in labels {
match &gossip.crds.lookup(&label).unwrap().data {
match &gossip.crds.get(&label).unwrap().value.data {
CrdsData::Vote(_, vote) => {
assert!(vote_slots.insert(vote.slot().unwrap()));
}

View File

@ -222,14 +222,6 @@ impl Crds {
}
}
pub fn lookup(&self, label: &CrdsValueLabel) -> Option<&CrdsValue> {
self.table.get(label).map(|x| &x.value)
}
pub fn lookup_versioned(&self, label: &CrdsValueLabel) -> Option<&VersionedCrdsValue> {
self.table.get(label)
}
pub fn get(&self, label: &CrdsValueLabel) -> Option<&VersionedCrdsValue> {
self.table.get(label)
}

View File

@ -1197,14 +1197,8 @@ pub(crate) mod tests {
1,
);
assert!(rsp.iter().all(|rsp| rsp.is_empty()));
assert!(dest_crds.lookup(&caller.label()).is_some());
assert_eq!(
dest_crds
.lookup_versioned(&caller.label())
.unwrap()
.local_timestamp,
1
);
assert!(dest_crds.get(&caller.label()).is_some());
assert_eq!(dest_crds.get(&caller.label()).unwrap().local_timestamp, 1);
}
#[test]
fn test_process_pull_request_response() {
@ -1243,13 +1237,7 @@ pub(crate) mod tests {
assert_eq!(same_key.label(), new.label());
assert!(same_key.wallclock() < new.wallclock());
node_crds.insert(same_key.clone(), 0).unwrap();
assert_eq!(
node_crds
.lookup_versioned(&same_key.label())
.unwrap()
.local_timestamp,
0
);
assert_eq!(node_crds.get(&same_key.label()).unwrap().local_timestamp, 0);
let mut done = false;
let mut pings = Vec::new();
let ping_cache = Mutex::new(ping_cache);
@ -1300,21 +1288,9 @@ pub(crate) mod tests {
)
.0;
assert_eq!(failed, 0);
assert_eq!(
node_crds
.lookup_versioned(&new.label())
.unwrap()
.local_timestamp,
1
);
assert_eq!(node_crds.get(&new.label()).unwrap().local_timestamp, 1);
// verify that the whole record was updated for dest since this is a response from dest
assert_eq!(
node_crds
.lookup_versioned(&same_key.label())
.unwrap()
.local_timestamp,
1
);
assert_eq!(node_crds.get(&same_key.label()).unwrap().local_timestamp, 1);
done = true;
break;
}
@ -1337,19 +1313,23 @@ pub(crate) mod tests {
0,
)));
node_crds.insert(old.clone(), 0).unwrap();
let value_hash = node_crds.lookup_versioned(&old.label()).unwrap().value_hash;
let value_hash = node_crds.get(&old.label()).unwrap().value_hash;
//verify self is valid
assert_eq!(node_crds.lookup(&node_label).unwrap().label(), node_label);
assert_eq!(
node_crds.get(&node_label).unwrap().value.label(),
node_label
);
// purge
let timeouts = node.make_timeouts(node_pubkey, &HashMap::new(), Duration::default());
node.purge_active(&thread_pool, &mut node_crds, node.crds_timeout, &timeouts);
//verify self is still valid after purge
assert_eq!(node_crds.lookup(&node_label).unwrap().label(), node_label);
assert_eq!(node_crds.lookup_versioned(&old.label()), None);
assert_eq!(
node_crds.get(&node_label).unwrap().value.label(),
node_label
);
assert_eq!(node_crds.get(&old.label()), None);
assert_eq!(node_crds.num_purged(), 1);
for _ in 0..30 {
// there is a chance of a false positive with bloom filters

View File

@ -459,7 +459,7 @@ mod test {
push.process_push_message(&mut crds, &Pubkey::default(), value.clone(), 0),
Ok(())
);
assert_eq!(crds.lookup(&label), Some(&value));
assert_eq!(crds.get(&label).unwrap().value, value);
// push it again
assert_matches!(
@ -843,7 +843,7 @@ mod test {
push.process_push_message(&mut crds, &Pubkey::default(), value.clone(), 0),
Ok(())
);
assert_eq!(crds.lookup(&label), Some(&value));
assert_eq!(crds.get(&label).unwrap().value, value);
// push it again
assert_matches!(