Skip to content
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
9 changes: 9 additions & 0 deletions rs/moq-net/src/model/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10223,6 +10223,9 @@ impl Subscriber {
/// subscriber's ranges. A copy knows only the skips its wire forwarded.
///
/// What tells a reader that nothing lies between two groups, or before a track's first.
/// It knows only the skips recorded so far, so `false` means "not known skipped": a skip
/// still in flight reads `false`, as does one a local producer's cache expired below its
/// edge. A reader that asks once treats such a group as one with something before it.
pub fn is_skipped(&self, groups: ops::Range<u64>) -> bool {
let Some(last) = groups.end.checked_sub(1).filter(|last| *last >= groups.start) else {
return true;
Expand Down Expand Up @@ -10793,6 +10796,12 @@ impl Ordered {
self.inner.poll_largest(waiter)
}

/// Whether the publisher declared every start in `groups` skipped; see
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
/// [`Subscriber::is_skipped`].
pub fn is_skipped(&self, groups: ops::Range<u64>) -> bool {
self.inner.is_skipped(groups)
}

/// Whether `other` reads the same underlying track state.
pub fn is_clone(&self, other: &Self) -> bool {
self.inner.is_clone(&other.inner)
Expand Down
27 changes: 24 additions & 3 deletions rs/moq-stats/src/produce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ struct Snapshot<T> {
largest: Option<u64>,
/// The interval the newest group opened in, which the next group has to pass.
opened: Option<u64>,
/// The track's name is new, so nothing comes before its first group, and it says so.
fresh: bool,
deltas: bool,
/// The newest snapshot payload written, and what the last update wrote
/// (zero when nothing). Bench builds only.
Expand All @@ -481,13 +483,24 @@ impl<T: Serialize> Snapshot<T> {
group: None,
largest: None,
opened: None,
fresh: false,
#[cfg(feature = "bench")]
held: 0,
#[cfg(feature = "bench")]
wrote: 0,
}
}

/// Declare every start below the first group skipped, for a track whose name no earlier
/// run used: a reader then knows the first group it reads opens the track
/// ([`moq_net::track::Subscriber::is_skipped`]). A reader the skip hasn't reached, in
/// flight or forgotten by this relay's cache, reads the first group as a later one, so
/// a meter that bills a run from zero only on its first group never counts it twice.
fn fresh(mut self) -> Self {
self.fresh = true;
self
}

fn demand(&self) -> moq_net::track::Demand {
self.track.demand()
}
Expand Down Expand Up @@ -543,6 +556,9 @@ impl<T: Serialize> Snapshot<T> {
if let Some(group) = self.group.take() {
group.close()?;
}
if self.fresh && self.largest.is_none() {
self.track.skip_groups(0..start);
}
self.group = Some(self.track.append_group(start)?);
self.largest = Some(start);
self.opened = Some(stamp.group);
Expand Down Expand Up @@ -908,7 +924,7 @@ impl BucketTrack {
let track = broadcast.create_track(name.as_str(), info())?;
Ok(Self {
name,
snapshot: Snapshot::new(track, config()),
snapshot: Snapshot::new(track, config()).fresh(),
body: BucketBody {
epoch,
tiers: Frame::default(),
Expand Down Expand Up @@ -3168,7 +3184,7 @@ mod tests {
let registry = producer.registry();
let (_, broadcast) = announced(&origin).await;
let stats = crate::Consumer::new(broadcast.clone(), Default::default());
// The listed run's name, and the start of its first group.
// The listed run's name, and the start of its first group, which nothing comes before.
let run = async |broadcast: &moq_net::broadcast::Consumer| {
let name = crate::listed_bucket_track(broadcast, &moq_net::Path::from_static("acme")).await;
let mut track = subscribe(broadcast, &name).await;
Expand All @@ -3177,7 +3193,12 @@ mod tests {
let start = group.unwrap().unwrap().start;
first = Some(first.map_or(start, |first: u64| first.min(start)));
}
(name, first)
let first = first.expect("a run's first group is listed");
assert!(
track.is_skipped(0..first),
"a run says nothing precedes its first group"
);
(name, Some(first))
};

let session =
Expand Down