Skip to content

Commit

Permalink
Fix locking when downloading RIS dump files (#1177) (#1179)
Browse files Browse the repository at this point in the history
This PR does not lock the 'seen' announcements while downloading new RIR dump
files. This prevented read access to the announcement during download. This
change postpones getting the write lock until after the download is
completed, so it only keeps it for the shortest possible time.
  • Loading branch information
timbru authored Jun 12, 2024
1 parent 9311cca commit ea72c1e
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions src/commons/bgp/analyser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,36 @@ impl BgpAnalyser {
}

pub async fn update(&self) -> Result<bool, BgpAnalyserError> {
if let Some(loader) = &self.dump_loader {
let mut seen = self.seen.write().await;
if let Some(last_time) = seen.last_checked() {
if (last_time + Duration::minutes(BGP_RIS_REFRESH_MINUTES)) > Time::now() {
trace!("Will not check BGP Ris Dumps until the refresh interval has passed");
return Ok(false); // no need to update yet
}
}
let announcements = loader.download_updates().await?;
if seen.equivalent(&announcements) {
debug!("BGP Ris Dumps unchanged");
seen.update_checked();
Ok(false)
} else {
info!("Updated announcements ({}) based on BGP Ris Dumps", announcements.len());
seen.update(announcements);
Ok(true)
let loader = match self.dump_loader.as_ref() {
Some(loader) => loader,
None => return Ok(false)
};
if let Some(last_time) = self.seen.read().await.last_checked() {
if (last_time + Duration::minutes(BGP_RIS_REFRESH_MINUTES))
> Time::now()
{
trace!(
"Will not check BGP RIS dumps until the \
refresh interval has passed"
);
return Ok(false); // no need to update yet
}
} else {
}
let announcements = loader.download_updates().await?;
let mut seen = self.seen.write().await;
if seen.equivalent(&announcements) {
debug!("BGP Ris Dumps unchanged");
seen.update_checked();
Ok(false)
}
else {
info!(
"Updated announcements ({}) based on BGP Ris Dumps",
announcements.len()
);
seen.update(announcements);
Ok(true)
}
}

pub async fn analyse(
Expand Down Expand Up @@ -349,10 +358,11 @@ mod tests {
#[tokio::test]
#[ignore]
async fn download_ris_dumps() {
let bgp_ris_dump_v4_uri = "http://www.ris.ripe.net/dumps/riswhoisdump.IPv4.gz";
let bgp_ris_dump_v6_uri = "http://www.ris.ripe.net/dumps/riswhoisdump.IPv6.gz";

let analyser = BgpAnalyser::new(true, bgp_ris_dump_v4_uri, bgp_ris_dump_v6_uri);
let analyser = BgpAnalyser::new(
true,
"http://www.ris.ripe.net/dumps/riswhoisdump.IPv4.gz",
"http://www.ris.ripe.net/dumps/riswhoisdump.IPv6.gz",
);

assert!(analyser.seen.read().await.is_empty());
assert!(analyser.seen.read().await.last_checked().is_none());
Expand Down

0 comments on commit ea72c1e

Please sign in to comment.