diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-30 02:01:30 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-30 03:13:15 -0300 |
| commit | f8a56c962d5103b84453d4305cd27973a71d4aa3 (patch) | |
| tree | 95da95264b53fab6637808bd62410f7740b2880c /src/replica.zig | |
| parent | 6118ad214bb74744e7b38004b34e4487a6635be1 (diff) | |
| download | pardes-f8a56c962d5103b84453d4305cd27973a71d4aa3.tar.gz pardes-f8a56c962d5103b84453d4305cd27973a71d4aa3.zip | |
replica clients join again: one that diverged (a digest the session's unit did not end on) and one the session let go to upgrade dial it again, the same join as the first, and say why in a line over their frame until a key; a client of another build is told "session upgraded to a newer pardes: upgrade this client too"
tty.zig `remote` is a loop of joins over one terminal: the link ended, its reader joined, the replica let go, the session dialled again (an upgrade's exec and load, and its daemon's, retried for 20 s), its dump loaded, its view's size sent again. `Remote.notify` draws the line (`noticeLine`, the client's own, never the session's core).
The welcome carries the session's semantics: the daemon judged the hello by the hash it last heard, which an upgrade under way may not have said yet.
replica.zig `Peers.refuseAll`: before an Upgrade's dump each client is sent `refused` after what it was sent (up to 200 ms) and let go, its view with it.
"A newer pardes is installed" is a Host call (`newer_build`) the core makes in its focus step, so replica clients take the line from the tape; the GUI still says it itself.
PARDES_TEST_DIVERGE=<n> puts a client's core off the session's once quiet after its n-th unit. test/daemon.py: the clients test has one rejoin and agree; the upgrade test has a client of the old build told to upgrade and one of the build running join again and agree.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/replica.zig')
| -rw-r--r-- | src/replica.zig | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/replica.zig b/src/replica.zig index 7bf0574f..95135307 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -1140,6 +1140,8 @@ pub const Peer = struct { limit: usize = 64 << 20, closing: bool = false, cut: bool = false, + /// Its writer has ended (what it was sent, written). + done: std.atomic.Value(bool) = .init(false), /// `parts` queued for it, in order; never waits. A client whose queue /// passes its limit is cut off: its link is shut down, and its reader @@ -1169,6 +1171,7 @@ pub const Peer = struct { fn writeLoop(peer: *Peer) void { const io = peer.peers.io; + defer peer.done.store(true, .release); while (true) { peer.lock.lockUncancelable(io); while (peer.out.items.len == 0 and !peer.closing and !peer.cut) peer.cond.waitUncancelable(io, &peer.lock); @@ -1457,7 +1460,7 @@ pub const Peers = struct { var out: [wire.hello_max + 64]u8 = undefined; // The session's digest as dumped, for the joiner to check its load by. const digest = tape.digestOf(core); - const welcome = wire.encodeServer(&out, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = k, .dump_len = bytes.len, .gmtoff = gmtoff(), .digest = digest } }) catch unreachable; + const welcome = wire.encodeServer(&out, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = k, .dump_len = bytes.len, .gmtoff = gmtoff(), .digest = digest, .semantics = wire.semantics } }) catch unreachable; peer.send(&.{welcome}); var at: usize = 0; while (at < bytes.len) : (at += dump_piece) { @@ -1535,6 +1538,33 @@ pub const Peers = struct { ps.gpa.destroy(peer); } + /// Every client told `why` and let go, its view with it: an Upgrade's + /// exec is next (tty.zig `upgradeNow`). What each was sent goes first, + /// for up to 200 ms; a client then dials the session again. + pub fn refuseAll(ps: *Peers, core: *Pardes, why: []const u8) void { + if (ps.count() == 0) return; + var out: [600]u8 = undefined; + const words = wire.encodeServer(&out, .{ .refused = why }) catch return; + const io = ps.io; + for (ps.list) |slot| if (slot) |peer| { + peer.send(&.{words}); + peer.lock.lockUncancelable(io); + peer.closing = true; + peer.cond.signal(io); + peer.lock.unlock(io); + }; + const until = nowNs() + 200 * std.time.ns_per_ms; + while (nowNs() < until) { + const busy = for (ps.list) |slot| { + if (slot) |peer| if (!peer.done.load(.acquire)) break true; + } else false; + if (!busy) break; + const ts: libc.timespec = .{ .sec = 0, .nsec = 2 * std.time.ns_per_ms }; + _ = libc.nanosleep(&ts, null); + } + ps.dropAll(core); + } + /// Detach typed in client view `k`'s: its link ends (its reader says /// it is gone, and the next boundary lets it go). pub fn detach(ps: *Peers, k: u8) bool { @@ -1612,6 +1642,9 @@ pub const Joined = struct { dump: []u8, /// The session's digest as dumped (`Replica.loaded`). digest: u64 = 0, + /// Its build's (wire.semantics): the daemon judged the hello by what it + /// last heard, which an upgrade under way may not have said yet. + semantics: u64 = 0, /// What was read past the dump: the stream's (`readStream`). rest: Framer = .{}, }; @@ -1657,6 +1690,7 @@ pub fn dial(gpa: Allocator, path: []const u8, session: []const u8, why: []u8) ?J r.j.view = w.view; r.j.gmtoff = w.gmtoff; r.j.digest = w.digest; + r.j.semantics = w.semantics; r.j.dump = r.gpa.alloc(u8, @intCast(w.dump_len)) catch { r.failed = "out of memory for the session's dump"; return false; |
