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 @@ -141,7 +141,6 @@ removed).
- [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
- [A tightened SUBSCRIBE keeps the start's budget honest](/quest/m1/start-budget-update.md) - a relay copy records the delay its start was resolved under, so a SUBSCRIBE_UPDATE tightening cannot make later readers skip fillable history
- [Aborted copies don't hold an end open](/quest/m1/settled-abort.md) - a track's declared end settles when a fetched copy finishes a group whose live copy was cut or evicted
- [Broadcast archives](/quest/m1/archive/README.md) - ANNOUNCE, TRACKS, and a SUBSCRIBE per track record every track under a prefix to any object_store, a host serves a stored broadcast back, and the catalog drops its archive pointer for a per-rendition `hls` field
- [HLS recorder target](/quest/m1/hls-record-target.md) - the moq-cli HLS recorder takes its target duration from the declared `hls` duration
- [Compressed tracks](/quest/m1/compress/README.md) - a track flagged `compress` is DEFLATEd per group by moq-net, forwarded compressed, and inflated once on the relay for peers that cannot signal it; `catalog.json.z` and moq-flate go away
Expand Down
29 changes: 0 additions & 29 deletions quest/m1/settled-abort.md

This file was deleted.

156 changes: 148 additions & 8 deletions rs/moq-net/src/model/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,15 @@ impl Slot {
}
}

/// Whether the copy serving this slot finished, even one a transport bound cut short, so
/// nothing it promised a reader is still in flight. A fetched head serving the group to
/// its end is judged in place of the live copy beside it, which may still be written or
/// may have been cut or evicted. Once no head serves, an aborted live copy holds the end
/// open: a session that died mid-group delivered less than the end promised.
fn is_settled(&self) -> bool {
self.serving().is_settled()
}

/// Every copy this slot holds, the live group first.
fn copies(&self) -> impl Iterator<Item = &group::Handle> {
std::iter::once(&self.group).chain(self.head.as_deref())
Expand Down Expand Up @@ -2451,14 +2460,14 @@ impl TrackState {
}

/// Whether the declared end is reached, the pending tail owes nothing below it, and
/// every cached copy below it finished, even one a transport bound cut short, so
/// nothing the end promised is still in flight.
/// every cached slot below it settled ([`Slot::is_settled`]), so nothing the end
/// promised is still in flight.
fn is_settled(&self) -> bool {
let Some(fin) = self.final_sequence() else {
return false;
};
let reached = self.sealed || self.reaches(fin);
reached && !self.owes(fin) && self.lookup.range(..fin).all(|(_, slot)| slot.group.is_settled())
reached && !self.owes(fin) && self.lookup.range(..fin).all(|(_, slot)| slot.is_settled())
}

/// Record that the end settled before a write that could reopen it: an abort, a late
Expand Down Expand Up @@ -2626,14 +2635,19 @@ impl TrackState {
}
if self.is_complete() {
// An abort after the end settled keeps the clean end; until then a group below it
// may still abort, which would cut the track off, so wait for each to finish. One
// that aborts leaves the outcome to the track's own abort or drop.
// may still abort, which would cut the track off, so wait for each slot to settle
// ([`Slot::is_settled`]). One whose last serving copy aborts leaves the outcome to
// the track's own abort or drop.
if self.abort.is_none()
&& let Some(fin) = self.final_sequence()
{
for (_, slot) in self.lookup.range(..fin) {
// One poll, so a group finishing meanwhile is seen rather than slept on.
if !matches!(slot.group.poll_closed(waiter), Poll::Ready(Ok(()))) {
for (_, slot) in self.lookup.range(..fin).filter(|(_, slot)| !slot.is_settled()) {
// Watch every copy, since a serving head that aborts hands the slot back to
// the live group, then judge again so a copy closing meanwhile is seen.
for group in slot.copies() {
let _ = group.poll_closed(waiter);
}
if !slot.is_settled() {
return Poll::Pending;
}
}
Expand Down Expand Up @@ -16182,6 +16196,132 @@ mod test {
(live, head)
}

/// A live group with a fetched head of group 0 still writing, and the track's end
/// declared past it. The live copy ended as `live` says: aborted with it, else finished.
#[cfg(feature = "async")]
async fn live_group_under_a_writing_head(live: Option<Error>) -> (Producer, group::Producer) {
let mut producer = track_producer("test", Info::timed());
let dynamic = producer.requests();
let consumer = producer.consume();

let mut group = producer.create_group(group::Info { sequence: 0 }).unwrap();
group.start_at(1).unwrap();
group
.write_frame(Timestamp::ZERO, bytes::Bytes::from_static(b"delta"))
.unwrap();
let _fetch = consumer.fetch_group(0, None);
let mut head = dynamic
.requested_fill_group()
.await
.unwrap()
.accept(Info::timed())
.unwrap();
for payload in [&b"snapshot"[..], b"delta"] {
head.write_frame(Timestamp::ZERO, bytes::Bytes::from_static(payload))
.unwrap();
}

match live {
Some(err) => group.abort(err).unwrap(),
None => group.finish().unwrap(),
}
producer.finish_at(Position::group(1)).unwrap();
(producer, head)
}

/// The fetched head serving a group to its end settles the declared end once it finishes,
/// whether the live copy beside it was cut, evicted, or finished, and a later abort keeps
/// that clean end, whether `closed()` saw it first or only the abort did.
#[moq_clock::test]
#[cfg(feature = "async")]
async fn a_fetched_head_settles_the_end_once_it_finishes() {
use std::sync::atomic::{AtomicBool, Ordering};

for live in [Some(Error::Cancel), Some(Error::Evicted), None] {
for polled in [false, true] {
let (producer, mut head) = live_group_under_a_writing_head(live.clone()).await;
let woken = Arc::new(AtomicBool::new(false));
let waiter = kio::Waiter::new(futures::task::waker(Arc::new(FlagWake(woken.clone()))));
if polled {
assert!(
producer.poll_closed(&waiter).is_pending(),
"{live:?}: the head still writes"
);
}
head.finish().unwrap();
if polled {
assert!(
woken.load(Ordering::SeqCst),
"{live:?}: the head finishing wakes the wait"
);
assert!(matches!(producer.poll_closed(&waiter), Poll::Ready(Ok(()))), "{live:?}");
}

producer.clone().abort(Error::Timeout).unwrap();
let noop = kio::Waiter::noop();
assert!(
matches!(producer.poll_closed(&noop), Poll::Ready(Ok(()))),
"{live:?} polled={polled}"
);
assert!(
matches!(producer.consume().poll_complete(&noop), Poll::Ready(Ok(()))),
"{live:?} polled={polled}"
);
}
}
}

/// A fetched head aborting hands its group back to the live copy: a finished one settles
/// the end, while a cut one leaves nothing that delivered the group, so an abort still
/// cuts the track off.
#[moq_clock::test]
#[cfg(feature = "async")]
async fn an_aborted_head_hands_the_end_back_to_the_live_copy() {
use std::sync::atomic::{AtomicBool, Ordering};

for (live, settles) in [(None, true), (Some(Error::App(5)), false)] {
let (producer, head) = live_group_under_a_writing_head(live.clone()).await;
let woken = Arc::new(AtomicBool::new(false));
let waiter = kio::Waiter::new(futures::task::waker(Arc::new(FlagWake(woken.clone()))));
assert!(producer.poll_closed(&waiter).is_pending(), "{live:?}");

head.abort(Error::Cancel).unwrap();
assert!(
woken.load(Ordering::SeqCst),
"{live:?}: the head aborting wakes the wait"
);
assert_eq!(producer.poll_closed(&waiter).is_ready(), settles, "{live:?}");
producer.clone().abort(Error::Timeout).unwrap();
let outcome = producer.poll_closed(&kio::Waiter::noop());
match settles {
true => assert!(matches!(outcome, Poll::Ready(Ok(()))), "{live:?}: {outcome:?}"),
false => assert!(
matches!(outcome, Poll::Ready(Err(Error::Timeout))),
"{live:?}: {outcome:?}"
),
}
}
}

/// A finished fetched head serves its group to the end, so the declared end settles while
/// the live copy beside it is still written, and that copy aborting later keeps it clean.
#[moq_clock::test]
#[cfg(feature = "async")]
async fn a_finished_head_settles_the_end_over_an_open_live_copy() {
let mut producer = track_producer("test", Info::timed());
let consumer = producer.consume();
let noop = kio::Waiter::noop();
let (live, _head) = live_group_with_head(&producer).await;

producer.finish_at(Position::group(1)).unwrap();
assert!(matches!(producer.poll_closed(&noop), Poll::Ready(Ok(()))));

live.abort(Error::Cancel).unwrap();
producer.clone().abort(Error::Timeout).unwrap();
assert!(matches!(producer.poll_closed(&noop), Poll::Ready(Ok(()))));
assert!(matches!(consumer.poll_complete(&noop), Poll::Ready(Ok(()))));
}

/// A fetched head still writing holds the largest stream open after the live copy
/// aborted and the track ended, so a later head frame is reported rather than lost.
#[moq_clock::test]
Expand Down
Loading