removes Crds::lookup and lookup_versioned (#17438)
This commit is contained in:
@ -683,14 +683,10 @@ impl ClusterInfo {
|
|||||||
where
|
where
|
||||||
F: FnOnce(&ContactInfo) -> Y,
|
F: FnOnce(&ContactInfo) -> Y,
|
||||||
{
|
{
|
||||||
let entry = CrdsValueLabel::ContactInfo(*id);
|
let label = CrdsValueLabel::ContactInfo(*id);
|
||||||
self.gossip
|
let gossip = self.gossip.read().unwrap();
|
||||||
.read()
|
let entry = gossip.crds.get(&label)?;
|
||||||
.unwrap()
|
Some(map(entry.value.contact_info()?))
|
||||||
.crds
|
|
||||||
.lookup(&entry)
|
|
||||||
.and_then(CrdsValue::contact_info)
|
|
||||||
.map(map)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lookup_contact_info_by_gossip_addr(
|
pub fn lookup_contact_info_by_gossip_addr(
|
||||||
@ -715,13 +711,11 @@ impl ClusterInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn lookup_epoch_slots(&self, ix: EpochSlotsIndex) -> EpochSlots {
|
pub fn lookup_epoch_slots(&self, ix: EpochSlotsIndex) -> EpochSlots {
|
||||||
let entry = CrdsValueLabel::EpochSlots(ix, self.id());
|
let label = CrdsValueLabel::EpochSlots(ix, self.id());
|
||||||
self.gossip
|
let gossip = self.gossip.read().unwrap();
|
||||||
.read()
|
let entry = gossip.crds.get(&label);
|
||||||
.unwrap()
|
entry
|
||||||
.crds
|
.and_then(|v| v.value.epoch_slots())
|
||||||
.lookup(&entry)
|
|
||||||
.and_then(CrdsValue::epoch_slots)
|
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or_else(|| EpochSlots::new(self.id(), timestamp()))
|
.unwrap_or_else(|| EpochSlots::new(self.id(), timestamp()))
|
||||||
}
|
}
|
||||||
@ -884,8 +878,8 @@ impl ClusterInfo {
|
|||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.crds
|
.crds
|
||||||
.lookup(&CrdsValueLabel::LowestSlot(self.id()))
|
.get(&CrdsValueLabel::LowestSlot(self.id()))
|
||||||
.and_then(|x| x.lowest_slot())
|
.and_then(|x| x.value.lowest_slot())
|
||||||
.map(|x| x.lowest)
|
.map(|x| x.lowest)
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
if min > last {
|
if min > last {
|
||||||
@ -1050,9 +1044,9 @@ impl ClusterInfo {
|
|||||||
(0..MAX_LOCKOUT_HISTORY as u8)
|
(0..MAX_LOCKOUT_HISTORY as u8)
|
||||||
.filter_map(|ix| {
|
.filter_map(|ix| {
|
||||||
let vote = CrdsValueLabel::Vote(ix, self_pubkey);
|
let vote = CrdsValueLabel::Vote(ix, self_pubkey);
|
||||||
let vote = gossip.crds.lookup(&vote)?;
|
let vote = gossip.crds.get(&vote)?;
|
||||||
num_crds_votes += 1;
|
num_crds_votes += 1;
|
||||||
match &vote.data {
|
match &vote.value.data {
|
||||||
CrdsData::Vote(_, vote) if should_evict_vote(vote) => {
|
CrdsData::Vote(_, vote) if should_evict_vote(vote) => {
|
||||||
Some((vote.wallclock, ix))
|
Some((vote.wallclock, ix))
|
||||||
}
|
}
|
||||||
@ -1073,8 +1067,8 @@ impl ClusterInfo {
|
|||||||
self.time_gossip_read_lock("gossip_read_push_vote", &self.stats.push_vote_read);
|
self.time_gossip_read_lock("gossip_read_push_vote", &self.stats.push_vote_read);
|
||||||
(0..MAX_LOCKOUT_HISTORY as u8).find(|ix| {
|
(0..MAX_LOCKOUT_HISTORY as u8).find(|ix| {
|
||||||
let vote = CrdsValueLabel::Vote(*ix, self.id());
|
let vote = CrdsValueLabel::Vote(*ix, self.id());
|
||||||
if let Some(vote) = gossip.crds.lookup(&vote) {
|
if let Some(vote) = gossip.crds.get(&vote) {
|
||||||
match &vote.data {
|
match &vote.value.data {
|
||||||
CrdsData::Vote(_, prev_vote) => match prev_vote.slot() {
|
CrdsData::Vote(_, prev_vote) => match prev_vote.slot() {
|
||||||
Some(prev_vote_slot) => prev_vote_slot == vote_slot,
|
Some(prev_vote_slot) => prev_vote_slot == vote_slot,
|
||||||
None => {
|
None => {
|
||||||
@ -3432,13 +3426,8 @@ mod tests {
|
|||||||
let d = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), timestamp());
|
let d = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), timestamp());
|
||||||
let label = CrdsValueLabel::ContactInfo(d.id);
|
let label = CrdsValueLabel::ContactInfo(d.id);
|
||||||
cluster_info.insert_info(d);
|
cluster_info.insert_info(d);
|
||||||
assert!(cluster_info
|
let gossip = cluster_info.gossip.read().unwrap();
|
||||||
.gossip
|
assert!(gossip.crds.get(&label).is_some());
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.crds
|
|
||||||
.lookup(&label)
|
|
||||||
.is_some());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assert_in_range(x: u16, range: (u16, u16)) {
|
fn assert_in_range(x: u16, range: (u16, u16)) {
|
||||||
@ -3711,7 +3700,7 @@ mod tests {
|
|||||||
let gossip = cluster_info.gossip.read().unwrap();
|
let gossip = cluster_info.gossip.read().unwrap();
|
||||||
let mut vote_slots = HashSet::new();
|
let mut vote_slots = HashSet::new();
|
||||||
for label in labels {
|
for label in labels {
|
||||||
match &gossip.crds.lookup(&label).unwrap().data {
|
match &gossip.crds.get(&label).unwrap().value.data {
|
||||||
CrdsData::Vote(_, vote) => {
|
CrdsData::Vote(_, vote) => {
|
||||||
assert!(vote_slots.insert(vote.slot().unwrap()));
|
assert!(vote_slots.insert(vote.slot().unwrap()));
|
||||||
}
|
}
|
||||||
|
@ -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> {
|
pub fn get(&self, label: &CrdsValueLabel) -> Option<&VersionedCrdsValue> {
|
||||||
self.table.get(label)
|
self.table.get(label)
|
||||||
}
|
}
|
||||||
|
@ -1197,14 +1197,8 @@ pub(crate) mod tests {
|
|||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
assert!(rsp.iter().all(|rsp| rsp.is_empty()));
|
assert!(rsp.iter().all(|rsp| rsp.is_empty()));
|
||||||
assert!(dest_crds.lookup(&caller.label()).is_some());
|
assert!(dest_crds.get(&caller.label()).is_some());
|
||||||
assert_eq!(
|
assert_eq!(dest_crds.get(&caller.label()).unwrap().local_timestamp, 1);
|
||||||
dest_crds
|
|
||||||
.lookup_versioned(&caller.label())
|
|
||||||
.unwrap()
|
|
||||||
.local_timestamp,
|
|
||||||
1
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_process_pull_request_response() {
|
fn test_process_pull_request_response() {
|
||||||
@ -1243,13 +1237,7 @@ pub(crate) mod tests {
|
|||||||
assert_eq!(same_key.label(), new.label());
|
assert_eq!(same_key.label(), new.label());
|
||||||
assert!(same_key.wallclock() < new.wallclock());
|
assert!(same_key.wallclock() < new.wallclock());
|
||||||
node_crds.insert(same_key.clone(), 0).unwrap();
|
node_crds.insert(same_key.clone(), 0).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(node_crds.get(&same_key.label()).unwrap().local_timestamp, 0);
|
||||||
node_crds
|
|
||||||
.lookup_versioned(&same_key.label())
|
|
||||||
.unwrap()
|
|
||||||
.local_timestamp,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
let mut done = false;
|
let mut done = false;
|
||||||
let mut pings = Vec::new();
|
let mut pings = Vec::new();
|
||||||
let ping_cache = Mutex::new(ping_cache);
|
let ping_cache = Mutex::new(ping_cache);
|
||||||
@ -1300,21 +1288,9 @@ pub(crate) mod tests {
|
|||||||
)
|
)
|
||||||
.0;
|
.0;
|
||||||
assert_eq!(failed, 0);
|
assert_eq!(failed, 0);
|
||||||
assert_eq!(
|
assert_eq!(node_crds.get(&new.label()).unwrap().local_timestamp, 1);
|
||||||
node_crds
|
|
||||||
.lookup_versioned(&new.label())
|
|
||||||
.unwrap()
|
|
||||||
.local_timestamp,
|
|
||||||
1
|
|
||||||
);
|
|
||||||
// verify that the whole record was updated for dest since this is a response from dest
|
// verify that the whole record was updated for dest since this is a response from dest
|
||||||
assert_eq!(
|
assert_eq!(node_crds.get(&same_key.label()).unwrap().local_timestamp, 1);
|
||||||
node_crds
|
|
||||||
.lookup_versioned(&same_key.label())
|
|
||||||
.unwrap()
|
|
||||||
.local_timestamp,
|
|
||||||
1
|
|
||||||
);
|
|
||||||
done = true;
|
done = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1337,19 +1313,23 @@ pub(crate) mod tests {
|
|||||||
0,
|
0,
|
||||||
)));
|
)));
|
||||||
node_crds.insert(old.clone(), 0).unwrap();
|
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
|
//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
|
// purge
|
||||||
let timeouts = node.make_timeouts(node_pubkey, &HashMap::new(), Duration::default());
|
let timeouts = node.make_timeouts(node_pubkey, &HashMap::new(), Duration::default());
|
||||||
node.purge_active(&thread_pool, &mut node_crds, node.crds_timeout, &timeouts);
|
node.purge_active(&thread_pool, &mut node_crds, node.crds_timeout, &timeouts);
|
||||||
|
|
||||||
//verify self is still valid after purge
|
//verify self is still valid after purge
|
||||||
assert_eq!(node_crds.lookup(&node_label).unwrap().label(), node_label);
|
assert_eq!(
|
||||||
|
node_crds.get(&node_label).unwrap().value.label(),
|
||||||
assert_eq!(node_crds.lookup_versioned(&old.label()), None);
|
node_label
|
||||||
|
);
|
||||||
|
assert_eq!(node_crds.get(&old.label()), None);
|
||||||
assert_eq!(node_crds.num_purged(), 1);
|
assert_eq!(node_crds.num_purged(), 1);
|
||||||
for _ in 0..30 {
|
for _ in 0..30 {
|
||||||
// there is a chance of a false positive with bloom filters
|
// there is a chance of a false positive with bloom filters
|
||||||
|
@ -459,7 +459,7 @@ mod test {
|
|||||||
push.process_push_message(&mut crds, &Pubkey::default(), value.clone(), 0),
|
push.process_push_message(&mut crds, &Pubkey::default(), value.clone(), 0),
|
||||||
Ok(())
|
Ok(())
|
||||||
);
|
);
|
||||||
assert_eq!(crds.lookup(&label), Some(&value));
|
assert_eq!(crds.get(&label).unwrap().value, value);
|
||||||
|
|
||||||
// push it again
|
// push it again
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
@ -843,7 +843,7 @@ mod test {
|
|||||||
push.process_push_message(&mut crds, &Pubkey::default(), value.clone(), 0),
|
push.process_push_message(&mut crds, &Pubkey::default(), value.clone(), 0),
|
||||||
Ok(())
|
Ok(())
|
||||||
);
|
);
|
||||||
assert_eq!(crds.lookup(&label), Some(&value));
|
assert_eq!(crds.get(&label).unwrap().value, value);
|
||||||
|
|
||||||
// push it again
|
// push it again
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
|
@ -180,13 +180,9 @@ fn ring_network_create(num: usize) -> Network {
|
|||||||
let start_info = {
|
let start_info = {
|
||||||
let start = &network[&keys[k]];
|
let start = &network[&keys[k]];
|
||||||
let start_id = start.lock().unwrap().id;
|
let start_id = start.lock().unwrap().id;
|
||||||
start
|
let label = CrdsValueLabel::ContactInfo(start_id);
|
||||||
.lock()
|
let gossip = start.gossip.lock().unwrap();
|
||||||
.unwrap()
|
gossip.crds.get(&label).unwrap().value.clone()
|
||||||
.crds
|
|
||||||
.lookup(&CrdsValueLabel::ContactInfo(start_id))
|
|
||||||
.unwrap()
|
|
||||||
.clone()
|
|
||||||
};
|
};
|
||||||
let end = network.get_mut(&keys[(k + 1) % keys.len()]).unwrap();
|
let end = network.get_mut(&keys[(k + 1) % keys.len()]).unwrap();
|
||||||
end.lock()
|
end.lock()
|
||||||
@ -226,7 +222,7 @@ fn connected_staked_network_create(stakes: &[u64]) -> Network {
|
|||||||
let start = &network[k].lock().unwrap();
|
let start = &network[k].lock().unwrap();
|
||||||
let start_id = start.id;
|
let start_id = start.id;
|
||||||
let start_label = CrdsValueLabel::ContactInfo(start_id);
|
let start_label = CrdsValueLabel::ContactInfo(start_id);
|
||||||
start.crds.lookup(&start_label).unwrap().clone()
|
start.crds.get(&start_label).unwrap().value.clone()
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
for end in network.values_mut() {
|
for end in network.values_mut() {
|
||||||
@ -275,11 +271,9 @@ fn network_simulator(thread_pool: &ThreadPool, network: &mut Network, max_conver
|
|||||||
// push a message to the network
|
// push a message to the network
|
||||||
network_values.par_iter().for_each(|locked_node| {
|
network_values.par_iter().for_each(|locked_node| {
|
||||||
let node = &mut locked_node.lock().unwrap();
|
let node = &mut locked_node.lock().unwrap();
|
||||||
let mut m = node
|
let label = CrdsValueLabel::ContactInfo(node.id);
|
||||||
.crds
|
let entry = node.crds.get(&label).unwrap();
|
||||||
.lookup(&CrdsValueLabel::ContactInfo(node.id))
|
let mut m = entry.value.contact_info().cloned().unwrap();
|
||||||
.and_then(|v| v.contact_info().cloned())
|
|
||||||
.unwrap();
|
|
||||||
m.wallclock = now;
|
m.wallclock = now;
|
||||||
node.process_push_message(
|
node.process_push_message(
|
||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
|
Reference in New Issue
Block a user