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
1 change: 0 additions & 1 deletion quest/m1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ per-frame CPU growth since #5926.
- [moq-c at parity](/quest/m1/c/README.md) - the hand-written `moq-c` ships at the cut with every m1 binding feature moq-ffi gains
- [Bindings see a moq-transport run end as an end](/quest/m1/ffi-ietf-run-end.md) - an IETF publisher ending its run reaches moq-ffi consumers as an end, not `Internal`
- [Byte-stream renditions form a ladder](/quest/m1/stream-ladder.md) - moq-ffi stream producers link as `lower` and disable unfundable rungs like frame producers
- [A relay answers a SUBSCRIBE on a copy it kept after a fetch](/quest/m1/relay-fetched-copy-subscribe.md) - the downstream SUBSCRIBE_OK waits for the upstream edge instead of hanging
- [A job's exact route continues its claim's readers](/quest/m1/announce-takeover.md) - a job's route inherits its claim's instance, replacing the ANNOUNCE_TAKEOVER predecessor design
- [Subscribe ranges](/quest/m1/subscribe-ranges/README.md) - a lite-07 SUBSCRIBE asks for past and live ranges with absolute or relative ends, in either order, and replaces FETCH; merged ranges never starve a subscriber; relays fill misses by range, including over moq-transport
- [Drop set](/quest/m1/drop-set.md) - each cursor judges missing groups against its own budget, so a narrow reader drops promptly and a widening re-offers groups already reported dropped on lite-07
Expand Down
29 changes: 0 additions & 29 deletions quest/m1/relay-fetched-copy-subscribe.md

This file was deleted.

3 changes: 3 additions & 0 deletions rs/moq-net/src/ietf/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ fn serving_subscription(subscriber_priority: u8) -> Subscription {
priority: super::priority::from_wire(subscriber_priority),
// No Max Age is the publisher's retention alone, whatever it turns out to be.
max_delay: None,
// SUBSCRIBE_OK names the live edge, which a relay learns only from its upstream's
// answer: never from its cache, nor from an edge reported before.
feed: true,
..Default::default()
}
}
Expand Down
78 changes: 33 additions & 45 deletions rs/moq-net/src/ietf/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,15 +756,15 @@ fn largest_group(track: &track::Producer, answer: Option<ietf::Location>) -> Opt
}

