Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent out of order frames #298

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions digitiser-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition.workspace = true

[dependencies]
anyhow.workspace = true
chrono.workspace = true
clap.workspace = true
metrics.workspace = true
metrics-exporter-prometheus.workspace = true
Expand Down
12 changes: 12 additions & 0 deletions digitiser-aggregator/src/frame/cache.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::{partial::PartialFrame, AggregatedFrame};
use crate::data::{Accumulate, DigitiserData};
use chrono::{DateTime, Utc};
use std::{collections::VecDeque, fmt::Debug, time::Duration};
use supermusr_common::{record_metadata_fields_to_span, spanned::SpannedAggregator, DigitizerId};
use supermusr_streaming_types::FrameMetadata;
Expand All @@ -9,6 +10,7 @@ pub(crate) struct FrameCache<D: Debug> {
ttl: Duration,
expected_digitisers: Vec<DigitizerId>,

latest_timestamp_dispatched: Option<DateTime<Utc>>,
frames: VecDeque<PartialFrame<D>>,
}

Expand All @@ -20,6 +22,7 @@ where
Self {
ttl,
expected_digitisers,
latest_timestamp_dispatched: None,
frames: Default::default(),
}
}
Expand All @@ -31,6 +34,12 @@ where
metadata: &FrameMetadata,
data: D,
) {
if let Some(latest_timestamp_dispatched) = self.latest_timestamp_dispatched {
if metadata.timestamp <= latest_timestamp_dispatched {
warn!("Frame's timestamp earlier than or equal to the latest frame dispatched: {0} <= {1}", metadata.timestamp, latest_timestamp_dispatched);
return;
}
}
let frame = {
match self
.frames
Expand Down Expand Up @@ -92,6 +101,9 @@ where
if let Err(e) = frame.end_span() {
warn!("Frame span drop failed {e}")
}

// This frame is the next to be set to latest timestamp dispatched
self.latest_timestamp_dispatched = Some(frame.metadata.timestamp);
Some(frame.into())
} else {
None
Expand Down
Loading