diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 8e9e6dc0f67..7c47c639982 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -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) -> bool { let Some(last) = groups.end.checked_sub(1).filter(|last| *last >= groups.start) else { return true; @@ -10793,6 +10796,12 @@ impl Ordered { self.inner.poll_largest(waiter) } + /// Whether the publisher declared every start in `groups` skipped; see + /// [`Subscriber::is_skipped`]. + pub fn is_skipped(&self, groups: ops::Range) -> 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) diff --git a/rs/moq-stats/src/produce.rs b/rs/moq-stats/src/produce.rs index 5dfadba3838..54a597da756 100644 --- a/rs/moq-stats/src/produce.rs +++ b/rs/moq-stats/src/produce.rs @@ -463,6 +463,8 @@ struct Snapshot { largest: Option, /// The interval the newest group opened in, which the next group has to pass. opened: Option, + /// 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. @@ -481,6 +483,7 @@ impl Snapshot { group: None, largest: None, opened: None, + fresh: false, #[cfg(feature = "bench")] held: 0, #[cfg(feature = "bench")] @@ -488,6 +491,16 @@ impl Snapshot { } } + /// 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() } @@ -543,6 +556,9 @@ impl Snapshot { 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); @@ -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(), @@ -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; @@ -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 =