/// Whether `subscription` needs a live feed for a copy whose publisher reported its Largest
/// Object in group `edge`: one of its ranges is open, counts back from the live edge, or
/// reaches the group the publisher may still be writing. Ranges wholly below it read only
/// history, which fills serve.
/// Object in group `edge`: a reader asked for it ([`track::Subscription::feed`]), or one of
/// its ranges is open, counts back from the live edge, or reaches the group the publisher
/// may still be writing. Ranges wholly below it read only history, which fills serve.
fn wants_feed(subscription: &track::Subscription, edge: Option<u64>) -> bool {
if subscription.ranges.is_empty() {
return false;
}
let history = subscription.start().is_some() && subscription.end().zip(edge).is_some_and(|(end, edge)| end <= edge);
!history
subscription.feed || !history
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

/// A copy with no subscription upstream, kept for fetches and a returning subscriber.
Expand Down Expand Up @@ -2966,13 +2966,7 @@ impl Subscriber {
}
};
let start = subscription.as_ref().and_then(|s| s.start());
let join = match subscribe_join(start, subscription.as_ref().and_then(|s| s.end()), self.version) {
Ok(join) => join,
Err(err) => {
target.fail(err);
return None;
}
};
let join = subscribe_join(start, subscription.as_ref().and_then(|s| s.end()), self.version);
// A live join delivers nothing below the group SUBSCRIBE_OK names as Largest. Every
// draft-18 join is one, since its joining FETCH carries that group alone.
let live = start.is_none() || join.fetch;
Expand Down Expand Up @@ -3590,7 +3584,17 @@ impl Subscriber {
&& (poll_headed(&fill, waiter).is_ready()
|| largest.is_some_and(|largest| track.poll_past(largest.group, waiter).is_ready()))
{
track.set_live(largest, None);
// An absolute feed starts where it asked, whatever the answer's Largest; a
// live join's starts there.
let from = sent_bounds.0.filter(|_| !live);
match largest {
// A feed ending before the answer's Largest never shows it, so the
// answer alone makes the copy current. A live join's feed is open.
Some(largest) if !live && sent_bounds.1.is_some_and(|end| end <= largest.group) => {
track.set_live_ahead(largest, from)
}
largest => track.set_live(largest, from),
}
resuming = None;
}
// The last subscriber left: the upstream subscription goes with it, as on
Expand Down Expand Up @@ -3665,10 +3669,7 @@ impl Subscriber {
};
let ranges = if bounds != sent_bounds {
let mut join = if Filter::is_draft20(self.version) {
match subscribe_join(bounds.0, bounds.1, self.version) {
Ok(join) => join,
Err(err) => return Poll::Ready(End::Invalid(err)),
}
subscribe_join(bounds.0, bounds.1, self.version)
} else {
Join {
filter: match bounds {
Expand Down Expand Up @@ -12124,24 +12125,22 @@ struct Join {
/// Earlier drafts have no fill parameter. Every subscription is a live join: Largest
/// Object, followed by a joining FETCH relative at offset 0 for that group's head. An
/// earlier start's groups are left to the copy's fills, one FETCH per run of them, and a
/// later start skips the head locally. A bounded end has no
/// joining-FETCH spelling, so it is refused rather than left open.
/// later start skips the head locally. A bounded end has no joining-FETCH spelling
/// either, so the join stays open and readers stop at their own end: refusing it would
/// abort a resumed copy for every reader it serves.
///
/// A start group we already know is absolute on draft-22 and needs no fill: the
/// subscription's own range covers it, which is what our publisher serves from its cache.
fn subscribe_join(start: Option<u64>, end: Option<u64>, version: Version) -> Result<Join, Error> {
fn subscribe_join(start: Option<u64>, end: Option<u64>, version: Version) -> Join {
if !Filter::is_draft20(version) {
if end.is_some() {
return Err(Error::Unsupported);
}
return Ok(Join {
return Join {
filter: Filter::NextObject,
fill: None,
fetch: true,
});
};
}

Ok(match start {
match start {
// The live join: everything after the live edge, plus the current group's head.
None => Join {
filter: Filter::NextObject,
Expand Down Expand Up @@ -12175,7 +12174,7 @@ fn subscribe_join(start: Option<u64>, end: Option<u64>, version: Version) -> Res
fill: None,
fetch: false,
},
})
}
}

/// Resolve the first absolute ID or a later ID delta without overflowing. Subgroup relay
Expand Down Expand Up @@ -12223,7 +12222,7 @@ mod filter_tests {
#[test]
fn live_joins_the_current_group_with_a_fill() {
assert_eq!(
subscribe_join(None, None, Version::Draft22).unwrap(),
subscribe_join(None, None, Version::Draft22),
Join {
filter: Filter::NextObject,
fill: Some(ietf::Fill {
Expand All @@ -12241,7 +12240,7 @@ mod filter_tests {
#[test]
fn a_past_start_is_absolute() {
assert_eq!(
subscribe_join(Some(7), Some(10), Version::Draft22).unwrap(),
subscribe_join(Some(7), Some(10), Version::Draft22),
Join {
filter: Filter::Absolute {
start: ietf::Location { group: 7, object: 0 },
Expand All @@ -12257,7 +12256,7 @@ mod filter_tests {
#[test]
fn the_whole_track_is_unfiltered() {
assert_eq!(
subscribe_join(Some(0), None, Version::Draft22).unwrap(),
subscribe_join(Some(0), None, Version::Draft22),
Join {
filter: Filter::Unfiltered,
fill: None,
Expand All @@ -12268,36 +12267,25 @@ mod filter_tests {

const JOINING_DRAFTS: [Version; 1] = [Version::Draft18];

/// Every draft-18 join is Largest Object plus a joining FETCH, whatever its start,
/// so the current group's head arrives on the fetch stream and the live tail on the
/// Every draft-18 join is Largest Object plus a joining FETCH, whatever its start or
/// end, so the current group's head arrives on the fetch stream and the live tail on the
/// subscription.
#[test]
fn older_drafts_always_join_live() {
for version in JOINING_DRAFTS {
for start in [None, Some(7)] {
for (start, end) in [(None, None), (Some(7), None), (Some(7), Some(10))] {
assert_eq!(
subscribe_join(start, None, version).unwrap(),
subscribe_join(start, end, version),
Join {
filter: Filter::NextObject,
fill: None,
fetch: true,
},
"{version} from {start:?}"
"{version} from {start:?} to {end:?}"
);
}
}
}

/// A bounded end has no joining-FETCH spelling, so it is refused rather than left open.
#[test]
fn older_drafts_refuse_a_bounded_end() {
for version in JOINING_DRAFTS {
assert!(
matches!(subscribe_join(Some(7), Some(10), version), Err(Error::Unsupported)),
"{version}"
);
}
}
}

/// Draft-22's current-group join, where one group arrives on two streams: the fill fetch
Expand Down
7 changes: 7 additions & 0 deletions rs/moq-net/src/model/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ pub struct Subscription {
/// subscribers fresh. Each subscriber's own publisher (a relay's downstream session)
/// still serves it in its own order.
pub order: Order,
/// Whether this reader needs the source's live feed, not only its history: a wire
/// publisher owes its peer an answer naming the live edge, which only the upstream's own
/// answer gives. A session holding no upstream subscription for its copy subscribes again
/// for such a reader, whatever its ranges. Aggregated as any: one such reader is enough.
pub(crate) feed: bool,
}

/// Which of a subscription's pending groups the publisher sends first.
Expand Down Expand Up @@ -294,6 +299,7 @@ impl Default for Subscription {
max_delay: Some(Duration::ZERO),
ranges: vec![Range::oldest()],
order: Order::Descending,
feed: false,
}
}
}
Expand Down Expand Up @@ -475,6 +481,7 @@ impl Combined {
if let Order::Descending = sub.order {
combined.order = Order::Descending;
}
combined.feed |= sub.feed;
}

/// The aggregate, or `None` without a subscriber.
Expand Down
27 changes: 26 additions & 1 deletion rs/moq-net/src/model/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2846,6 +2846,21 @@ impl TrackState {
/// read as the live edge, though the route already holds a newer one.
#[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))]
fn set_live(&mut self, largest: Option<Position>, start: Option<u64>) {
self.answered(largest, start, true);
}

/// [`Self::set_live`] for a feed that serves no group from `largest`'s on, such as a
/// bounded subscription of history: the cache can never show that group, so the answer
/// alone makes it current, and relative starts count back from that group.
#[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))]
fn set_live_ahead(&mut self, largest: Position, start: Option<u64>) {
self.answered(Some(largest), start, false);
}

/// The route answered with `largest`. With `reaches`, its feed reaches that group, so
/// readers wait until the cache shows it.
#[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))]
fn answered(&mut self, largest: Option<Position>, start: Option<u64>, reaches: bool) {
let Feed::Idle { newest } = self.feed else {
return;
};
Expand All @@ -2868,7 +2883,7 @@ impl TrackState {
_ => self.live_floor,
};
match largest.map(|largest| largest.group) {
Some(from) if !self.shows(from) => self.feed = Feed::Answered { from },
Some(from) if reaches && !self.shows(from) => self.feed = Feed::Answered { from },
edge => self.go_live(edge),
}
}
Expand Down Expand Up @@ -3686,6 +3701,16 @@ impl Producer {
}
}

/// [`Self::set_live`] for a feed that serves no group from `largest`'s on, such as a
/// bounded subscription of history: readers resume at once, counting relative starts
/// back from `largest`'s group. A no-op unless idle.
#[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))]
pub(crate) fn set_live_ahead(&mut self, largest: Position, start: Option<u64>) {
if let Ok(mut state) = self.modify() {
state.set_live_ahead(largest, start);
}
}

/// Whether a subscription feeds this copy: its session holds one upstream for it, or
/// none, so nothing reaches it but what fills answer. Only the session knows, from its
/// own state; the cache never tells. While unfed, a bounded read's holes are misses up
Expand Down
11 changes: 9 additions & 2 deletions rs/moq-net/src/model/track/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub(super) struct Subscriptions {
max_delay: BTreeMap<Duration, usize>,
ranges: Ranges,
descending: usize,
/// Subscribers that need the live feed; see [`Subscription::feed`].
feed: usize,
/// The lowest group consumers want while no refresh is pending, never lowered. See
/// [`super::Demand::wanted`].
wanted: u64,
Expand All @@ -35,16 +37,17 @@ pub(super) struct Subscriptions {
}

/// Everything the aggregate holds besides its ranges.
type Scalars = (i8, Option<Duration>, Order);
type Scalars = (i8, Option<Duration>, Order, bool);

impl Subscriptions {
pub(super) fn combined(&self) -> Option<Subscription> {
let (priority, max_delay, order) = self.scalars()?;
let (priority, max_delay, order, feed) = self.scalars()?;
Some(Subscription {
priority,
max_delay,
ranges: self.ranges.union(),
order,
feed,
})
}

Expand All @@ -65,6 +68,7 @@ impl Subscriptions {
} else {
Order::Descending
},
self.feed != 0,
)
})
}
Expand Down Expand Up @@ -140,6 +144,7 @@ impl Subscriptions {
}
}
self.descending += usize::from(new.order == Order::Descending);
self.feed += usize::from(new.feed);
self.count += 1;
}
if let Some(old) = old {
Expand All @@ -151,6 +156,7 @@ impl Subscriptions {
}
}
self.descending -= usize::from(old.order == Order::Descending);
self.feed -= usize::from(old.feed);
self.count -= 1;
}
if reshaped || self.scalars() != prev {
Expand Down Expand Up @@ -315,6 +321,7 @@ mod tests {
} else {
Order::Descending
},
feed: rng.random_bool(0.25),
};
match (&mut slots[index], rng.random_range(0..3)) {
(slot @ None, _) => *slot = Some((producer.subscribe(next.clone()), next)),
Expand Down
Loading
Loading