diff --git a/drafts/draft-lcurley-moq-ietf.md b/drafts/draft-lcurley-moq-ietf.md index 5dde8cbb77a..f1d6514818c 100644 --- a/drafts/draft-lcurley-moq-ietf.md +++ b/drafts/draft-lcurley-moq-ietf.md @@ -70,7 +70,6 @@ A Group Stream, FETCH response, or datagram is read with the Version of its trac # Group Streams {#group} When the extension is negotiated, a Group Stream carries a Group State after the GROUP message, and an Object Record before each FRAME. A FETCH response carries the same, with the Group State first. -A FETCH for a track with a Version MUST NOT set a non-zero `Start Byte`, since an Object Record names a whole object; a publisher MUST reset the response with a PROTOCOL_VIOLATION otherwise. ~~~ Group Stream { @@ -266,7 +265,6 @@ A high, distinctive value is used to avoid collisions with the low values {{moql ## Since draft-lcurley-moq-ietf-00 (in progress) -- A FETCH for a track with a Version never starts partway into a frame. - A relay never restates the Max Age as MAX_CACHE_DURATION, and a sealed MAX_CACHE_DURATION is advisory. - Preserve relayed track timestamps and their unchecked MoQ Transport provenance across negotiated hops. Without the extension a relay serves them as native moq-lite timestamps rather than untimed. - Initial version. diff --git a/drafts/draft-lcurley-moq-lite.md b/drafts/draft-lcurley-moq-lite.md index 7a4f1e92dd5..66b1073b584 100644 --- a/drafts/draft-lcurley-moq-lite.md +++ b/drafts/draft-lcurley-moq-lite.md @@ -215,7 +215,6 @@ A subscriber that has received frames 0 through `N-1` of group `G` and wants the This is what lets a subscriber move a Track to a different publisher partway through a Group instead of waiting for the next Group to start, which matters for Tracks whose current Group may stay open indefinitely. A Group can therefore be assembled from more than one publisher: each contributes a disjoint run of frames, and the subscriber concatenates them in index order. -A subscriber that has received the first `B` bytes of frame `N` FETCHes `G` from frame `N` with a `Start Byte` of `B`, so a frame read partway on one publisher continues on another without sending its first bytes again. A partial Group is only ever delivered to a subscriber that asked for one with FETCH, or as the [continuation](#yield) of a paused Group. A publisher that holds only part of a Group a subscription covers names it in a [SUBSCRIBE_DROP](#subscribe-drop) rather than deliver the part it holds. @@ -2240,7 +2239,6 @@ FETCH Message { Subscriber Max Age (i) Group Sequence (i) Frame Start (i) - Start Byte (i) Frame End (i) } ~~~ @@ -2269,11 +2267,6 @@ The sequence number of the group to fetch. The index of the first frame to return within the group (see [Positions](#positions)). A plain absolute index; 0 means the start of the group (default). -**Start Byte**: -The offset of the first payload byte to return within the frame at `Frame Start`; 0 means the whole frame (default). -The first FRAME of the response still states that frame's full size, and carries only its payload from `Start Byte` on; later frames are whole. -A non-zero `Start Byte` at or past the frame's size is a protocol violation, since the rest of a frame is never empty, and so is a non-zero `Start Byte` on a Track whose `Compression` is not none, since a compressed frame inflates only from its first byte, or on a Track carrying a MoqTransport Version under the `ietf` extension, whose object records name whole objects. - **Frame End**: The last frame to return (inclusive), encoded as the absolute frame index + 1. A value of 0 means through the end of the group (default). @@ -2578,7 +2571,6 @@ An application-specific payload. - Added `Group Order` to SUBSCRIBE and SUBSCRIBE_UPDATE: descending (0x0, the previous fixed order) or ascending (0x1). - Added an optional `Subscriber Min Age` to SUBSCRIBE and SUBSCRIBE_UPDATE, the subscriber's target latency, encoded as milliseconds plus one with zero meaning not stated. A relay forwards the smallest stated value. - FETCH reads one Group or a slice of one, and SUBSCRIBE reads whole Groups: a read starting partway through a Group FETCHes it. A publisher holding only part of a Group a subscription covers drops it. -- Added `Start Byte` to FETCH, after `Frame Start`: the response's first frame states its full size and carries only its payload from that byte, so a frame read partway on one publisher continues on another from where it stopped. - A SUBSCRIBE_UPDATE that lowers a `Start` covers the groups below the old start that the publisher still holds, not only those that arrive later. A group already sent is not sent again. - Replaced SUBSCRIBE_OK `Group` with a `Range Start` per Range: the Group where that Range's delivery starts, including at a Relative or Time Anchor, from which its Groups are owed. - Each Range takes an implicit Range ID, and SUBSCRIBE_UPDATE edits the live Ranges instead of restating them: `Remove Count` Range IDs to retire, then the Ranges to add. The live Ranges must stay non-empty and fit in one SUBSCRIBE. A Range resolves its Anchors once, however many updates leave it live. diff --git a/js/net/src/lite/fetch.test.ts b/js/net/src/lite/fetch.test.ts index 63d2655facd..7ad10d9c6c1 100644 --- a/js/net/src/lite/fetch.test.ts +++ b/js/net/src/lite/fetch.test.ts @@ -89,7 +89,6 @@ test("Fetch decodes the optional delay offset before converting to milliseconds" await w.u62(delay + 1n); await w.u62(42n); await w.u53(0); // start frame - await w.u53(0); // start byte await w.u53(0); // through the end }), ); @@ -101,20 +100,3 @@ test("Fetch decodes the optional delay offset before converting to milliseconds" unsafe.maxDelay = Number.MAX_SAFE_INTEGER + 1; await expect(encode(version, unsafe)).rejects.toThrow(RangeError); }); - -test("Fetch carries a start byte only on draft-07, beside its start frame", async () => { - const partway = () => - new Fetch({ - broadcast: Path.from("room/1"), - track: "video", - priority: 3, - group: 42n, - startFrame: 2, - startByte: 1 << 20, - endFrame: 5, - }); - const got = await roundtrip(Version.DRAFT_07, partway()); - expect([got.startFrame, got.startByte, got.endFrame]).toEqual([2, 1 << 20, 5]); - await expect(encode(Version.DRAFT_06, partway())).rejects.toThrow("start byte"); - expect((await roundtrip(Version.DRAFT_06, sample())).startByte).toBe(0); -}); diff --git a/js/net/src/lite/fetch.ts b/js/net/src/lite/fetch.ts index b4f9ee49012..8d9e223b426 100644 --- a/js/net/src/lite/fetch.ts +++ b/js/net/src/lite/fetch.ts @@ -5,7 +5,7 @@ import * as Duration from "./duration.ts"; import { decodeNode, decodePin, encodeNode, encodePin } from "./instance.ts"; import * as Message from "./message.ts"; import { fromWire, toWire } from "./priority.ts"; -import { hasByteStart, hasFetchMaxDelay, hasFrameBounds, Version } from "./version.ts"; +import { hasFetchMaxDelay, hasFrameBounds, Version } from "./version.ts"; function guardFetch(version: Version) { switch (version) { @@ -34,12 +34,6 @@ export class Fetch { /** Index of the first frame to return; 0 is the start of the group. Lite-06+. */ startFrame: number; - /** - * Offset of the first byte to return within frame {@link startFrame}; 0 is the whole - * frame. The response still states that frame's full size. Lite-07+. - */ - startByte: number; - /** * Index of the last frame to return (inclusive), or undefined for through the end * of the group. Lite-06+. @@ -56,7 +50,6 @@ export class Fetch { maxDelay, group, startFrame = 0, - startByte = 0, endFrame, }: { broadcast: Path.Valid; @@ -68,7 +61,6 @@ export class Fetch { maxDelay?: number; group: bigint; startFrame?: number; - startByte?: number; endFrame?: number; }) { this.broadcast = broadcast; @@ -80,7 +72,6 @@ export class Fetch { this.maxDelay = maxDelay; this.group = group; this.startFrame = startFrame; - this.startByte = startByte; this.endFrame = endFrame; } @@ -94,17 +85,13 @@ export class Fetch { else if (this.maxDelay !== undefined) throw new Error("fetch maxDelay not supported for this version"); await w.u62(this.group); - if (!hasFrameBounds(version) && (this.startFrame !== 0 || this.endFrame !== undefined)) { + if (hasFrameBounds(version)) { + await w.u53(this.startFrame); + await w.u53(this.endFrame !== undefined ? this.endFrame + 1 : 0); + } else if (this.startFrame !== 0 || this.endFrame !== undefined) { // The peer would serve the whole group, including frames we excluded. throw new Error("frame bounds not supported for this version"); } - if (!hasByteStart(version) && this.startByte !== 0) { - // The peer would resend the frame from its start, misaligning the reader. - throw new Error("fetch start byte not supported for this version"); - } - if (hasFrameBounds(version)) await w.u53(this.startFrame); - if (hasByteStart(version)) await w.u53(this.startByte); - if (hasFrameBounds(version)) await w.u53(this.endFrame !== undefined ? this.endFrame + 1 : 0); } static async #decode(r: Reader, version: Version): Promise { @@ -121,7 +108,6 @@ export class Fetch { } const startFrame = await r.u53(); - const startByte = hasByteStart(version) ? await r.u53() : 0; const endFrame = await r.u53(); if (endFrame > 0 && endFrame - 1 < startFrame) { throw new Error("fetch frame range ends before it starts"); @@ -137,7 +123,6 @@ export class Fetch { maxDelay, group, startFrame, - startByte, endFrame: endFrame > 0 ? endFrame - 1 : undefined, }); } diff --git a/js/net/src/lite/publisher.ts b/js/net/src/lite/publisher.ts index ba42f19c5ad..f8db6980650 100644 --- a/js/net/src/lite/publisher.ts +++ b/js/net/src/lite/publisher.ts @@ -36,7 +36,7 @@ import { } from "../internal.ts"; import type { Consumer as OriginConsumer } from "../origin.ts"; import * as Path from "../path.ts"; -import { readSize, sendPayload, sendPayloadFrom } from "../payload.ts"; +import { readSize, sendPayload } from "../payload.ts"; import { Priority, sendOrder } from "../priority.ts"; import { rescale } from "../rescale.ts"; import { concat, encodeVarint, type Reader, type Stream, type StreamVersion, Writer } from "../stream.ts"; @@ -276,10 +276,7 @@ type ServeGroup = { }; /** What serving fetched frames needs beyond the group and destination stream. */ -type ServeFetch = Omit & { - /** The byte frame `start` is served from: only its rest follows its full-size header. */ - byte: number; -}; +type ServeFetch = Omit; /** What the serving loop takes from the subscribe stream instead of serving a group. */ type Control = @@ -1389,7 +1386,6 @@ export class Publisher { stamp: stamping(this.version, info), compress: info.compress, start: msg.startFrame, - byte: msg.startByte, end: msg.endFrame, }); console.debug(`fetch done: broadcast=${msg.broadcast} track=${msg.track} group=${msg.group}`); @@ -2431,10 +2427,8 @@ export class Publisher { async #runFetchGroup( group: group.Consumer, stream: Writer, - { stamp, compress, start: startFrame, byte, end: endFrame }: ServeFetch, + { stamp, compress, start: startFrame, end: endFrame }: ServeFetch, ) { - // A compressed frame inflates only from its first byte; no subscriber asks for less. - if (byte > 0 && compress) throw new Error("a compressed frame is served whole"); // The response carries no header, so the receiver numbers the first frame it gets // as `startFrame`. Skipping the head here is the only thing keeping those numbers // honest; a group that ends before we reach it can't be served at all. @@ -2459,14 +2453,11 @@ export class Publisher { prevTs = ts; } - // The first frame states its full size, then carries only the bytes from `byte`. - const skip = index === startFrame ? byte : 0; - const size = readSize(read); - // A non-zero start byte names a byte of the frame, so the rest is never empty. - if (skip > 0 && skip >= size) throw new Error(`fetch start byte ${skip} not within the frame's ${size}`); - await stream.write(frameHeader(stream.version, delta, read.inflated, size, hasLengthFirst(this.version))); - if (read.chunks) await sendPayloadFrom(read.chunks, skip, (chunk) => stream.write(chunk), stream.closed); - else if (frame.payload.length > skip) await stream.write(frame.payload.subarray(skip)); + await stream.write( + frameHeader(stream.version, delta, read.inflated, readSize(read), hasLengthFirst(this.version)), + ); + if (read.chunks) await sendPayload(read.chunks, (chunk) => stream.write(chunk), stream.closed); + else if (frame.payload.length > 0) await stream.write(frame.payload); } } diff --git a/js/net/src/lite/version.ts b/js/net/src/lite/version.ts index 4f82bc102ea..b635e705bb4 100644 --- a/js/net/src/lite/version.ts +++ b/js/net/src/lite/version.ts @@ -311,12 +311,6 @@ export function hasRanges(version: Version): boolean { } } -/** Whether FETCH carries a Start Byte within its first frame, so a reader cut off partway - * through a frame asks for only the rest of it. Added in lite-07. */ -export function hasByteStart(version: Version): boolean { - return hasFetchMaxDelay(version); -} - /** Whether FETCH carries the subscriber's optional max delay. Added in lite-07; an earlier * fetch is bounded by the publisher's max age alone. */ export function hasFetchMaxDelay(version: Version): boolean { diff --git a/js/net/src/payload.ts b/js/net/src/payload.ts index 6be11ce3552..c7c1537945f 100644 --- a/js/net/src/payload.ts +++ b/js/net/src/payload.ts @@ -76,24 +76,13 @@ export async function sendPayload( write: (chunk: Uint8Array) => Promise, closed: Promise, ): Promise { - return sendPayloadFrom(chunks, 0, write, closed); -} - -/** {@link sendPayload}, writing only the bytes from offset `skip` on. */ -export async function sendPayloadFrom( - chunks: frame.Consumer, - skip: number, - write: (chunk: Uint8Array) => Promise, - closed: Promise, -): Promise { - for (let read = 0; ; ) { + for (let sent = 0; ; ) { const chunk = await hooks.readFrameChunk(chunks, closed); if (!(chunk instanceof Uint8Array)) { - if (read < chunks.size) throw new Error("stream closed mid-frame"); + if (sent < chunks.size) throw new Error("stream closed mid-frame"); return; } - const from = Math.max(0, skip - read); - read += chunk.byteLength; - if (from < chunk.byteLength) await write(chunk.subarray(from)); + sent += chunk.byteLength; + await write(chunk); } } diff --git a/quest/m2/fetch-start-byte.md b/quest/m2/fetch-start-byte.md deleted file mode 100644 index 31c695b9863..00000000000 --- a/quest/m2/fetch-start-byte.md +++ /dev/null @@ -1,30 +0,0 @@ -# [S] lite-07 freezes without FETCH Start Byte - -## Goal - -lite-07's FETCH carries no Start Byte: a failover mid-frame refetches the -frame and skips what was read, as before -[moq-dev/moq#8699](https://github.com/moq-dev/moq/pull/8699), and the draft, -Rust, and JS match. - -## Plan - -Found 2026-11-14 by the [feature review](/quest/m3/release/feature-review.md). -Frames are capped at `MAX_CACHE_BYTES`, 32 MiB (`rs/moq-net/src/model/group.rs`). -Whole-frame reads move `read_idx` only once a frame completes, so they ask -byte 0 anyway; only chunk readers gain: a relay forwarding a frame, and the -TCP pump of [moq-dev/moq#8741](https://github.com/moq-dev/moq/pull/8741), -whose own measurements found 64 KiB frames fastest. The saving is at most one -frame's prefix, on one hop, per failover. The cost is a `Lead` type in the group code, -66 start-byte sites across `rs/moq-net` and `js/net`, and a field frozen in -lite-07. No quest names a consumer of frames over 32 MiB. - -Restore refetch-and-skip, and require a named consumer of -large frames before [byte holes](/quest/m3/unbounded-groups/byte-holes.md) -starts. - -Decided 2026-11-14 (maintainer, pick on [moq-dev/moq#8764](https://github.com/moq-dev/moq/pull/8764)): ✅ (a) back Start Byte out of lite-07 and restore refetch-and-skip (rejected: (b) keep it). - -Public API: (a) removes the start-byte surface #8699 added. Wire: lite-07-wip -FETCH loses Start Byte. - diff --git a/quest/m2/lite07-finalize.md b/quest/m2/lite07-finalize.md index 6deca5174ff..dc52f3ea25d 100644 --- a/quest/m2/lite07-finalize.md +++ b/quest/m2/lite07-finalize.md @@ -160,7 +160,6 @@ would need a breaking release had it landed right after the cut: - [Lite-07 by start](/quest/m2/time-addressing/lite07.md) - lite-07 carries group starts, previous-start links, GROUP_END, and time bounds instead of sequence numbers - [@moq/net by start](/quest/m2/time-addressing/js.md) - JS speaks the same lite-07 wire - [Warm routes on the wire](/quest/m2/warm-routes-wire.md) - removes WARM_* and SUBSCRIBE's `Warm` byte from lite-07 -- [FETCH Start Byte](/quest/m2/fetch-start-byte.md) - removes FETCH's byte offset into a half-read frame - [Subscriber Min Age](/quest/m2/subscriber-min-age.md) - removes SUBSCRIBE's minimum age, which nothing reads ## Related diff --git a/quest/m3/unbounded-groups/README.md b/quest/m3/unbounded-groups/README.md index 624f72ccda7..405c4347651 100644 --- a/quest/m3/unbounded-groups/README.md +++ b/quest/m3/unbounded-groups/README.md @@ -1,29 +1,37 @@ -# Unbounded groups and frames +# Unbounded groups ## Goal -Groups and frames have no fixed size cap. `MAX_GROUP_FRAMES` is already gone +Groups have no fixed size cap. `MAX_GROUP_FRAMES` is already gone ([moq-dev/moq#6993](https://github.com/moq-dev/moq/pull/6993)), and -`MAX_CACHE_BYTES` (32 MB) stops capping groups and frames and instead bounds -how much of a group's live tail is held. A group sheds whole frames from its -front once its tail passes 32 MB, or sooner when the shared cache pool is over -budget, so one long group never grows without bound even on a relay with no -cache capacity set. A reader or FETCH that reaches a shed front is served by a +`MAX_CACHE_BYTES` (32 MB) stops capping groups and instead bounds how much of +a group's live tail is held. A group sheds whole frames from its front once +its tail passes 32 MB, or sooner when the shared cache pool is over budget, +so one long group never grows without bound even on a relay with no cache +capacity set. A reader or FETCH that reaches a shed front is served by a flight, a separate paced copy filled from upstream or the publisher's own refill handler; failing that, it asks for a new group (refresh), and otherwise it gets `Evicted`. Readers never fail just because a group got big. The motivating workloads are long-lived single groups (data/log tracks, audio, -window timelines), video with very long GOPs, and file transfers where a frame -is a whole file. +window timelines) and video with very long GOPs. The hot write and read path for ordinary groups does not regress. Non-goals: pinning memory for slow readers, byte-precise refill over -moq-transport, and starting a reader mid-group at whatever the cache still -holds (a tail join). +moq-transport, starting a reader mid-group at whatever the cache still +holds (a tail join), and frames over 32 MiB in Rust or mid-frame resume. ## Plan +Decided 2026-11-15 (maintainer, on +[moq-dev/moq#8837](https://github.com/moq-dev/moq/pull/8837)): ✅ delete Byte +holes (rejected: keep it parked). No consumer sends frames over 32 MiB, so a +Rust frame stays capped at `MAX_CACHE_BYTES` and mid-frame resume is out until +one does. JS byte holes, which only mirrored it for `@moq/net`, went with it. A frame cut off partway on a route failure is +refetched whole and the reader skips what it read (`frame::Consumer`'s +`Recover`). The decisions below on byte positions, segment shedding, and the +byte offset on the lite wip are history until then. + Decided 2026-11-05 (maintainer, /quest-plan), on the open questions of [moq-dev/moq#7944](https://github.com/moq-dev/moq/pull/7944), which landed flights: @@ -152,8 +160,7 @@ Decided 2026-10-16 (maintainer interview): - The byte offset goes on the current lite wip version (lite-07-wip today); the lite-07 cut does not wait on it. Decided 2026-10-27 (maintainer): wire quests target whichever wip is current when they land, so - [Byte holes](/quest/m3/unbounded-groups/byte-holes.md) waits only on Front - eviction and Flights. If lite-07 is cut first, lite-07 peers start flights + Byte holes waited only on Front eviction and Flights. If lite-07 is cut first, lite-07 peers start flights only at frame boundaries, over lite-07's transport frame offsets, which allow a fill to start without the shed prefix (decided 2026-10-25, maintainer: the application API stays whole-group). diff --git a/quest/m3/unbounded-groups/byte-holes.md b/quest/m3/unbounded-groups/byte-holes.md deleted file mode 100644 index 9955c243b28..00000000000 --- a/quest/m3/unbounded-groups/byte-holes.md +++ /dev/null @@ -1,95 +0,0 @@ -# [M] Byte holes - -## Goal - -A frame of any size, such as a file delivered as one frame, passes through a -relay holding only a group's 32 MB tail. Sealed segments inside the frame -are shed like front frames, and a flight -([moq-dev/moq#7944](https://github.com/moq-dev/moq/pull/7944)) can start at a `(frame, byte)` position on the current lite wip version. -`MAX_CACHE_BYTES` stops capping a frame; it still bounds a group's tail. - -## Plan - -See the [epic](/quest/m3/unbounded-groups/README.md) for the decisions. -Decided 2026-10-27 (maintainer): the byte offset targets the current lite wip -version (lite-07-wip today); the lite-07 cut does not wait on it. This follows -[lite-07's freeze policy](/quest/m2/lite07-finalize.md): wire quests target -whichever wip is current when they land, and its Required list is not a -closed freeze set. If lite-07 is cut first, the offset goes on the next wip -and lite-07 peers start flights only at frame boundaries, like older lite -versions. Decided 2026-10-28 (maintainer): shed frames are served again only -by flights, so this waited on Flights, which landed in -[moq-dev/moq#7944](https://github.com/moq-dev/moq/pull/7944). - -Moved to m3 2026-11-12 (maintainer, /quest-audit), with its epic: the cut does not wait on it, so if lite-07 is cut first the offset goes on the next wip, as above. - -Decided 2026-11-05 (maintainer, /quest-audit): ✅ the byte offset rides -FETCH's frame start plus the group header, not a SUBSCRIBE range end. - -Decided 2026-11-13 (maintainer, /quest-complete): - -- ✅ The byte stays crate-private until a public API needs it (rejected: add - `Position::byte` now, about 90 literals across moq-net, moq-archive, and - moq-ffi). `Position` also names subscribe ranges and largest locations, - where a byte means nothing. -- ✅ [moq-dev/moq#8699](https://github.com/moq-dev/moq/pull/8699) merges its - slice alone, and this quest keeps the rest (rejected: grow that PR to the - whole quest). - -Landed in [moq-dev/moq#8699](https://github.com/moq-dev/moq/pull/8699), the -first slice: - -- Lite-07 FETCH carries a `Start Byte` after `Frame Start`, in Rust, JS, and the - lite draft. The response's first frame states its full size and carries only - its bytes from there. A FETCH response has no header, so this needed no - group-header field. -- A group copy can start partway into a frame: `group::Bounds::byte` keeps the - rest of that frame aside as the copy's `Lead`, outside the frame log. Every - whole-frame read finds that frame missing (`Lagged`). Only - `group::Consumer::at` with `poll_next_frame_at` reads it, from a byte at or - past the copy's start. -- Route failover mid-frame (`frame::Consumer`'s `Recover`) asks for only the - missing suffix by byte. Its integration regression is - `rs/moq-net/tests/integration/byte_holes.rs`, with a 5 MiB frame. A frame - larger than the 32 MB tail waits on the frame cap below. -- Rust readers already had a chunked payload read - (`frame::Consumer::read_chunk`), so nothing was added. -- The byte stays crate-private (`group::Fetch::byte_start`, the fill's start). - Public `Position` did not gain a field, since nothing public reads a byte - position yet. - -What remains: - -- Segments are `frame::SEGMENT` (1 MiB) long, so segment `i` always holds - bytes from `i * SEGMENT`, and a completed chain is `frame::Payload::Chain`. - Only a frame past one segment written in pieces chains. One written whole - (`write_frame`, or a single write or transport chunk carrying all of it) - stays one `Bytes` at any size, so evicting part of it needs it split into - segment slices, whose memory frees only once every slice drops, or copied - into segments. -- Every sealed segment is evictable under the same policy as front frames, - including one a reader is on. A reader keeps its current segment alive - through its own reference, as prefetched frames are today. That memory - is bounded by readers times one segment, not by the cache. A reader holding - a `Payload::Chain` holds every segment through its `Arc<[Bytes]>` today, so - the chain has to hand a reader one segment at a time. Only the writer's open - segment stays resident. A reader at a shed segment boards a flight that - starts at its `(frame, byte)`: `FillState::fly` and `group::Bounds` already - carry the byte, and the flight's copy starts with a `Lead`. -- A group stream that starts mid-frame (a relay holding only a group's tail, - once segments shed) carries the byte offset in the lite wip GROUP header - beside `Frame Start`, and still states the frame's full size. Older lite - versions and moq-transport start only at frame or object boundaries. A - reader inside a shed object refreshes or is `Evicted` there. -- `MAX_CACHE_BYTES` stops capping a frame (`group::Producer::open_frame` and - `open_lead` refuse a larger one today). Then extend the failover regression - to a frame larger than the 32 MB tail. -- Drop the 32 MiB interop cap in `drafts/draft-lcurley-moq-e2ee.md` if it no - longer follows from a model limit, and run `just drafts check`. -- Test a frame several times the 32 MB tail through a relay chain: a late - joiner reads it whole through a flight, and memory stays near 32 MB per - copy. - -Public API: `Position` gains a byte field only once a public reader needs a -byte position, and `MAX_CACHE_BYTES` stops capping a frame. Wire: a byte -offset on the current lite wip's group header. diff --git a/quest/m3/unbounded-groups/compressed-stream.md b/quest/m3/unbounded-groups/compressed-stream.md index 952de343169..4d03f105765 100644 --- a/quest/m3/unbounded-groups/compressed-stream.md +++ b/quest/m3/unbounded-groups/compressed-stream.md @@ -1,9 +1,11 @@ -# [M] Compressed frames have no size cap and inflate as a bounded stream +# [M] Compressed frames are capped only like plain ones and inflate as a bounded stream ## Goal -A compressed frame of any size publishes and is received in Rust and -`@moq/net`, like a plain one. The 32 MiB guard on a compressed frame goes. +A compressed frame publishes and is received in Rust and `@moq/net` at any +size a plain one may have: any size in `@moq/net`, and up to a plain frame's +32 MiB cap (`MAX_CACHE_BYTES`) in Rust. The separate 32 MiB guard on a +compressed slice goes. The wire still declares each compressed slice's size (and its `Inflated Size`) up front, so a publisher still compresses a frame whole before it sends it. A receiver never inflates a frame whole in memory: it inflates as @@ -39,20 +41,21 @@ Decided 2026-10-31 (user, /quest-plan of the follow-ups from the 2026-10-31 `write_frames` (`group.rs:1719`, `:1798`) check only the plain payload against 32 MB, so an incompressible frame near the cap encodes to a slice every receiver refuses. With no compressed cap, there is nothing to - mismatch; [Byte holes](/quest/m3/unbounded-groups/byte-holes.md) removes - the plain cap. + mismatch: the inflated size stays checked against the plain cap. +- Rust frames stay capped at 32 MiB. Decided 2026-11-15 (maintainer, on + [moq-dev/moq#8837](https://github.com/moq-dev/moq/pull/8837)): Byte holes, + which would have lifted the plain cap, was deleted, since no consumer sends + frames over 32 MiB. So this quest no longer waits on it, and its Rust half + drops only the compressed-slice guard and inflates in segments. - The lite draft's FRAME text ("a receiver MUST check it against its limits before inflating") stays; add that a receiver may inflate incrementally and must stop at the declared size. Update `doc/concept` and the compression docs that state the 32 MiB cap. -- Tests, both languages: a compressed frame several times 32 MB round-trips - over lite-07 and a relay chain with memory held near the tail; a slice +- Tests: in JS, a compressed frame several times 32 MB round-trips over + lite-07 with memory held near the tail; in Rust, an incompressible frame at + the plain cap round-trips over lite-07 and a relay chain. Both: a slice whose payload inflates past its declared size fails as malformed without allocating the excess. Public API: removes the compressed-frame `FrameTooLarge` refusal (JS, Rust, JSON preflight). Wire: none. - -## Required - -- [Byte holes](/quest/m3/unbounded-groups/byte-holes.md) - Rust frames past 32 MB at all diff --git a/quest/m3/unbounded-groups/js-byte-holes.md b/quest/m3/unbounded-groups/js-byte-holes.md deleted file mode 100644 index 377e2dd079d..00000000000 --- a/quest/m3/unbounded-groups/js-byte-holes.md +++ /dev/null @@ -1,53 +0,0 @@ -# [S] JS byte holes - -## Goal - -`@moq/net` speaks the lite wip byte offset on FETCH's frame start and group -headers as Rust does, so a JS reader cut off inside a large frame continues it -from the byte it reached instead of failing. - -## Plan - -Moved to m3 2026-11-12 (maintainer, /quest-audit), with its epic: it mirrors Byte holes, which the cut does not wait on. - -Decided 2026-10-27 (maintainer): split out of the JS unbounded groups -quest. This half mirrors -[Byte holes](/quest/m3/unbounded-groups/byte-holes.md). - -Decided 2026-10-31 (maintainer, on -[moq-dev/moq#7411](https://github.com/moq-dev/moq/pull/7411)): chunked frame -storage and reads moved into that PR, which removed the JS frame cap. JS now -has `Group.Producer.createFrame` and `Group.Consumer.nextFrame` with -`readChunk`, stores a large frame as 1 MiB segments that shed under the -32 MiB tail, and streams payloads past one segment on lite and -moq-transport. What is left here is the wire: - -- Mirror the byte offset on the same lite wip version as Rust, on FETCH's - frame start and the group stream header, and refill a hole inside a frame the way - Rust does. -- A consumer that took a frame to stream and loses its copy partway - through fails today, since resuming at the next frame would drop the rest - of that frame (`#torn` in `js/net/src/group.ts`). Continue it from the - serving route's copy at its byte offset, as Rust's `frame::Consumer` - `Recover` does once Byte holes lands. -- Test a frame several times the cache window through a Rust relay, read - as chunks, plus Rust/JS interop of a mid-frame refill. Run - `just test interop --all`. -- If [the Rust model in the browser](/quest/m5/rs2ts-js.md) is adopted first, - this shrinks to exposing its byte-offset recovery. - -Decided 2026-11-05 (maintainer, /quest-audit): ✅ the byte offset rides -FETCH's frame start plus the group header, not a SUBSCRIBE range end. -SUBSCRIBE ranges are whole groups since 2026-11-03 -(Lite-07 FETCH is single-group only, -[moq-dev/moq#8616](https://github.com/moq-dev/moq/pull/8616) and -[moq-dev/moq#7675](https://github.com/moq-dev/moq/pull/7675)), and flights -ride lite FETCH since [moq-dev/moq#7944](https://github.com/moq-dev/moq/pull/7944). -This waits for that quest. - -Public API: none beyond the recovery. Wire: the lite wip byte offset, as -Byte holes defines it. - -## Required - -- [Byte holes](/quest/m3/unbounded-groups/byte-holes.md) - the Rust contract and the lite wire this mirrors diff --git a/rs/moq-net/src/lite/fetch.rs b/rs/moq-net/src/lite/fetch.rs index f132b702cd6..0ef400e8d5d 100644 --- a/rs/moq-net/src/lite/fetch.rs +++ b/rs/moq-net/src/lite/fetch.rs @@ -29,9 +29,6 @@ pub struct Fetch<'a> { pub group: u64, /// Index of the first frame to return; 0 is the start of the group. Lite06+ only. pub start_frame: u64, - /// Offset of the first byte to return within frame `start_frame`; 0 is the whole - /// frame. The response still states that frame's full size. Lite07+ only. - pub start_byte: u64, /// Index of the last frame to return (inclusive), or `None` for through the end of /// the group. Lite06+ only. pub end_frame: Option, @@ -50,7 +47,6 @@ impl Fetch<'_> { max_delay: self.max_delay, group: self.group, start_frame: self.start_frame, - start_byte: self.start_byte, end_frame: self.end_frame, } } @@ -77,17 +73,9 @@ impl<'a> Message<'a> for Fetch<'a> { }; let group = r.varint()?; - let start_frame = match version.has_frame_bounds() { - true => r.varint()?, - false => 0, - }; - let start_byte = match version.has_byte_start() { - true => r.varint()?, - false => 0, - }; - let end_frame = match version.has_frame_bounds() { - true => r.varint_opt()?, - false => None, + let (start_frame, end_frame) = match version.has_frame_bounds() { + true => (r.varint()?, r.varint_opt()?), + false => (0, None), }; // A range that ends before it starts can never be served. if end_frame.is_some_and(|end| end < start_frame) { @@ -104,7 +92,6 @@ impl<'a> Message<'a> for Fetch<'a> { max_delay, group, start_frame, - start_byte, end_frame, }) } @@ -134,22 +121,12 @@ impl<'a> Message<'a> for Fetch<'a> { } w.varint(self.group)?; - if !version.has_frame_bounds() && (self.start_frame != 0 || self.end_frame.is_some()) { - // The peer would serve the whole group, including frames the caller excluded. - return Err(EncodeError::Version); - } - if !version.has_byte_start() && self.start_byte != 0 { - // The peer would resend the frame from its start, misaligning the reader. - return Err(EncodeError::Version); - } if version.has_frame_bounds() { w.varint(self.start_frame)?; - } - if version.has_byte_start() { - w.varint(self.start_byte)?; - } - if version.has_frame_bounds() { w.varint_opt(self.end_frame)?; + } else if self.start_frame != 0 || self.end_frame.is_some() { + // The peer would serve the whole group, including frames the caller excluded. + return Err(EncodeError::Version); } Ok(()) @@ -171,30 +148,10 @@ mod test { max_delay: None, group: 7, start_frame: 0, - start_byte: 0, end_frame: None, } } - /// Lite-07 asks for the rest of a frame; an older peer cannot, so encoding refuses. - #[test] - fn fetch_start_byte_roundtrips_only_on_lite07() { - let mut msg = fetch_sample(); - msg.start_frame = 2; - msg.start_byte = 1 << 20; - let got = fetch_roundtrip(Version::Lite07, &msg); - assert_eq!((got.start_frame, got.start_byte), (2, 1 << 20)); - assert!( - msg.encode_msg( - &mut Encoder::new(&mut Vec::new(), Version::Lite06.into()), - Version::Lite06 - ) - .is_err() - ); - msg.start_byte = 0; - assert_eq!(fetch_roundtrip(Version::Lite06, &msg).start_byte, 0); - } - #[test] fn fetch_max_delay_roundtrips_on_lite07() { let mut msg = fetch_sample(); diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index 0dc20e53106..b6b8c30acac 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -3130,9 +3130,6 @@ enum FetchServe { batch_pos: usize, /// The `ietf` extension's object records, when negotiated. records: Option, - /// The byte the first frame is served from, until it is: the response states that - /// frame's full size and carries only its bytes from here. - lead: Option, }, } @@ -3183,7 +3180,6 @@ impl Request for FetchServe { priority: msg.priority, max_delay: msg.max_delay, frame_start: msg.start_frame, - byte_start: msg.start_byte, }, end: msg.end_frame.and_then(|end| end.checked_add(1)), }, @@ -3207,24 +3203,15 @@ impl Request for FetchServe { Self::Fetch { msg, fetching } => { // Before the group: a fetched group polled while this waited would be lost. let ietf = ready!(shared.peer_setup.poll_ietf(waiter)); + let group = ready!(kio::Task::poll(fetching, waiter))?.with_range(msg.start_frame..); + // The response carries no header, so a short run is indistinguishable // from one that started elsewhere: only serve a range we can cover // exactly. `fetch_group` already positions the consumer, so this is a // belt-and-braces check on a promise the wire can't restate. - let Some(group) = ready!(kio::Task::poll(fetching, waiter))?.at(msg.start_frame, msg.start_byte) - else { + if group.index() != msg.start_frame { return Poll::Ready(Err(Error::Lagged)); - }; - // A compressed frame inflates only from its first byte, and an object record - // names a whole object, so neither is served from a later byte; this side - // never asks for it. - let lead = match msg.start_byte { - 0 => None, - _ if group.is_compressed() || (ietf && group.ietf().is_some()) => { - return Poll::Ready(Err(Error::ProtocolViolation)); - } - byte => Some(usize::try_from(byte).map_err(|_| Error::WrongSize)?), - }; + } // The end is a serving cap only: the cached group runs to the end of // the group so it stays usable for anyone else (see // `group::Fetch::frame_start`). Only the end, so the start stays where @@ -3251,7 +3238,6 @@ impl Request for FetchServe { batch: Box::default(), batch_pos: 0, records, - lead, }; } Self::Serve { @@ -3263,35 +3249,11 @@ impl Request for FetchServe { batch, batch_pos, records, - lead, } => loop { ready!(writer.poll_flush(waiter))?; if let Some(records) = records { ready!(records.poll_state(writer, group, waiter))?; } - if let Some(byte) = *lead { - let Some(next) = ready!(group.poll_next_frame_at(byte, waiter))? else { - // The group ends before the frame the request starts in. - return Poll::Ready(Err(Error::WrongSize)); - }; - *lead = None; - if let Some(records) = records { - records.frame(writer, group.index() - 1, next.fields.as_deref())?; - } - // The frame's full size: the subscriber knows it asked for the rest. - buffer_frame_info( - writer, - shared.version, - next.timestamp, - next.inflated, - next.size, - *stamp, - prev_ts, - next.size - byte as u64, - )?; - *frame = Some(next); - continue; - } if let Some(pending) = chunk { ready!(writer.poll_write(waiter, pending))?; if !bytes::Buf::has_remaining(pending) { @@ -3316,7 +3278,6 @@ impl Request for FetchServe { batched.frame.payload.len() as u64, *stamp, prev_ts, - batched.frame.payload.len() as u64, )?; let payload = std::mem::take(&mut batched.frame.payload); if !payload.is_empty() { @@ -3352,7 +3313,6 @@ impl Request for FetchServe { next.size, *stamp, prev_ts, - next.size, )?; *frame = Some(next); return Poll::Ready(Ok(ControlFlow::Continue(()))); @@ -4630,8 +4590,6 @@ fn buffer_frame_info( size: u64, stamp: Option, prev_ts: &mut u64, - // Payload bytes that follow: fewer than `size` only for a frame served from a byte. - sent: u64, ) -> Result<(), Error> { // Lite-07 leads with the size plus one, leaving 0 for GROUP_END. let length_first = version.has_length_first(); @@ -4651,7 +4609,7 @@ fn buffer_frame_info( if !length_first { writer.buffer_varint(size)?; } - writer.frame(sent); + writer.frame(size); Ok(()) } @@ -6762,7 +6720,6 @@ impl GroupServe { batched.frame.payload.len() as u64, self.ctx.stamp, &mut self.prev_ts, - batched.frame.payload.len() as u64, ) }); if let Err(err) = buffered { @@ -6817,7 +6774,6 @@ impl GroupServe { next.size, self.ctx.stamp, &mut self.prev_ts, - next.size, ) }); if let Err(err) = buffered { @@ -11233,7 +11189,6 @@ mod tests { max_delay: None, group: 0, start_frame: 0, - start_byte: 0, end_frame: None, }; leave_request::(version, &fetch, wait, close).await; @@ -12311,7 +12266,6 @@ mod tests { max_delay: None, group: 0, start_frame: 2, - start_byte: 0, end_frame: Some(3), }, "video", @@ -12383,7 +12337,6 @@ mod tests { max_delay: None, group: 0, start_frame: 0, - start_byte: 0, end_frame: None, } .encode(&mut crate::coding::Encoder::new(&mut script, VERSION.into()), VERSION) @@ -12461,7 +12414,6 @@ mod tests { max_delay: Some(Duration::from_millis(500)), group: 0, start_frame: 0, - start_byte: 0, end_frame: None, } .encode(&mut crate::coding::Encoder::new(&mut script, VERSION.into()), VERSION) @@ -12491,90 +12443,6 @@ mod tests { assert_eq!(session.log.resets(), vec![crate::StreamError::Old.to_code()]); } - /// A FETCH from partway into a frame of a moq-transport track, whose object records name - /// whole objects, is refused once the `ietf` extension carries those records; a moq-lite - /// track on the same session is served from the byte. - #[kio::test] - async fn a_start_byte_is_refused_on_a_track_with_object_records() { - const VERSION: Version = Version::Lite07; - for transport in [false, true] { - let origin = crate::origin::Config::new(std::num::NonZeroU64::new(1).unwrap()).produce(); - let broadcast = origin.route("room", crate::origin::RouteOptions::hidden()).unwrap(); - let mut info = track::Info::timed(); - if transport { - info.properties = Some(Arc::new(crate::model::object::TrackProperties { - version: crate::ietf::Version::Draft18, - values: Vec::new(), - })); - } - let track = broadcast.broadcast().create_track("video", info).unwrap(); - broadcast.announce().unwrap(); - let mut group = track.append_group(0).unwrap(); - group.write_frame(crate::Timestamp::ZERO, b"abcd".to_vec()).unwrap(); - group.close().unwrap(); - - let peer_setup = crate::lite::PeerSetup::new(false, crate::transport::Address::Setup).offer_ietf(true); - peer_setup - .set(crate::lite::Setup { - ietf: true, - ..Default::default() - }) - .unwrap(); - let (_, goaway) = crate::goaway::Handle::new(true); - let publisher = Publisher::new(PublisherConfig { - runtime: crate::time::sim(), - session: crate::driver::Transport::new(ScriptedSession::new(Vec::new())), - origin: origin.consume(), - version: VERSION, - peer_setup, - goaway, - peer_hop: None, - auth: crate::auth::Link::new(false), - peer_grant: Default::default(), - client: false, - subscriptions: Default::default(), - estimate: kio::Producer::default().weak(), - }); - let mut script = Vec::new(); - lite::Fetch { - instance: None, - node: 0, - depth: 0, - broadcast: crate::Path::from_static("room"), - track: "video".into(), - priority: 0, - max_delay: None, - group: 0, - start_frame: 0, - start_byte: 2, - end_frame: None, - } - .encode(&mut crate::coding::Encoder::new(&mut script, VERSION.into()), VERSION) - .unwrap(); - let session = ScriptedSession::new(script); - let (send, recv) = kio::wait(|waiter| { - ::poll_open_bi(&session, waiter, Default::default()) - }) - .await - .unwrap(); - let stream = Stream:: { - writer: Writer::new(crate::transport::boxed::SendStream::new(send), VERSION), - reader: crate::coding::Reader::new(crate::transport::boxed::RecvStream::new(recv), VERSION), - }; - let mut serve = RequestServe::::new(publisher.shared.clone(), stream); - assert!(drive(&mut serve).await, "the fetch ended"); - let refused = crate::StreamError::Session(SessionError::ProtocolViolation).to_code(); - match transport { - true => assert_eq!(session.log.resets(), vec![refused]), - false => { - assert!(session.log.resets().is_empty(), "a moq-lite track serves from the byte"); - let written = session.log.writes.lock().unwrap(); - assert!(written.ends_with(b"cd") && !written.ends_with(b"abcd")); - } - } - } - } - #[kio::test] async fn report_consumes_probe_targets_until_fin() { for version in [ diff --git a/rs/moq-net/src/lite/subscriber.rs b/rs/moq-net/src/lite/subscriber.rs index 6234caac87a..23962c94c32 100644 --- a/rs/moq-net/src/lite/subscriber.rs +++ b/rs/moq-net/src/lite/subscriber.rs @@ -2050,17 +2050,10 @@ impl FrameIngest { /// Where the frame `header` opens goes: a new frame of the group, or on a continuation, /// one the group holds already, skipped, or the one a YIELDED reset cut short, completed. - fn dispatch(&mut self, group: &mut crate::recv::Group, header: frame::Header) -> Result { + fn dispatch(&mut self, group: &crate::recv::Group, header: frame::Header) -> Result { let index = self.index; // The peer's Frame Start can number a frame past any count. self.index = index.checked_add(1).ok_or(Error::ProtocolViolation)?; - // A response from a byte: the header states the frame's full size, and only the rest - // of it follows. - if group.lead_at(index).is_some() { - return Ok(IngestPhase::Payload { - frame: group.create_lead(header)?, - }); - } let held = group.frame_count() as u64; if index >= held { return Ok(IngestPhase::Admit { header }); @@ -2111,12 +2104,9 @@ impl FrameIngest { let lite::ietf::Decoded { properties, gap } = lite::ietf::decode_properties(&block, self.framing, true)?; group.mark_gap(id, gap)?; - // The rest of a frame the copy starts partway into is numbered below its count. // A plain group's frames are numbered by index, so a continuation re-sending - // frames its group holds finds them below its count too. - let next = id == group.frame_count() as u64 - || group.lead_at(id).is_some() - || (!records.relayed && id == self.index); + // frames its group holds finds them below its count. + let next = id == group.frame_count() as u64 || (!records.relayed && id == self.index); let plain = next && properties.is_empty(); if !plain && !records.relayed { return Err(Error::ProtocolViolation); @@ -14327,7 +14317,6 @@ enum FetchRunState { request: Option, stream: Stream, frame_start: u64, - byte_start: u64, frame_end: Option, }, /// Flushed; waiting for the publisher to answer before accepting. @@ -14335,7 +14324,6 @@ enum FetchRunState { request: Option, stream: Stream, frame_start: u64, - byte_start: u64, frame_end: Option, }, Ingest { @@ -14505,15 +14493,6 @@ impl kio::Task for FetchServeRun { false => 0, }; - // Only the rest of a frame a reader got partway through, which a compressed - // frame cannot start at: it inflates only from its first byte. Nor can a - // moq-transport track's, whose object records name whole objects. - let whole_objects = matches!(self.info.peek(), Some(Ok(info)) if info.ietf().is_some()); - let byte_start = match self.serve.subscriber.version.has_byte_start() { - true if plain && !whole_objects && frame_start == request.frame_start() => request.byte_start(), - _ => 0, - }; - let frame_end = if self.serve.subscriber.version.has_frame_bounds() && plain { request.frame_end() } else { @@ -14533,7 +14512,6 @@ impl kio::Task for FetchServeRun { .filter(|_| self.serve.subscriber.version.has_fetch_max_delay()), group: self.group, start_frame: frame_start, - start_byte: byte_start, // A bounded plain copy keeps this provenance in the cache; older wires // and compressed groups widen to a complete representation. end_frame: frame_end.and_then(|end| end.checked_sub(1)), @@ -14553,7 +14531,6 @@ impl kio::Task for FetchServeRun { request: Some(request), stream, frame_start, - byte_start, frame_end, }; } @@ -14572,7 +14549,6 @@ impl kio::Task for FetchServeRun { request, mut stream, frame_start, - byte_start, frame_end, } = std::mem::replace(&mut self.state, FetchRunState::Done) else { @@ -14585,7 +14561,6 @@ impl kio::Task for FetchServeRun { request, stream, frame_start, - byte_start, frame_end, }; } @@ -14622,7 +14597,6 @@ impl kio::Task for FetchServeRun { request, mut stream, frame_start, - byte_start, frame_end, } = std::mem::replace(&mut self.state, FetchRunState::Done) else { @@ -14654,7 +14628,6 @@ impl kio::Task for FetchServeRun { group_info, group::Bounds { start: frame_start, - byte: byte_start, end: frame_end, }, ) { diff --git a/rs/moq-net/src/lite/version.rs b/rs/moq-net/src/lite/version.rs index 249be4f19f2..21ff2916d51 100644 --- a/rs/moq-net/src/lite/version.rs +++ b/rs/moq-net/src/lite/version.rs @@ -210,15 +210,6 @@ impl Version { ) } - /// Whether FETCH carries a `Start Byte` within its first frame, so a reader cut off - /// partway through a frame asks for only the rest of it. Added in lite-07. - pub(crate) fn has_byte_start(self) -> bool { - !matches!( - self, - Self::Lite01 | Self::Lite02 | Self::Lite03 | Self::Lite04 | Self::Lite05 | Self::Lite06 - ) - } - /// Whether this version's SUBSCRIBE, SUBSCRIBE_UPDATE, SUBSCRIBE_OK, and TRACK_INFO /// carry the retired `Ordered` byte. /// diff --git a/rs/moq-net/src/model/frame.rs b/rs/moq-net/src/model/frame.rs index fb23bc2a4d2..89ef4065f77 100644 --- a/rs/moq-net/src/model/frame.rs +++ b/rs/moq-net/src/model/frame.rs @@ -1000,6 +1000,7 @@ impl FrameBuf { } /// The canonical allocation's charge, counted once by its cache owner. + #[cfg(test)] pub(super) fn content_size(&self) -> u64 { self.content.bill.get().map_or(0, cache::Extra::size) } @@ -1297,9 +1298,6 @@ pub struct Producer { stats: stats::Meter, // The frame's share of the origin's [`Budget`], if it got one, held until it ends. admission: Option, - // Writes the rest of the frame its copy starts partway into (see - // [`group::Producer::create_lead`]), which stays out of the frame log. - lead: bool, } impl std::ops::Deref for Producer { @@ -1320,17 +1318,9 @@ impl Producer { cancel_on_drop: false, stats: stats::Meter::default(), admission, - lead: false, } } - /// Write the rest of the frame a copy starts partway into. - #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] - pub(super) fn lead(mut self) -> Self { - self.lead = true; - self - } - /// Attach the parent group's ingress meter, so written chunks bump `bytes`. pub(super) fn with_meter(mut self, meter: stats::Meter) -> Self { self.stats = meter; @@ -1414,14 +1404,8 @@ impl Producer { if self.buf.written(Ordering::Acquire) != self.buf.size() { return Err(Error::WrongSize); } - let mut group = self.group.take().expect("frame owns its group"); - if self.lead { - self.done = true; - // Its readers already hold its buffer, so only the wake is left. - group.frame_notify(); - return Ok(group); - } let payload = self.buf.freeze(); + let mut group = self.group.take().expect("frame owns its group"); let committed = group.frame_commit(Cached { timestamp: self.info.timestamp, payload, @@ -1528,10 +1512,7 @@ pub struct Consumer { #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] pub(crate) inflated: Option, source: Source, - // The frame offset `source` starts at: non-zero only for the rest of a frame a copy - // started partway into (see [`group::Consumer::at`]). - base: usize, - // Byte offset consumed so far, from the frame's start. + // Byte offset consumed so far. read_idx: usize, // Egress payload meter, so chunks bump `bytes` exactly once as they're read out. // Empty (no-op) for an untagged group. @@ -1561,7 +1542,6 @@ impl Consumer { fields: header.fields, inflated: header.inflated, source, - base: 0, read_idx: 0, stats: stats::Meter::default(), expiry: None, @@ -1570,15 +1550,6 @@ impl Consumer { } } - /// Read from frame offset `from`, with `source` holding the frame from `base`, which - /// is at most `from`. - pub(super) fn starting_at(mut self, base: usize, from: usize) -> Self { - debug_assert!(base <= from); - self.base = base; - self.read_idx = from; - self - } - /// Carry this frame across a front's route changes; see [`super::resume`]. pub(super) fn with_recover(mut self, recover: super::resume::Recover, index: u64) -> Self { self.recover = Some(Box::new((recover, index))); @@ -1617,9 +1588,7 @@ impl Consumer { if self.state.read().sparse() { return Poll::Ready(Err(Error::Unsupported)); } - // Only the rest of the frame is asked for: the bytes already read are not sent again. - let byte = self.read_idx as u64; - let mut replacement = match recover.poll(*index, byte, failed.as_ref(), waiter) { + let mut replacement = match recover.poll(*index, failed.as_ref(), waiter) { Poll::Ready(Ok(group)) => group, Poll::Ready(Err(err)) => return Poll::Ready(Err(err)), Poll::Pending => return Poll::Pending, @@ -1634,7 +1603,7 @@ impl Consumer { if self.inflated.is_some() { replacement.group = replacement.group.compressed(); } - let frame = match replacement.group.poll_next_frame_at(self.read_idx, waiter) { + let frame = match replacement.group.poll_next_frame(waiter) { Poll::Ready(Ok(Some(frame))) => frame, Poll::Ready(Ok(None)) => return Poll::Ready(Err(Error::WrongSize)), Poll::Ready(Err(err)) => return Poll::Ready(Err(err)), @@ -1654,14 +1623,9 @@ impl Consumer { if frame.info.size != self.info.size || frame.inflated != self.inflated { return Poll::Ready(Err(Error::ProtocolViolation)); } - // Positioned at this read's byte, so the replacement holds every byte from it. - if frame.base > self.read_idx { - return Poll::Ready(Err(Error::Lagged)); - } recover.adopt(&replacement); self.state = frame.state; self.source = frame.source; - self.base = frame.base; } } @@ -1679,7 +1643,7 @@ impl Consumer { fn size(&self) -> usize { match &self.source { - Source::Complete(payload) => self.base + payload.len(), + Source::Complete(payload) => payload.len(), Source::Partial(_) => self.info.size as usize, } } @@ -1727,17 +1691,15 @@ impl Consumer { if self.expired { return Poll::Ready(Err(Error::Old)); } - // The source's own offsets: it holds the frame from `base`. - let size = self.info.size as usize - self.base; + let size = self.info.size as usize; loop { - let at = self.read_idx - self.base; // Borrowed rather than cloned: every reader of the frame shares its count. let buf = match &self.source { Source::Complete(payload) => { - if at >= payload.len() { + if self.read_idx >= payload.len() { return Poll::Ready(Ok(None)); } - let out = payload.chunk_at(at); + let out = payload.chunk_at(self.read_idx); self.read_idx += out.len(); self.stats.bytes(out.len() as u64); return Poll::Ready(Ok(Some(out))); @@ -1745,8 +1707,8 @@ impl Consumer { Source::Partial(buf) => buf, }; let written = buf.written(Ordering::Acquire); - if written > at { - let out = buf.slice(at, written); + if written > self.read_idx { + let out = buf.slice(self.read_idx, written); self.read_idx += out.len(); self.stats.bytes(out.len() as u64); return Poll::Ready(Ok(Some(out))); @@ -1762,7 +1724,7 @@ impl Consumer { let Source::Partial(buf) = &self.source else { unreachable!("only a partial frame waits for its bytes"); }; - let read_idx = at; + let read_idx = self.read_idx; // Park on the group's channel; the producer notifies it on each write and // on abort. Re-check the atomic on wake. ready!(poll_state(&self.state, waiter, |state| { @@ -1792,18 +1754,18 @@ impl Consumer { if self.expired { return Poll::Ready(Err(Error::Old)); } - let read_idx = self.read_idx - self.base; let buf = match &self.source { Source::Complete(payload) => { - let out = payload.contiguous(read_idx); - self.read_idx = self.base + payload.len(); + let out = payload.contiguous(self.read_idx); + self.read_idx = payload.len(); self.stats.bytes(out.len() as u64); return Poll::Ready(Ok(out)); } Source::Partial(buf) => buf.clone(), }; - let size = self.info.size as usize - self.base; + let size = self.info.size as usize; + let read_idx = self.read_idx; // Waiting on the rest of the payload is a stall; see `poll_read_chunk`. if buf.written(Ordering::Acquire) < size && self.poll_expired(waiter) { return Poll::Ready(Err(Error::Old)); @@ -1819,7 +1781,7 @@ impl Consumer { } })?); let out = buf.freeze().contiguous(read_idx); - self.read_idx = self.base + size; + self.read_idx = size; self.stats.bytes(out.len() as u64); Poll::Ready(Ok(out)) } diff --git a/rs/moq-net/src/model/group.rs b/rs/moq-net/src/model/group.rs index fecf7cb8e4d..e36ae7a2362 100644 --- a/rs/moq-net/src/model/group.rs +++ b/rs/moq-net/src/model/group.rs @@ -208,26 +208,9 @@ impl Entry { #[derive(Clone, Copy, Debug, Default)] pub(crate) struct Bounds { pub start: u64, - /// The first byte held of frame `start`: non-zero when the copy starts partway into - /// it, which only a read continuing that frame from a later byte can use (see [`Lead`]). - pub byte: u64, pub end: Option, } -/// The frame a copy holds only the rest of, from byte `byte` on: a transport started the copy -/// partway into frame `index`, the one before [`GroupState::offset`]. -/// -/// Kept beside the frame log rather than in it, so every whole-frame read of the copy finds -/// frame `index` missing ([`Error::Lagged`]), as it would on a copy starting at the next -/// frame. Only a read continuing the frame from `byte` or later reaches it, through -/// [`Consumer::at`]. -pub(super) struct Lead { - index: usize, - byte: usize, - // Opened by the first frame the copy's ingest writes, with the frame's full size. - open: Option<(frame::Info, FrameBuf)>, -} - /// Shared group state. Model-visible so [`frame`] handles can observe its outcome /// while streaming a partial frame. #[derive(Default)] @@ -248,10 +231,6 @@ pub(super) struct GroupState { // The single in-flight frame, if one is open. pub(super) partial: Option, - // The frame before `offset` this copy holds only a suffix of, if it started partway into - // it. Boxed: it is the rare case. - lead: Option>, - // Index of the first frame this handle holds: any the group deliberately started // past (see [`Producer::start_at`]). Reading below it is [`Error::Lagged`]; the // frames are not here. Frames shed from the front since sit between it and @@ -922,19 +901,10 @@ impl GroupState { payload + fields } - /// The bytes the live tail holds: every committed frame, their fields, the rest of a - /// frame the copy started partway into, and the in-flight frame at its declared size. + /// The bytes the live tail holds: every committed frame, their fields, and the + /// in-flight frame at its declared size. fn tail(&self) -> u64 { - self.cache + self.relay.as_ref().map_or(0, |relay| relay.bytes) + self.lead_bytes() + self.unwritten() - } - - /// The rest of the frame the copy started partway into, at its declared size like the - /// in-flight frame, since its later writes trim nothing. - fn lead_bytes(&self) -> u64 { - self.lead - .as_deref() - .and_then(|lead| lead.open.as_ref()) - .map_or(0, |(_, buf)| buf.size() as u64) + self.cache + self.relay.as_ref().map_or(0, |relay| relay.bytes) + self.unwritten() } /// The frame slots the tail holds beyond the log's first segment, so a group of empty @@ -1027,12 +997,6 @@ impl GroupState { if tail.saturating_add(slots) <= MAX_CACHE_BYTES { return true; } - // The lead is the oldest frame, so it goes first. Only a later frame trims, once the - // lead is written; its readers keep the bytes they hold. - if self.lead.as_deref().is_some_and(|lead| lead.open.is_some()) { - tail -= self.lead_bytes(); - self.lead = None; - } let mut end = self.held(); while tail.saturating_add(slots) > MAX_CACHE_BYTES && let Some(entry) = self.entry(end) @@ -1481,7 +1445,6 @@ impl GroupState { self.front = VecDeque::new(); self.evict_log(self.log.end()); self.partial = None; - self.lead = None; if let Some(content) = self.content.take() { content.detach(self.outcome.error().cloned().unwrap_or(Error::Dropped)); } @@ -1810,26 +1773,8 @@ impl Producer { } /// Apply transport bounds before this copy is published to the cache. - /// - /// A copy starting partway into frame `start` starts at the next frame, holding the - /// rest of `start` aside as its [`Lead`], which the first frame written opens. pub(crate) fn bound(&mut self, frames: Bounds) -> Result<()> { - match frames.byte { - 0 => self.start_at(frames.start)?, - byte => { - let next = frames - .start - .checked_add(1) - .ok_or(Error::BoundsExceeded(crate::coding::BoundsExceeded))?; - self.start_at(next)?; - let byte = usize::try_from(byte).map_err(|_| Error::BoundsExceeded(crate::coding::BoundsExceeded))?; - modify(&self.handle.state)?.lead = Some(Box::new(Lead { - index: frames.start as usize, - byte, - open: None, - })); - } - } + self.start_at(frames.start)?; if let Some(end) = frames.end { let end = usize::try_from(end).map_err(|_| Error::BoundsExceeded(crate::coding::BoundsExceeded))?; let mut state = modify(&self.handle.state)?; @@ -2089,65 +2034,6 @@ impl Producer { Ok(frame::Producer::new(self, buf, info, admission).with_meter(meter)) } - /// Open the rest of the frame this copy starts partway into (see [`Bounds::byte`]): - /// `frame` declares the frame's full size, and the producer takes only the bytes past - /// the copy's start. - /// - /// [`Error::ProtocolViolation`] unless the copy starts partway into a frame it has not - /// opened yet, or when the frame is no larger than that start: a transport answering - /// from a byte always has more of the frame to send. A compressed frame never starts - /// partway, since its bytes inflate only from its first. - #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] - pub(crate) fn create_lead(mut self, frame: frame::Header) -> Result { - let meter = self.chunk_meter(None); - let res = self.open_lead(frame); - match res { - Ok((info, buf, admission)) => { - // Ingress: one frame opened, its bytes counted per chunk, as `create_object` does. - self.stats.frames(1); - Ok(frame::Producer::new(self, buf, info, admission) - .lead() - .with_meter(meter)) - } - Err(err) => { - let _ = self.handle.abort(err.clone()); - Err(err) - } - } - } - - #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] - fn open_lead(&mut self, header: frame::Header) -> Result<(frame::Info, FrameBuf, Option)> { - let frame = header.info; - let timestamp = self.handle.track.rescale(frame.timestamp)?; - if frame.size > MAX_CACHE_BYTES { - return Err(Error::FrameTooLarge); - } - if header.inflated.is_some() || header.fields.is_some() { - return Err(Error::ProtocolViolation); - } - let mut state = modify(&self.handle.state)?; - let Some(lead) = state.lead.as_deref().filter(|lead| lead.open.is_none()) else { - return Err(Error::ProtocolViolation); - }; - let rest = usize::try_from(frame.size) - .ok() - .and_then(|size| size.checked_sub(lead.byte)) - .filter(|rest| *rest > 0) - .ok_or(Error::ProtocolViolation)?; - let (buf, admission) = FrameBuf::admitted(rest, self.handle.cache.frames()); - // Charged as its bytes arrive, and freed with the last reader holding them. - buf.shared().bill_content(state.charge.extra()); - let info = frame::Info { - size: frame.size, - timestamp, - }; - state.lead.as_deref_mut().expect("checked above").open = Some((info, buf.clone())); - // The ingest settled the relay state before writing the lead, as before any frame. - state.wrote = true; - Ok((info, buf, admission)) - } - /// The meter a streamed frame's chunks bump: none for a plain frame a compressed group /// compresses on commit, which counts its stored slice then, as `bytes` counts payload /// as stored. @@ -2826,15 +2712,7 @@ impl Handle { let same_form = head.compressed == state.flate.is_some(); // A copy that shed its front holds no run from `offset` for the head to precede. let shed = state.held() != offset; - // Nor does one holding only the rest of the frame below `offset` (see [`Lead`]). - let lead = state.lead.is_some(); - if state.outcome.error().is_some() - || state.sparse() - || !same_form - || shed || lead - || head.start >= offset - || !reaches - { + if state.outcome.error().is_some() || state.sparse() || !same_form || shed || head.start >= offset || !reaches { return; } let count = offset - head.start; @@ -3072,11 +2950,7 @@ impl Handle { pub(super) fn covers(&self, frames: Bounds) -> bool { let state = self.state.read(); state.outcome.error().is_none() - && (state.offset as u64 <= frames.start - || state - .lead - .as_ref() - .is_some_and(|lead| lead.index as u64 == frames.start && lead.byte as u64 <= frames.byte)) + && state.offset as u64 <= frames.start && match (state.range_end, frames.end) { (None, _) => true, (Some(cap), Some(end)) => end <= cap as u64, @@ -3084,15 +2958,6 @@ impl Handle { } } - /// The byte this copy starts frame `index` at, if it holds only the rest of it and - /// has not opened it yet (see [`Producer::create_lead`]). - #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] - pub(crate) fn lead_at(&self, index: u64) -> Option { - let state = self.state.read(); - let lead = state.lead.as_deref()?; - (lead.index as u64 == index && lead.open.is_none()).then_some(lead.byte as u64) - } - /// Whether this copy was cut short at the back by its transport request. pub(super) fn back_cut(&self) -> bool { self.state.read().range_end.is_some() @@ -3243,12 +3108,6 @@ impl Handle { || state.flate.as_ref().map_or(0, |flate| flate.plain.bill.size()), |content| content.size(), ) + state.partial.as_ref().map_or(0, |partial| partial.buf.view_size()) - // The rest of a frame the copy started partway into, billed apart from its charge. - + state - .lead - .as_deref() - .and_then(|lead| lead.open.as_ref()) - .map_or(0, |(_, buf)| buf.content_size()) } /// Whether the payload cached after the first frame exceeds `ratio` times the first @@ -4219,7 +4078,7 @@ impl Consumer { } let index = self.cursor.index as u64; let recover = self.recover_mut().expect("only a recovering group needs a replacement"); - let replacement = ready!(recover.poll(index, 0, failed.as_ref(), waiter))?; + let replacement = ready!(recover.poll(index, failed.as_ref(), waiter))?; // A plain read inflates from frame 0, which a replacement starting later lacks // when the failed route's head was not lent to it. if !self.cursor.raw @@ -4363,99 +4222,6 @@ impl Consumer { self } - /// This reader positioned at frame `index`, to continue that frame from byte `byte` - /// with [`Self::poll_next_frame_at`], or `None` when this copy does not hold it from - /// there: it starts past the frame, or partway into it past `byte`. - pub(crate) fn at(self, index: u64, byte: u64) -> Option { - let mut group = self.with_range(index..); - if group.index() == index { - return Some(group); - } - let starts = { - let state = group.cursor.state.read(); - state - .lead - .as_deref() - .is_some_and(|lead| lead.index as u64 == index && lead.byte as u64 <= byte) - }; - if !starts || group.index() != index + 1 { - return None; - } - // Below the copy's start: only `poll_next_frame_at` reads the frame there. - group.cursor.index = index as usize; - group.cursor.prefetch = Prefetch::default(); - group.cursor.partial = false; - Some(group) - } - - /// Whether the group's track compresses its frames. - #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] - pub(crate) fn is_compressed(&self) -> bool { - self.cursor.compressed - } - - /// The next frame, to stream from byte `from` on, which a copy starting partway into - /// it (see [`Bounds::byte`]) serves if it starts at or before `from`. - /// - /// [`Error::WrongSize`] when a non-zero `from` is not within the frame. - pub(crate) fn poll_next_frame_at( - &mut self, - from: usize, - waiter: &kio::Waiter, - ) -> Poll>> { - if self.expired { - return Poll::Ready(Err(Error::Old)); - } - let index = self.cursor.index; - let res = self.cursor.poll(waiter, |state| { - let Some(lead) = state.lead.as_deref().filter(|lead| lead.index == index) else { - return Poll::Ready(Ok(None)); - }; - if from < lead.byte { - return Poll::Ready(Err(Error::Lagged)); - } - match &lead.open { - Some((info, buf)) => Poll::Ready(Ok(Some((*info, buf.clone(), lead.byte)))), - None if state.outcome.error().is_some() || state.outcome.frames().is_some() => { - Poll::Ready(Err(state.outcome.error().cloned().unwrap_or(Error::Lagged))) - } - None => Poll::Pending, - } - }); - // A lead that stops arriving is judged by the read's budget, as a whole frame is. - let lead = ready!(self.poll_expired_if_blocked(waiter, res))?; - let frame = match lead { - Some((info, _, _)) if from as u64 >= info.size => return Poll::Ready(Err(Error::WrongSize)), - Some((info, buf, base)) => { - self.cursor.index += 1; - self.stats.frames(1); - let header = frame::Header { - info, - fields: None, - inflated: None, - }; - let frame = frame::Consumer::new(self.cursor.state.clone(), header, frame::Source::Partial(buf)) - .with_meter(self.stats.clone()) - .starting_at(base, from); - let end = self.cursor.end.unwrap_or(usize::MAX); - match &self.expiry { - Some(policy) => frame.with_expiry( - frame::Expiry::new(policy.clone(), self.stats.clone(), self.delivery.clone()) - .for_frame(self.cursor.index..end, true), - ), - None => frame, - } - } - None => match ready!(self.poll_next_frame(waiter))? { - // A non-zero start names a byte of the frame, so the rest is never empty. - Some(frame) if from > 0 && from as u64 >= frame.size => return Poll::Ready(Err(Error::WrongSize)), - Some(frame) => frame.starting_at(0, from), - None => return Poll::Ready(Ok(None)), - }, - }; - Poll::Ready(Ok(Some(frame))) - } - /// Cap reads before frame `end`, or remove the cap with `None`, without moving the /// start, which [`Self::with_range`] would clamp up to the first available frame. pub(crate) fn with_end(mut self, end: impl Into>) -> Self { @@ -4839,7 +4605,6 @@ impl Consumer { pub(super) fn unread(&self, index: usize) -> Bounds { Bounds { start: index as u64, - byte: 0, end: self.cursor.end.map(|end| end as u64), } } @@ -5326,10 +5091,6 @@ pub struct Fetch { /// There is no public matching end. Private transport caps retain incomplete cache /// provenance, so a bounded reply never answers a later whole-group fetch. pub(crate) frame_start: u64, - - /// The first byte to fetch of frame `frame_start`. Like that start, only a route change - /// sets it: a frame read partway when its route failed asks for the rest of it. - pub(crate) byte_start: u64, } impl Fetch { @@ -6038,30 +5799,6 @@ mod test { ); } - /// A copy holding only the rest of a frame adopts no head over it: the head would hold - /// that frame whole beside its rest, outside the live tail's admission. - #[test] - fn a_copy_with_a_lead_adopts_no_head() { - let mut producer = Info { start: 0 }.produce(); - producer - .bound(Bounds { - start: 1, - byte: 1, - end: None, - }) - .unwrap(); - let adopter = producer.handle(); - let head = Head { - content: None, - start: 0, - first_object: true, - entries: vec![Entry::plain(Frame::new(Timestamp::ZERO, Bytes::from_static(b"ab")).into(), 0); 2], - compressed: false, - }; - adopter.adopt_head(&head); - assert_eq!(adopter.state.read().offset, 2, "the head was adopted over the lead"); - } - /// A head's slots count against the live tail, so a head of empty frames that would /// take the group's slots past it is not adopted. #[test] @@ -6959,140 +6696,6 @@ mod test { } } - /// A copy started partway into frame 1 holds its rest aside: whole reads find the frame - /// missing, a read from at or past the copy's start byte streams the rest, and the frames - /// after it read as usual. - #[test] - #[cfg(feature = "async")] - fn a_copy_started_partway_into_a_frame_serves_only_its_rest() { - let bounded = || { - let mut producer = Info { start: 0 }.produce(); - producer - .bound(Bounds { - start: 1, - byte: 3, - end: None, - }) - .unwrap(); - producer - }; - let next_at = |group: &mut Consumer, from| match group.poll_next_frame_at(from, &kio::Waiter::noop()) { - Poll::Ready(res) => Some(res), - Poll::Pending => None, - }; - - // The rest of a frame no larger than the start is no frame at all. - assert!(matches!( - bounded().create_lead(sized(3).into()), - Err(Error::ProtocolViolation) - )); - - let producer = bounded(); - let handle = producer.handle(); - assert_eq!(handle.lead_at(1), Some(3)); - let covers = |start, byte| handle.covers(Bounds { start, byte, end: None }); - assert!(covers(1, 3) && covers(1, 4) && covers(2, 0)); - assert!(!covers(1, 2) && !covers(1, 0) && !covers(0, 0)); - - let mut lagged = producer.consume(); - lagged.skip_to(1); - assert!(matches!(lagged.read_frame().now_or_never(), Some(Err(Error::Lagged)))); - let mut plain = producer.consume().with_range(0..); - assert_eq!(plain.index(), 2, "a whole read starts past the frame"); - assert!(plain.clone().at(1, 2).is_none(), "the copy starts past byte 2"); - let mut rest = plain.clone().at(1, 4).unwrap(); - let mut early = plain.clone().at(1, 3).unwrap(); - let mut past = plain.clone().at(1, 10).unwrap(); - let mut edge = plain.clone().at(1, 6).unwrap(); - assert!(next_at(&mut rest, 4).is_none(), "waits for the frame to open"); - - let before = handle.cache_size(); - let mut lead = producer.create_lead(sized(6).into()).unwrap(); - assert_eq!(handle.lead_at(1), None, "opened"); - assert!( - plain.clone().poll_wire(&kio::Waiter::noop()).is_ready(), - "the lead settles the relay state" - ); - assert_eq!(lead.remaining(), 3, "only the rest is written"); - lead.write(b"de".as_ref()).unwrap(); - assert!( - matches!(next_at(&mut past, 10), Some(Err(Error::WrongSize))), - "a byte past the frame's end" - ); - assert!( - matches!(next_at(&mut edge, 6), Some(Err(Error::WrongSize))), - "the frame's end leaves no rest" - ); - let mut frame = next_at(&mut rest, 4).unwrap().unwrap().unwrap(); - assert_eq!(frame.size, 6, "it states the frame's full size"); - assert_eq!(&frame.read_chunk().now_or_never().unwrap().unwrap().unwrap()[..], b"e"); - lead.write(b"f".as_ref()).unwrap(); - assert!( - handle.cache_size() >= before + 3, - "the rest counts toward the group's eviction size" - ); - let mut producer = lead.finish().unwrap(); - producer.write_frame(Timestamp::ZERO, b"g".as_ref()).unwrap(); - producer.close().unwrap(); - assert_eq!(&frame.read_chunk().now_or_never().unwrap().unwrap().unwrap()[..], b"f"); - assert!(frame.read_chunk().now_or_never().unwrap().unwrap().is_none()); - assert_eq!( - rest.read_frame().now_or_never().unwrap().unwrap().unwrap().payload, - b"g"[..] - ); - - let mut frame = next_at(&mut early, 3).unwrap().unwrap().unwrap(); - assert_eq!(frame.read_all().now_or_never().unwrap().unwrap(), b"def"[..]); - - let read = plain.read_frame().now_or_never().unwrap().unwrap().unwrap(); - assert_eq!(read.payload, b"g"[..], "whole reads skip the frame held in part"); - } - - /// The rest of a frame the copy started partway into counts toward the live tail, and - /// is the first frame a later one sheds past it; a reader already holding it keeps it. - #[test] - #[cfg(feature = "async")] - fn a_lead_is_shed_first_past_the_live_tail() { - let half = MAX_CACHE_BYTES / 2; - let mut producer = Info { start: 0 }.produce(); - producer - .bound(Bounds { - start: 0, - byte: 1, - end: None, - }) - .unwrap(); - let handle = producer.handle(); - let mut holding = producer.consume().at(0, 1).unwrap(); - let mut late = producer.consume().at(0, 1).unwrap(); - - let mut lead = producer.create_lead(sized(half + 1).into()).unwrap(); - lead.write(Bytes::from(vec![1u8; half as usize])).unwrap(); - let mut producer = lead.finish().unwrap(); - let mut frame = match holding.poll_next_frame_at(1, &kio::Waiter::noop()) { - Poll::Ready(Ok(Some(frame))) => frame, - _ => panic!("the lead is readable"), - }; - assert!(handle.cache_size() >= half); - - producer - .write_frame(Timestamp::ZERO, Bytes::from(vec![2u8; (half + half / 2) as usize])) - .unwrap(); - assert!(handle.cache_size() < MAX_CACHE_BYTES, "the lead was not shed"); - assert!( - matches!( - late.poll_next_frame_at(1, &kio::Waiter::noop()), - Poll::Ready(Err(Error::Lagged)) - ), - "a reader that had not taken the lead finds it gone" - ); - assert_eq!( - frame.read_all().now_or_never().unwrap().unwrap().len() as u64, - half, - "a reader holding the lead keeps it" - ); - } - /// A declared size costs the peer nothing, so the pool is charged as the bytes /// arrive. Charging the declaration would let a peer evict the cache without /// sending anything. @@ -7741,13 +7344,7 @@ mod test { let cache = cache::Track::new(pool.clone(), Default::default(), kio::Weak::new()); let info = track::Info::default().with_compression(crate::track::Compression::Deflate); let mut released = Producer::new(Info::from(0u64), info.clone(), cache.clone()); - released - .bound(Bounds { - byte: 0, - start: 0, - end: Some(2), - }) - .unwrap(); + released.bound(Bounds { start: 0, end: Some(2) }).unwrap(); for index in 0..2 { released .write_frame(crate::Timestamp::unscaled(released.start), verbose(index)) @@ -8036,57 +7633,6 @@ mod test { assert!(matches!(finished.poll_finished(&waiter), Poll::Ready(Err(Error::Old)))); } - /// A read continuing a frame from a byte gives up with the read's budget, whether the - /// rest of the frame never opens or stops arriving partway. - #[test] - #[cfg(feature = "async")] - fn a_lead_read_expires_as_old() { - let bounded = || { - let mut producer = Info { start: 0 }.produce(); - producer - .bound(Bounds { - start: 0, - byte: 1, - end: None, - }) - .unwrap(); - producer - }; - let waiter = kio::Waiter::noop(); - - let producer = bounded(); - let expired = Switch::default(); - let mut group = producer - .consume() - .with_expiry(Arc::new(expired.clone())) - .at(0, 1) - .unwrap(); - assert!(group.poll_next_frame_at(1, &waiter).is_pending(), "waits for the lead"); - expired.set(true); - assert!(matches!( - group.poll_next_frame_at(1, &waiter), - Poll::Ready(Err(Error::Old)) - )); - - let producer = bounded(); - let expired = Switch::default(); - let mut group = producer - .consume() - .with_expiry(Arc::new(expired.clone())) - .at(0, 1) - .unwrap(); - let mut lead = producer.create_lead(sized(4).into()).unwrap(); - lead.write(b"b".as_ref()).unwrap(); - let mut frame = match group.poll_next_frame_at(1, &waiter) { - Poll::Ready(Ok(Some(frame))) => frame, - _ => panic!("the lead is readable"), - }; - assert_eq!(&frame.read_chunk().now_or_never().unwrap().unwrap().unwrap()[..], b"b"); - assert!(frame.read_chunk().now_or_never().is_none(), "waits for the rest"); - expired.set(true); - assert!(matches!(frame.read_chunk().now_or_never(), Some(Err(Error::Old)))); - } - /// Records a wake. #[derive(Default)] struct Woken(AtomicBool); @@ -8201,13 +7747,7 @@ mod test { #[test] fn a_bounded_copy_finished_short_of_its_bound_ends_cleanly() { let mut producer = Info { start: 0 }.produce(); - producer - .bound(Bounds { - byte: 0, - start: 0, - end: Some(4), - }) - .unwrap(); + producer.bound(Bounds { start: 0, end: Some(4) }).unwrap(); let mut reader = producer.consume(); for payload in [b"a", b"b"] { producer diff --git a/rs/moq-net/src/model/resume.rs b/rs/moq-net/src/model/resume.rs index 79adef2bf81..7c370d5a628 100644 --- a/rs/moq-net/src/model/resume.rs +++ b/rs/moq-net/src/model/resume.rs @@ -27,10 +27,9 @@ //! //! A group carries on across the switch through its [`Recover`]: once its copy stalls while //! a newer route serves, it continues from the serving route's copy of the same group at the -//! same frame (and byte), found in that copy's cache or fetched from it, which over lite-07 -//! asks only for the bytes of a frame past those already read. Once its copy fails, -//! any other copy still holding the group continues it first, since a group's name fixes its -//! content. +//! same frame, found in that copy's cache or fetched from it, skipping the bytes of a frame +//! already read. Once its copy fails, any other copy still holding the group continues it +//! first, since a group's name fixes its content. //! //! A group is handed out once however many copies deliver it: the reader skips any //! key its [`track::Subscriber`] already handed out, the same record that keeps a @@ -2237,15 +2236,13 @@ impl Recover { || (self.reader.is_none() && matches!(StreamError::from(err), StreamError::Old | StreamError::Evicted)) } - /// Poll for the serving route's copy of the group, positioned at frame `index` to read - /// it from byte `byte` on: a frame read partway asks only for the rest of it. + /// Poll for the serving route's copy of the group, positioned at frame `index`. /// /// `failed` is the error the current copy ended with, if it did; a stall is `None`. /// Returns the copy's error when nothing can continue the group. pub(super) fn poll( &mut self, index: u64, - byte: u64, failed: Option<&Error>, waiter: &kio::Waiter, ) -> Poll> { @@ -2285,7 +2282,7 @@ impl Recover { // fixes its content. A stall only moves to the serving copy, so two stalled copies // never trade the group back and forth. if failed.is_some() - && let Some(replacement) = self.held(index, byte) + && let Some(replacement) = self.held(index) { return Poll::Ready(Ok(replacement)); } @@ -2315,7 +2312,7 @@ impl Recover { if generation == self.generation && failed.is_none() { return Poll::Pending; } - let res = self.poll_serving(generation, &serving, (index, byte), failed, withdrawn.is_none(), waiter); + let res = self.poll_serving(generation, &serving, index, failed, withdrawn.is_none(), waiter); // The serving route failed too, and no front is left to replace it. if let (Poll::Pending, Some(err)) = (&res, failed) && terminal && copy_failed(&serving) @@ -2333,8 +2330,8 @@ impl Recover { } /// The group from the newest of the reader's other copies that still holds it unfailed, - /// positioned at frame `index` to read from byte `byte`. - fn held(&self, index: u64, byte: u64) -> Option { + /// positioned at frame `index`. + fn held(&self, index: u64) -> Option { let reader = self.reader.as_ref()?.upgrade()?; let reader = reader.lock().unwrap_or_else(PoisonError::into_inner); reader.copies.iter().rev().find_map(|copy| { @@ -2343,7 +2340,8 @@ impl Recover { } let group = copy.track.peek_group(self.key)?; lend_head(&self.handoff, self.key, ©.track, &group); - group.at(index, byte).map(|group| Replacement { + let group = group.with_range(index..); + (group.index() == index).then(|| Replacement { group, generation: copy.generation, copy: copy.track.clone(), @@ -2357,7 +2355,7 @@ impl Recover { &mut self, generation: u64, serving: &track::Consumer, - (index, byte): (u64, u64), + index: u64, failed: Option<&Error>, ask: bool, waiter: &kio::Waiter, @@ -2368,7 +2366,8 @@ impl Recover { match serving.poll_group(self.key, waiter) { Poll::Ready(Ok(Some(group))) if !same => { lend_head(&self.handoff, self.key, serving, &group); - if let Some(group) = group.at(index, byte) { + let group = group.with_range(index..); + if group.index() == index { return Poll::Ready(Ok(Replacement { group, generation, @@ -2398,27 +2397,19 @@ impl Recover { { verdict = Some(err); } - match self.poll_fetch( - generation, - serving, - (index, byte), - failed, - ask && verdict.is_none(), - waiter, - ) { + match self.poll_fetch(generation, serving, index, failed, ask && verdict.is_none(), waiter) { Poll::Ready(Ok(replacement)) => Poll::Ready(Ok(replacement)), res => verdict.map_or(res, |err| Poll::Ready(Err(err))), } } - /// Ask `serving` for the rest of the group from byte `byte` of frame `index`, unless told - /// not to `ask`, and poll the answer: the group, a refusal that ends a copy that failed, - /// or nothing yet. + /// Ask `serving` for the rest of the group from frame `index`, unless told not to `ask`, and + /// poll the answer: the group, a refusal that ends a copy that failed, or nothing yet. fn poll_fetch( &mut self, generation: u64, serving: &track::Consumer, - (index, byte): (u64, u64), + index: u64, failed: Option<&Error>, ask: bool, waiter: &kio::Waiter, @@ -2431,7 +2422,6 @@ impl Recover { let options = group::Fetch { max_delay: self.max_delay, frame_start: index, - byte_start: byte, ..Default::default() }; self.fetch = Some(( @@ -2449,7 +2439,8 @@ impl Recover { Fetch::Pending(pending) => match ready!(kio::Task::poll(&mut **pending, waiter)) { Ok(group) => { lend_head(&self.handoff, self.key, serving, &group); - if let Some(group) = group.at(index, byte) { + let group = group.with_range(index..); + if group.index() == index { return Poll::Ready(Ok(Replacement { group, generation, @@ -3837,122 +3828,6 @@ mod test { assert!(chunks.read_chunk().now_or_never().unwrap().unwrap().is_none()); } - /// A frame read partway when its route dies asks the next route for only the rest of it, - /// which a copy starting partway into the frame serves. - #[test] - #[cfg(feature = "async")] - fn a_half_read_frame_asks_only_for_the_rest() { - let routes = Producer::new(); - let logical = logical(&routes); - let a = copy(); - routes.serve(a.consume()); - let mut sub = subscribe(&logical, Duration::from_secs(10)); - - let open = a.create_group(group::Info { start: 0 }).unwrap(); - let mut frame = open - .create_frame(crate::frame::Info { - size: 4, - timestamp: ts(0), - }) - .unwrap(); - frame.write(b"ab".as_ref()).unwrap(); - let mut reading = recv(&mut sub); - let mut chunks = reading.next_frame().now_or_never().unwrap().unwrap().unwrap(); - assert_eq!( - &chunks.read_chunk().now_or_never().unwrap().unwrap().unwrap()[..], - b"ab" - ); - - drop(frame); - a.clone().abort(Error::Dropped).unwrap(); - let b = copy(); - let dynamic = b.requests(); - routes.serve(b.consume()); - assert!(chunks.read_chunk().now_or_never().is_none()); - let request = dynamic.requested_fill_group().now_or_never().unwrap().unwrap(); - assert_eq!((request.frame_start(), request.byte_start()), (0, 2)); - - // The answer holds the frame from byte 2 only, so a whole read of it finds nothing. - let rest = request - .accept_from( - crate::track::Info::timed(), - group::Bounds { - start: 0, - byte: 2, - end: None, - }, - ) - .unwrap(); - let mut lead = rest - .create_lead( - crate::frame::Info { - size: 4, - timestamp: ts(0), - } - .into(), - ) - .unwrap(); - lead.write(b"cd".as_ref()).unwrap(); - let mut rest = lead.finish().unwrap(); - rest.write_frame(ts(1), b"e".as_ref()).unwrap(); - rest.close().unwrap(); - - assert_eq!( - &chunks.read_chunk().now_or_never().unwrap().unwrap().unwrap()[..], - b"cd" - ); - assert!(chunks.read_chunk().now_or_never().unwrap().unwrap().is_none()); - assert_eq!(read(&mut reading), Some(b"e".to_vec())); - } - - /// A route that answers a byte ask with whole frames, as moq-transport and app - /// handlers do, keeps each frame at its index, and the read skips the bytes it had. - #[test] - #[cfg(feature = "async")] - fn a_half_read_frame_continues_from_a_whole_frame_answer() { - let routes = Producer::new(); - let logical = logical(&routes); - let a = copy(); - routes.serve(a.consume()); - let mut sub = subscribe(&logical, Duration::from_secs(10)); - - let open = a.create_group(group::Info { start: 0 }).unwrap(); - let mut frame = open - .create_frame(crate::frame::Info { - size: 4, - timestamp: ts(0), - }) - .unwrap(); - frame.write(b"ab".as_ref()).unwrap(); - let mut reading = recv(&mut sub); - let mut chunks = reading.next_frame().now_or_never().unwrap().unwrap().unwrap(); - assert_eq!( - &chunks.read_chunk().now_or_never().unwrap().unwrap().unwrap()[..], - b"ab" - ); - - drop(frame); - a.clone().abort(Error::Dropped).unwrap(); - let b = copy(); - let dynamic = b.requests(); - routes.serve(b.consume()); - assert!(chunks.read_chunk().now_or_never().is_none()); - let request = dynamic.requested_fill_group().now_or_never().unwrap().unwrap(); - assert_eq!((request.frame_start(), request.byte_start()), (0, 2)); - - let mut rest = request.accept(None).unwrap(); - rest.write_frame(ts(0), b"abcd".as_ref()).unwrap(); - rest.write_frame(ts(1), b"e".as_ref()).unwrap(); - rest.close().unwrap(); - - assert_eq!( - &chunks.read_chunk().now_or_never().unwrap().unwrap().unwrap()[..], - b"cd" - ); - assert!(chunks.read_chunk().now_or_never().unwrap().unwrap().is_none()); - assert_eq!(read(&mut reading), Some(b"e".to_vec())); - } - /// A resumed group that the serving route gives up or aborts ends with that route's /// error, even with no successor or later writes and its fetch still unanswered. #[test] diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 9a345abc970..fc09778760c 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -1773,7 +1773,6 @@ impl TrackState { key, group::Bounds { start: frame_start, - byte: 0, end: None, }, ) @@ -3908,7 +3907,6 @@ impl Boarding { pub(super) fn poll(&mut self, waiter: &kio::Waiter) -> Poll> { let frames = group::Bounds { start: self.frame, - byte: 0, end: None, }; let key = self.key; @@ -4301,11 +4299,7 @@ impl Producer { state.claim_key(info.start, start)?; let mut group = group::Producer::new(info, track, state.cache.clone()).with_meter(state.ingress.meter()); if start != 0 { - group.bound(group::Bounds { - start, - byte: 0, - end: None, - })?; + group.bound(group::Bounds { start, end: None })?; } if let Some(content) = content { group.handle().share_content(content); @@ -6420,7 +6414,6 @@ impl Consumer { || state.info.as_ref().is_none_or(|info| info.compressed()) { request.options.frame_start = 0; - request.options.byte_start = 0; } // A compressed stream needs the entire dictionary; an unknown track is conservative // until TRACK_INFO has told the relay which representation it will receive. @@ -6451,7 +6444,6 @@ impl Consumer { fills, key, frame_start: options.frame_start, - byte_start: options.byte_start, frame_end, priority: options.priority, max_delay: options.max_delay, @@ -6473,7 +6465,6 @@ impl Consumer { fills: state.read().fills.clone(), key, frame_start: options.frame_start, - byte_start: options.byte_start, frame_end, priority: options.priority, max_delay: options.max_delay, @@ -6808,7 +6799,6 @@ fn queue(fills: &kio::Shared, key: u64, request: &FetchOptions) -> Op group: key, frame: options.frame_start, }, - byte: options.byte_start, end, frame_end: request.end, asking: fill::Asking { @@ -6845,7 +6835,6 @@ pub struct Fetching { // This caller's own start, so a cached group that begins above it is a miss // rather than a short answer. frame_start: u64, - byte_start: u64, frame_end: Option, // This caller's priority, for a fetch that moves to a front's routes. priority: i8, @@ -6879,7 +6868,6 @@ impl Fetching { ) -> Self { let frames = group::Bounds { start: request.options.frame_start, - byte: request.options.byte_start, end: request.end, }; let (fills, cached) = { @@ -6901,7 +6889,6 @@ impl Fetching { fills, key, frame_start: request.options.frame_start, - byte_start: request.options.byte_start, frame_end: request.end, priority: request.options.priority, max_delay: request.options.max_delay, @@ -6949,7 +6936,6 @@ impl Fetching { priority: self.priority, max_delay: self.max_delay, frame_start: self.frame_start, - byte_start: self.byte_start, }; self.resume = Some(Box::new(routes.fetch_group( self.key, @@ -7007,7 +6993,6 @@ impl Fetching { // error is the channel closing without any of those. let frames = group::Bounds { start: frame_start, - byte: self.byte_start, end: self.frame_end, }; let cached = |waiter: &kio::Waiter| match state.poll(waiter, |state| state.poll_fetch_cached(key, frames)) { @@ -7064,7 +7049,6 @@ impl Fetching { priority: self.priority, max_delay: self.max_delay, frame_start: self.frame_start, - byte_start: self.byte_start, }; self.result = queue( &self.fills, @@ -8959,7 +8943,6 @@ impl Cursor { } let ask = fill::Ask { start: Position::group(0), - byte: 0, end: reach, frame_end: None, asking: *asking, @@ -9278,7 +9261,6 @@ impl Cursor { priority: asking.priority, max_delay: asking.delay.max, frame_start: 0, - byte_start: 0, }, end: None, }; @@ -18011,15 +17993,7 @@ mod test { .write() .ok() .unwrap() - .insert_group_request( - 3, - group::Bounds { - byte: 0, - start: 0, - end: Some(3), - }, - None, - ) + .insert_group_request(3, group::Bounds { start: 0, end: Some(3) }, None) .unwrap(); for (millis, payload) in [(300, b"a"), (301, b"b"), (302, b"c")] { head.write_frame(at(millis), &payload[..]).unwrap(); @@ -18045,15 +18019,7 @@ mod test { .write() .ok() .unwrap() - .insert_group_request( - 3, - group::Bounds { - byte: 0, - start: 0, - end: Some(3), - }, - None, - ) + .insert_group_request(3, group::Bounds { start: 0, end: Some(3) }, None) .unwrap(); let mut reader = head.consume().with_range(..3); for (millis, payload) in [(300, b"a"), (301, b"b"), (302, b"c")] { @@ -18099,15 +18065,7 @@ mod test { .write() .ok() .unwrap() - .insert_group_request( - 3, - group::Bounds { - byte: 0, - start: 2, - end: Some(3), - }, - None, - ) + .insert_group_request(3, group::Bounds { start: 2, end: Some(3) }, None) .unwrap(); drop(hold); cut.write_frame(at(302), &b"c"[..]).unwrap(); @@ -18196,15 +18154,7 @@ mod test { .write() .ok() .unwrap() - .insert_group_request( - 3, - group::Bounds { - byte: 0, - start: 0, - end: Some(3), - }, - None, - ) + .insert_group_request(3, group::Bounds { start: 0, end: Some(3) }, None) .unwrap(); for (millis, payload) in [(300, b"a"), (301, b"b"), (302, b"c")] { head.write_frame(at(millis), &payload[..]).unwrap(); @@ -26747,7 +26697,6 @@ mod test { 0, group::Bounds { start, - byte: 0, end: Some(start + 1), }, None, @@ -26776,15 +26725,7 @@ mod test { .write() .ok() .unwrap() - .insert_group_request( - 0, - group::Bounds { - byte: 0, - start: 0, - end: Some(1), - }, - None, - ) + .insert_group_request(0, group::Bounds { start: 0, end: Some(1) }, None) .unwrap(); assert!(Arc::ptr_eq(&owner, &refill.handle().content().unwrap())); refill.write_frame(refill.key_time(), b"zero".as_slice()).unwrap(); @@ -26804,15 +26745,7 @@ mod test { .write() .ok() .unwrap() - .insert_group_request( - 0, - group::Bounds { - byte: 0, - start: 0, - end: Some(1), - }, - None, - ) + .insert_group_request(0, group::Bounds { start: 0, end: Some(1) }, None) .unwrap(); new.write_frame(new.key_time(), b"new zero".as_slice()).unwrap(); assert!(!Arc::ptr_eq(&owner, &new.handle().content().unwrap())); @@ -26849,15 +26782,7 @@ mod test { .write() .ok() .unwrap() - .insert_group_request( - 0, - group::Bounds { - byte: 0, - start: 3, - end: Some(5), - }, - None, - ) + .insert_group_request(0, group::Bounds { start: 3, end: Some(5) }, None) .unwrap(); second.write_frame(second.key_time(), b"three".as_slice()).unwrap(); let mut second_read = second.consume().with_range(4..); @@ -26966,15 +26891,7 @@ mod test { .write() .ok() .unwrap() - .insert_group_request( - 0, - group::Bounds { - byte: 0, - start: 1, - end: Some(3), - }, - None, - ) + .insert_group_request(0, group::Bounds { start: 1, end: Some(3) }, None) .unwrap(); head.set_wire(wire(90)).unwrap(); let head = write(head, 90, b"b"); @@ -26990,15 +26907,7 @@ mod test { .write() .ok() .unwrap() - .insert_group_request( - 0, - group::Bounds { - byte: 0, - start: 0, - end: Some(2), - }, - None, - ) + .insert_group_request(0, group::Bounds { start: 0, end: Some(2) }, None) .unwrap(); earlier.set_wire(wire(90)).unwrap(); let earlier = write(earlier, 90, b"b"); @@ -27214,15 +27123,7 @@ mod test { .write() .ok() .unwrap() - .insert_group_request( - 0, - group::Bounds { - byte: 0, - start: 3, - end: Some(4), - }, - None, - ) + .insert_group_request(0, group::Bounds { start: 3, end: Some(4) }, None) .unwrap(); head.write_frame(head.key_time(), b"three".as_slice()).unwrap(); head.close().unwrap(); @@ -27245,15 +27146,7 @@ mod test { .write() .ok() .unwrap() - .insert_group_request( - 0, - group::Bounds { - byte: 0, - start: 4, - end: Some(5), - }, - None, - ) + .insert_group_request(0, group::Bounds { start: 4, end: Some(5) }, None) .unwrap(); assert!(Arc::ptr_eq( &identity.upgrade().unwrap(), @@ -27293,15 +27186,7 @@ mod test { .write() .ok() .unwrap() - .insert_group_request( - 0, - group::Bounds { - byte: 0, - start: 0, - end: Some(1), - }, - None, - ) + .insert_group_request(0, group::Bounds { start: 0, end: Some(1) }, None) .unwrap(); head.write_frame(head.key_time(), bytes::Bytes::new()).unwrap(); let head = head.close().unwrap(); diff --git a/rs/moq-net/src/model/track/fill.rs b/rs/moq-net/src/model/track/fill.rs index 0889fe43889..94be67cbedb 100644 --- a/rs/moq-net/src/model/track/fill.rs +++ b/rs/moq-net/src/model/track/fill.rs @@ -44,8 +44,6 @@ pub(in crate::model) struct FillState { /// One fill until it ends. struct Pending { start: Position, - // The first byte asked of frame `start`, for a reader continuing it partway. - byte: u64, end: u64, // Exclusive frame cap in the last group; None asks through the original end. frame_end: Option, @@ -285,8 +283,6 @@ impl Eq for Refusal {} /// A reader's request: the run `start.group..end`, from `start.frame` in its first group. pub(super) struct Ask { pub start: Position, - /// The first byte of frame `start` the reader wants: it already holds those before. - pub byte: u64, pub end: u64, pub frame_end: Option, pub asking: Asking, @@ -498,13 +494,13 @@ impl FillState { let pending = self.pending.get_mut(&id).expect("a covered key names a pending fill"); if groups.start == pending.start.group { // A reader starting in an earlier group wants this one whole. - let (frame, byte) = match ask.start.group == groups.start { - true => (ask.start.frame, ask.byte), - false => (0, 0), + let frame = match ask.start.group == groups.start { + true => ask.start.frame, + false => 0, }; - if (frame, byte) < (pending.start.frame, pending.byte) { + if frame < pending.start.frame { match pending.queued { - true => (pending.start.frame, pending.byte) = (frame, byte), + true => pending.start.frame = frame, // Taken: its handler may have asked its source from the later frame // already, so the earlier frames are a fill of their own. false => { @@ -559,9 +555,9 @@ impl FillState { } let id = self.next; self.next += 1; - let (start, byte) = match groups.start == ask.start.group { - true => (ask.start, ask.byte), - false => (Position::group(groups.start), 0), + let start = match groups.start == ask.start.group { + true => ask.start, + false => Position::group(groups.start), }; let result = kio::Producer::::default(); let mut asks = Asks::default(); @@ -583,7 +579,6 @@ impl FillState { id, Pending { start, - byte, end: groups.end, frame_end: if groups.end == ask.end { ask.frame_end } else { None }, time: None, @@ -636,7 +631,6 @@ impl FillState { id, Pending { start: Position { group: key, frame }, - byte: 0, end: groups.end, frame_end: None, time: None, @@ -688,7 +682,6 @@ impl FillState { id, Pending { start: ask.start, - byte: 0, end: ask.end, frame_end: None, time: Some(time), @@ -820,9 +813,8 @@ pub(super) fn poll_requested( }) { let id = guard.pop().expect("predicate guaranteed a fill"); let pending = guard.pending.get(&id).expect("popped fill is pending"); - let (start, byte, end, frame_end, time, flight) = ( + let (start, end, frame_end, time, flight) = ( pending.start, - pending.byte, pending.end, pending.frame_end, pending.time, @@ -836,7 +828,6 @@ pub(super) fn poll_requested( fills: fills.clone(), id, start, - byte, end, frame_end, time, @@ -903,8 +894,6 @@ struct Inner { fills: kio::Shared, id: u64, start: Position, - // The first byte of frame `start` asked for. - byte: u64, end: u64, // Exclusive frame cap in the last group; None asks through the original end. frame_end: Option, @@ -1261,7 +1250,6 @@ impl Fill { inner: self.inner.clone(), key, frame_start: self.inner.frame_start(key), - byte_start: self.inner.byte_start(key), frame_end: self.inner.bounds(key).end, priority: self.priority(), max_delay: self.max_delay(), @@ -1320,18 +1308,9 @@ impl Inner { } } - /// The first byte group `key` starts from within its first frame. - fn byte_start(&self, key: u64) -> u64 { - match key == self.start.group { - true => self.byte, - false => 0, - } - } - fn bounds(&self, key: u64) -> group::Bounds { group::Bounds { start: self.frame_start(key), - byte: self.byte_start(key), end: if key.checked_add(1) == Some(self.end) { self.frame_end } else { @@ -1340,15 +1319,8 @@ impl Inner { } } - /// A writer that never says it answers from a byte writes whole frames, so its copy - /// starts at a frame boundary even when the fill asked from a byte: only - /// [`GroupFill::accept_from`] starts one partway into a frame. fn accept(&self, key: u64, info: Option) -> Result { - let frames = group::Bounds { - byte: 0, - ..self.bounds(key) - }; - self.accept_from(key, info, frames) + self.accept_from(key, info, self.bounds(key)) } fn accept_from(&self, key: u64, info: Option, frames: group::Bounds) -> Result { @@ -1394,7 +1366,7 @@ impl Inner { if let Ok(mut outcome) = self.result.write() { outcome.accept(key..end); if let Ok(group) = &res - && (self.flight || frames.start > 0 || frames.byte > 0 || frames.end.is_some()) + && (self.flight || frames.start > 0 || frames.end.is_some()) { outcome.partial.insert(key, group.handle()); } @@ -1606,7 +1578,6 @@ pub(crate) struct GroupFill { inner: Arc>, key: u64, frame_start: u64, - byte_start: u64, frame_end: Option, priority: i8, max_delay: Option, @@ -1635,11 +1606,6 @@ impl GroupFill { self.frame_start } - /// The first byte of frame [`Self::frame_start`] the readers want; 0 is the whole frame. - pub(crate) fn byte_start(&self) -> u64 { - self.byte_start - } - /// The requested exclusive last frame, if this copy is bounded at the back. pub(crate) fn frame_end(&self) -> Option { self.frame_end diff --git a/rs/moq-net/src/model/track/miss.rs b/rs/moq-net/src/model/track/miss.rs index a3831d1818c..12d9d559188 100644 --- a/rs/moq-net/src/model/track/miss.rs +++ b/rs/moq-net/src/model/track/miss.rs @@ -1318,7 +1318,6 @@ impl Misses { for run in runs { let ask = Ask { start: Position::group(run.start), - byte: 0, end: run.end, frame_end: None, asking: *asking, diff --git a/rs/moq-net/src/recv.rs b/rs/moq-net/src/recv.rs index e866defba65..a475e6f77c2 100644 --- a/rs/moq-net/src/recv.rs +++ b/rs/moq-net/src/recv.rs @@ -64,22 +64,6 @@ impl Group { .map(frame::Producer::cancel_on_drop) } - /// The byte the copy starts frame `index` at, if it holds only the rest of that frame - /// (see [`group::Producer::create_lead`]). - pub fn lead_at(&self, index: u64) -> Option { - self.handle.lead_at(index) - } - - /// Move the writer and cancellation cleanup into the rest of the frame the copy starts - /// partway into. - pub fn create_lead(&mut self, frame: frame::Header) -> Result { - self.writer - .take() - .expect("group writer is available between frames") - .create_lead(frame) - .map(frame::Producer::cancel_on_drop) - } - /// Poll until the writer may admit the frame `header` opens, its payload and metadata, /// within `window` bytes past its fastest reader, so admitting it sheds no byte that /// reader has yet to take; see [`group::Producer::poll_paced`]. diff --git a/rs/moq-net/tests/integration/byte_holes.rs b/rs/moq-net/tests/integration/half_read_frame.rs similarity index 90% rename from rs/moq-net/tests/integration/byte_holes.rs rename to rs/moq-net/tests/integration/half_read_frame.rs index 6bb37a83088..4cff46521fb 100644 --- a/rs/moq-net/tests/integration/byte_holes.rs +++ b/rs/moq-net/tests/integration/half_read_frame.rs @@ -1,13 +1,12 @@ #![cfg(feature = "async")] //! A frame read partway when its route dies continues on the next route from the byte it -//! reached: over lite-07 the subscriber asks for only the rest of the frame, so the new route -//! sends none of the bytes already read. +//! reached: the subscriber FETCHes the whole frame again and skips the bytes already read. //! //! The publisher `P` is pulled by relays `A` and `B`. The subscribing relay `E` reads a large //! frame of group 0 halfway through `A`, then a cheaper route through `B` wins and `A`'s -//! session to `E` dies. `B`'s subscription starts at group 1, so `E` FETCHes the rest of the -//! frame from `B`. +//! session to `E` dies. `B`'s subscription starts at group 1, so `E` FETCHes the frame from +//! `B`. use crate::route_change::{link, priced_link, produce_origin, settle, timed}; use crate::support::harness::{MockConnectOptions, connect_mock}; @@ -35,7 +34,7 @@ fn sent(registry: &stats::Registry) -> u64 { } #[kio::test] -async fn a_half_read_frame_continues_from_its_byte() { +async fn a_half_read_frame_refetches_whole_and_skips_what_was_read() { let version: Version = "moq-lite-07-wip".parse().unwrap(); let publisher = produce_origin(1); let relay_a = produce_origin(2); @@ -113,12 +112,12 @@ async fn a_half_read_frame_continues_from_its_byte() { assert!(got == payload, "the frame continues at its byte"); // A publisher bills what the transport acknowledged, which trails what `E` read. + // `B` sends the whole frame again, plus group 1's. settle().await; - let rest = (SIZE - HALF) as u64; let sent = sent(®istry); - assert!(sent >= rest, "{sent} bytes cannot carry the {rest} left"); + let whole = SIZE as u64; assert!( - sent < rest + 1024, - "{sent} bytes resent what `E` read: only {rest} were left" + (whole..whole + 1024).contains(&sent), + "{sent} bytes for a {whole}-byte frame" ); } diff --git a/rs/moq-net/tests/integration/main.rs b/rs/moq-net/tests/integration/main.rs index 6acf754bf36..a57532402f3 100644 --- a/rs/moq-net/tests/integration/main.rs +++ b/rs/moq-net/tests/integration/main.rs @@ -12,7 +12,6 @@ mod announce_to_serve; mod answer_behind_cache; mod auth; mod broadcast_close; -mod byte_holes; mod catalog_acquisition; mod catalog_churn; mod catalog_handover; @@ -39,6 +38,7 @@ mod finite_relay; mod flights; mod goaway; mod group_order; +mod half_read_frame; mod history_groups; mod history_join; mod idle_cancel_refetch;