summaryrefslogtreecommitdiff
path: root/test/replicas.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 00:05:38 -0300
committerGabriel Schneider <[email protected]>2026-11-23 00:40:36 -0300
commita3d98f0e465ed9634d0534e0a6c71767b2a709b9 (patch)
treed8f777c00b13490c245ee7c93aa2a932c406173a /test/replicas.zig
parente6dd9c5c3a60e3609e99ab2076b5a2509a014a66 (diff)
downloadpardes-a3d98f0e465ed9634d0534e0a6c71767b2a709b9.tar.gz
pardes-a3d98f0e465ed9634d0534e0a6c71767b2a709b9.zip
link: a client whose link is up and must take the session's state again (it diverged, fell 2 s behind, or the session cut it off 64 MB behind) comes back OVER THAT LINK, the daemon not asked: its goodbye that says `again` and today's hello for its view in one write (`replica.comeBack`, runtime/client.zig `Loop.run` when `Link.backHere`), its reader letting the stream it leaves go (units, blobs and checks not even copied) and stopping at the session's welcome there, put back at its framer's front for the join's reader (`readLink`'s back mode, `Framer.putBack`), the join read on that framer (`joinOn` takes it; `replica.join`'s `here`); on the session the reader reads on after a `bye` that says `again`, a hello after it is the same client back (`Peer.take`, inputs numbered afresh), and `Peers.joinAgain` dumps for it there with what the old road put on the tape (`awayView`, then the join's `viewFor`: every side's terminals reloaded in that step), what was queued for it let go, the cut over; one writer loop writes a join whenever one is due (`Peer.gen`, `Peer.written`; the `.joined` note carries its gen so a stale one releases nothing), what it was sent a MiB at most a write at a message's end (`writeOut`) so a join due waits for no more of the old stream, a far client's old zstd frame ended before the welcome; a cut keeps the link (its words, then nothing until the hello); a link that ends before the welcome (an Upgrade's or a Restore's words: the session closes it), or one gone, is dialled again as before: the one case left for a redial; and a client refused its own load (`fromDump`) asks ONCE more over the same link with the session's digest a word a field after that dump (wire 31, nothing at 31 installed: a bye's byte 3 = `again` + `parts`, a new ServerTag `parts` 0x0d) and only then gives up, naming the fields that differ in its words and its log; the failing run first: test/daemon.py's new `pair_back` (a no-daemon pair whose client diverges, and one stopped 3 s while the session is edited) on the installed build 79b73e14711e: "the client and the session went (client exit 1)", "'diverged' let this client go", on this tree both join again over their own link, the session alive, the unsaved text there, agreed; `clients`: client D's socket the same across its rejoin, the session counting 6 joins, 1 over a client's own link and 5 handed by the daemon; `far_flood` (20 KB/s, 200 ms): the same link after 3 joins again of 0.56 s each against a dial each time on the installed build (0.99 s each), but agreement 68.6 s after `yes` ended against 22.7 s: the client reads through what the relay holds for it (the relay buffers without bound; ssh bounds it by its window), said in reports/pardes-link-lifecycle.md; `Peer.rejoin` and `hungUp` stay for the one road that still dials after a goodbye saying `again` (a client of another build exec'ing: `sameBuild`), their test rewritten for it; core tests at the replica's surface with real link threads (near and far: back over its own link; a refused load asked once more and loaded; refused twice and named, against a session played by hand; a cut client back over its link, the same peer, connection and view); the soak models the road (`ended`, `Soak.joinDown`, the `here` column); core-test 924/1084 (160 skipped), shell-test 1126/1129 (3 skipped), root.zig's machine_lines for replica.zig 76 -> 90 (the tests' sockets and sleeps; the session's one shutdown of a link it will not dump for again, and a close)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/replicas.zig')
-rw-r--r--test/replicas.zig122
1 files changed, 68 insertions, 54 deletions
diff --git a/test/replicas.zig b/test/replicas.zig
index 8f3e5ca5..247fc408 100644
--- a/test/replicas.zig
+++ b/test/replicas.zig
@@ -251,6 +251,8 @@ const Totals = struct {
/// Joins from a dump, refused, again after a divergence put on it
/// (PARDES_TEST_DIVERGE's), and clients that left; quiet checks.
joins: u64 = 0,
+ /// ...of them again over the client's own link (no dial).
+ here: u64 = 0,
refused: u64 = 0,
/// A pair's client's own boot the session's core at its join (`--pair`),
/// or not (its dump loaded instead, the fields that differ said).
@@ -527,11 +529,10 @@ const Client = struct {
stops: @FieldType(replica.Stats, "stops") = @splat(.{}),
/// Its Peer's writer's (`Soak.write`): the batch swapped out of the
/// session's queue for it (the Peers' allocator's), how much of it went
- /// down the link, whether a cut's words end it, a wake asked for room;
- /// how much of the queue carries the soak's clock (`Soak.stamp`).
+ /// down the link, a wake asked for room; how much of the queue carries
+ /// the soak's clock (`Soak.stamp`).
sending: std.ArrayListUnmanaged(u8) = .empty,
at: usize = 0,
- last: bool = false,
draining: bool = false,
marked: usize = 0,
/// The session's unit its last join's dump came after.
@@ -752,14 +753,17 @@ fn describe(buf: []u8, ev: pardes.Event) []const u8 {
} catch "?";
}
-/// Its link ended (it diverged, or it quits): its bye, and its join again
-/// for its view after a divergence (`Link.rejoins`), the core it leaves
-/// held until the dump comes, as `replica.join` holds it.
+/// Its link ended (it diverged, fell behind, was cut off, or it quits):
+/// its join again for its view (`Link.rejoins`), over its link while that
+/// is up (its goodbye and hello said there: runtime/client.zig `run`), the
+/// core it leaves held until the dump comes, as `replica.join` holds it;
+/// else its bye.
fn ended(cl: *Client, c: usize, net: *Net, now: u64, totals: *Totals, run_: Run, typing: *usize) !void {
const r = cl.r.?;
const link = &cl.loop.link;
+ const here = link.backHere() and replica.comeBack(link.fd, "soak", r.view, false);
// Its link ended by the session (a Detach), it says nothing more.
- if (!link.gone) replica.bye(link.fd, .{ .again = r.diverged != null or link.lagged != 0 });
+ if (!here and !link.gone) replica.bye(link.fd, .{ .again = r.diverged != null or link.lagged != 0 });
try drain(cl, c, net, now);
cl.live = 0;
if (link.lagged != 0) {
@@ -775,6 +779,10 @@ fn ended(cl: *Client, c: usize, net: *Net, now: u64, totals: *Totals, run_: Run,
if (link.rejoins()) {
cl.back = r.view;
cl.dialling = true;
+ if (here) {
+ totals.here += 1;
+ return;
+ }
return net.send(.{ .at = net.cross(&net.up[c], c, now, &.{}, 3), .n = 0, .kind = .dial, .who = @intCast(c + 1), .bytes = &.{} });
}
try totals.add(&r.stats);
@@ -1435,10 +1443,8 @@ const Soak = struct {
if (!there) cl.peer = null;
};
// A join taken (its Peer holds the dup handed) or refused (its dup
- // closed, daemon.refuseReplica): its writer's join first (the
- // welcome, then the dump with the session's blobs put back where
- // they go: Peer.writeJoin), its far word read (`far` false: on
- // this machine), and its pins let go at the next boundary.
+ // closed, daemon.refuseReplica): its writer's join first (`joinDown`),
+ // its far word read (`far` false: on this machine).
for (s.clients, 0..) |*cl, c| if (cl.handed >= 0) {
defer cl.handed = -1;
const peer = for (ps.list) |slot| {
@@ -1448,44 +1454,17 @@ const Soak = struct {
try net.toClient(c, now, .refused, cl.gen, &.{});
continue;
};
- const f = (try pardes.wire.framed(peer.welcome[0..peer.welcome_len])) orelse return error.BadWelcome;
- const welcome = (try pardes.wire.decodeServer(f.tag, f.payload)).welcome;
- var whole: std.ArrayListUnmanaged(u8) = .empty;
- errdefer whole.deinit(gpa);
- var pos: usize = 0;
- for (peer.blobs.items) |b| {
- try whole.appendSlice(gpa, peer.dump[pos..b.at]);
- try whole.appendSlice(gpa, b.bytes);
- pos = b.at;
- }
- try whole.appendSlice(gpa, peer.dump[pos..]);
var word: [16]u8 = undefined;
const far = try pardes.wire.encodeClient(&word, .{ .far = false });
_ = peer.take(far[0], far[pardes.wire.header_len..]);
- ps.post(.{ .joined = peer });
- cl.peer = peer;
- cl.shut = false;
- cl.read_done = false;
- cl.join_seq = ps.seq;
- cl.sending.clearRetainingCapacity();
- cl.at = 0;
- cl.last = false;
- cl.marked = 0;
- // What the join cost the session's step (Peers.join's measure).
- s.join_worst = @max(s.join_worst, ps.join_ns);
- try s.totals.join_session_ns.append(gpa, ps.join_ns);
- ps.join_ns = 0;
- cl.gen += 1;
- cl.id = welcome.client;
- cl.view = welcome.view.index();
- cl.digest = welcome.digest;
- s.totals.joins += 1;
- Witness.joined(c, cl, try gpa.dupe(u8, whole.items), cl.join_seq);
- try net.toClient(c, now, .dump, cl.gen, try whole.toOwnedSlice(gpa));
+ try s.joinDown(cl, c, peer);
};
- // A Detach typed in a client's view, or one cut off for its lag: its
- // link shut, it hears its end and nothing after; its reader's end
- // said (the next boundary lets it go).
+ // A join again over a client's own link (Peers.joinAgain): its writer's
+ // next, the stream it leaves let go.
+ for (s.clients, 0..) |*cl, c| if (cl.peer) |peer| if (peer.written != peer.gen) try s.joinDown(cl, c, peer);
+ // A Detach typed in a client's view: its link shut, it hears its end
+ // and nothing after; its reader's end said (the next boundary lets
+ // it go).
if (s.detach_view) |k| for (s.clients) |*cl| if (cl.peer) |p| if (p.view.index() == k and !cl.shut) {
cl.shut = true;
};
@@ -1513,6 +1492,44 @@ const Soak = struct {
s.echo.clearRetainingCapacity();
}
+ /// Client `c`'s Peer's writer's join (Peer.writeJoin): the welcome, then
+ /// the dump with the session's blobs put back where they go, down its
+ /// link, what was queued before it let go; its pins let go at the next
+ /// boundary.
+ fn joinDown(s: *Soak, cl: *Client, c: usize, peer: *replica.Peer) !void {
+ const ps = &s.l.peers;
+ const f = (try pardes.wire.framed(peer.welcome[0..peer.welcome_len])) orelse return error.BadWelcome;
+ const welcome = (try pardes.wire.decodeServer(f.tag, f.payload)).welcome;
+ var whole: std.ArrayListUnmanaged(u8) = .empty;
+ errdefer whole.deinit(gpa);
+ var pos: usize = 0;
+ for (peer.blobs.items) |b| {
+ try whole.appendSlice(gpa, peer.dump[pos..b.at]);
+ try whole.appendSlice(gpa, b.bytes);
+ pos = b.at;
+ }
+ try whole.appendSlice(gpa, peer.dump[pos..]);
+ peer.written = peer.gen;
+ ps.post(.{ .joined = .{ .peer = peer, .gen = peer.gen } });
+ cl.peer = peer;
+ cl.shut = false;
+ cl.read_done = false;
+ cl.join_seq = ps.seq;
+ cl.sending.clearRetainingCapacity();
+ cl.at = 0;
+ cl.marked = 0;
+ // What the join cost the session's step (Peers.join's measure).
+ s.join_worst = @max(s.join_worst, ps.join_ns);
+ try s.totals.join_session_ns.append(gpa, ps.join_ns);
+ ps.join_ns = 0;
+ cl.gen += 1;
+ cl.id = welcome.client;
+ cl.view = welcome.view.index();
+ cl.digest = welcome.digest;
+ s.totals.joins += 1;
+ Witness.joined(c, cl, try gpa.dupe(u8, whole.items), cl.join_seq);
+ try s.net.toClient(c, s.now, .dump, cl.gen, try whole.toOwnedSlice(gpa));
+ }
/// The units the session queued for client `cl` since, their heads
/// carrying the soak's clock, the session's here (its host's `now`):
/// what the client's lag is measured by. Its replica guesses no clock
@@ -1534,7 +1551,7 @@ const Soak = struct {
/// frame a message. The far link takes no more than `throttle_window`
/// ahead of what has crossed: the rest waits in the queue, as it does
/// for a writer blocked on its socket, until room comes (`.drain`). A
- /// cut's words end a batch, and its link after them.
+ /// cut's words are its last until its client's hello again there.
fn write(s: *Soak, cl: *Client, c: usize) !void {
const peer = cl.peer orelse return;
const net = s.net;
@@ -1543,11 +1560,9 @@ const Soak = struct {
if (cl.at == cl.sending.items.len) {
cl.sending.clearRetainingCapacity();
cl.at = 0;
- if (cl.last) return s.shut(cl, c);
const io = s.l.peers.io;
peer.lock.lockUncancelable(io);
std.mem.swap(std.ArrayListUnmanaged(u8), &peer.out, &cl.sending);
- cl.last = peer.cut;
peer.lock.unlock(io);
cl.marked = 0;
if (cl.sending.items.len == 0) return;
@@ -1590,11 +1605,10 @@ const Soak = struct {
}
/// Client `c`'s link ended at the session's side (a Detach typed in its
- /// view, or the words of a cut sent): it hears its end and nothing after,
- /// and its reader's end is said (the next boundary lets it go).
+ /// view): it hears its end and nothing after, and its reader's end is
+ /// said (the next boundary lets it go).
fn shut(s: *Soak, cl: *Client, c: usize) !void {
cl.shut = true;
- cl.last = false;
if (cl.read_done) return;
cl.read_done = true;
s.l.peers.post(.{ .gone = cl.peer.? });
@@ -3400,7 +3414,7 @@ pub fn main(init: std.process.Init) !void {
try stop_lines.print(gpa, "{d:>4} {d:>8} {d:>6} {d:>6} {d:>3}/{d}/{d} ", .{ rtt, t.unlisted, t.wakes, t.draws, t.asked[0], t.asked[1], t.asked[2] });
for (t.stops) |st| if (st.n > 0) try stop_lines.print(gpa, "{s}:{d} ", .{ st.name, st.n });
try stop_lines.append(gpa, '\n');
- try join_lines.print(gpa, "{d:>4} {d:>5} {d:>7} {d:>8} {d:>8} {d:>6} {d:>5}/{d:<5} {d:>5}/{d:<6} {d:>7} {d:>5}/{d}/{d}\n", .{ rtt, t.joins, t.refused, t.rejoined, t.detached, t.detach_words, t.agree, t.differ, t.checks, t.units, t.resizes, t.kind_panes[0], t.kind_panes[1], t.kind_panes[2] });
+ try join_lines.print(gpa, "{d:>4} {d:>5} {d:>4} {d:>7} {d:>8} {d:>8} {d:>6} {d:>5}/{d:<5} {d:>5}/{d:<6} {d:>7} {d:>5}/{d}/{d}\n", .{ rtt, t.joins, t.here, t.refused, t.rejoined, t.detached, t.detach_words, t.agree, t.differ, t.checks, t.units, t.resizes, t.kind_panes[0], t.kind_panes[1], t.kind_panes[2] });
try far_lines.print(gpa, "{d:>4} {d:>5} {d:>4} {d:>6.1}/{d:<6.1} {d:>6.1}/{d:<6.1} {d:>8} {d:>3} {d:>6.1}/{d:<6.1} {d:>6.1}/{d:<6.1} ({d}) {d:>6.0}/{d:<6.0} {d}\n", .{
rtt, t.far_joins, t.far_lags,
secs(pct(t.far_gaps.items, 50)), secs(pct(t.far_gaps.items, 100)),
@@ -3419,8 +3433,8 @@ pub fn main(init: std.process.Init) !void {
}
std.debug.print("terminals: a peer's unit bytes a second under the flood (the pty's bytes ride in them); KB of units sent to the peers in all\n", .{});
std.debug.print(" rtt unit B/s units KB\n{s}", .{term_lines.items});
- std.debug.print("clients: joins from a dump, refused (every view taken), joined again after a divergence put on them, left (of them by a Detach); quiet checks of the session's digest agreed/differed; the digests the clients compared (units and quiet), of the units they took; resizes the windows posted; the kinds' panes the session opened (image/life/pdf)\n", .{});
- std.debug.print(" rtt joins refused rejoined detached detach agree/differ checks/units resizes kinds\n{s}", .{join_lines.items});
+ std.debug.print("clients: joins from a dump (here: of them again over the client's own link, no dial), refused (every view taken), joined again after a divergence put on them, left (of them by a Detach); quiet checks of the session's digest agreed/differed; the digests the clients compared (units and quiet), of the units they took; resizes the windows posted; the kinds' panes the session opened (image/life/pdf)\n", .{});
+ std.debug.print(" rtt joins here refused rejoined detached detach agree/differ checks/units resizes kinds\n{s}", .{join_lines.items});
std.debug.print("stops: the wakes the clients' loops asked, the frames they drew, the yanks, pastes and links their frontends did (y/p/l), and what stopped their inputs (a stop counted again as its input is applied again), by name; those at a name replica.may_wait does not list fail the run\n", .{});
std.debug.print(" rtt unlisted wakes draws y/p/l stops\n{s}", .{stop_lines.items});
std.debug.print("far: the third client's link 1 Mbit/s and 200 ms each way (zstd's bytes): its joins from a dump, of them for its lag (Link.behind past replica.behind_max_ms), s between two from the flood's start (p50/max), s from the flood's end to its final screen (p50/max: a run that never shows it fails), the session's queue for it at most, clients cut off; a join's cost to the replicas there before it, ms on this process's clock (p50/max): the session's step (reloads and dump), a client's unit (reloads), how many; ms behind the session at most (Link.behind), the far client and the others, and the others' joins for it (0, or the run fails)\n", .{});