summaryrefslogtreecommitdiff
path: root/src/rollback.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-29 20:56:03 -0300
committerGabriel Schneider <[email protected]>2026-10-30 03:13:15 -0300
commitfdf74e199de7d0fc648f912875323f3dc920ffc2 (patch)
tree7e175c6fc9cb653200ff2abb7bcc5cf0fda3dc9f /src/rollback.zig
parent57aa8d2f9ae851fa9806abbd1fd04abf1fd2b57f (diff)
downloadpardes-fdf74e199de7d0fc648f912875323f3dc920ffc2.tar.gz
pardes-fdf74e199de7d0fc648f912875323f3dc920ffc2.zip
replica clients over a socket: the session streams each its dump and every unit after it (replica.zig `Peers`, a writer and a reader thread a client, units at each step boundary, a client's input stepped there in its own view), and `pardes --attach=<socket>:<name>` and `--attach=<host>:<name>` (through `ssh -tt -L`) are a client in the tty host, its keys applied at once by its own replica and drawn by its own process
wire.zig version 15: welcome (the client's id and view, the dump's length, the session's UTC offset and digest), dump pieces, units (with the authority's clocks), terminal messages both ways, a check. A unit carries one digest, at its end (`unit_digests`). The client: tty.zig `Shell.remote`, `feed` (a terminal's input to the replica and the session); the session's clock guessed from the last unit's (tape.zig `Guess`); a pump woken only by a client's post reads no new time (`mail_only`), and a unit of another's ending where the last ended leaves the speculation as it is (`neutral`); the rollback copy taken while idle (`Replica.ready`); views a frontend here does not draw left undrawn. A lagging client never holds the session: its queue is cut off past 64 MiB (PARDES_REPLICA_LAG_KB). Detach in a client ends that client; a Restore lets every client go. daemon.zig: a replica the daemon hands over is the session's loop's (a note), not a stub thread's. A window session refuses one in words. test/daemon.py `--clients`: two clients (one through the delay relay) type into a detached session and agree with it, one killed outright, one detached, a third typing into a shell. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/rollback.zig')
-rw-r--r--src/rollback.zig23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/rollback.zig b/src/rollback.zig
index 7216664c..b0394d22 100644
--- a/src/rollback.zig
+++ b/src/rollback.zig
@@ -40,11 +40,22 @@ const Pardes = pardes.Pardes;
const blob_min = 4096;
const checked = builtin.mode == .debug or builtin.mode == .safe;
+/// An address as a hash map's key: a multiply, not a Wyhash of its bytes
+/// (every allocation of a replica's core is a lookup).
+const Addr = struct {
+ pub fn hash(_: Addr, a: usize) u64 {
+ return @as(u64, a) *% 0x9e3779b97f4a7c15;
+ }
+ pub fn eql(_: Addr, a: usize, b: usize) bool {
+ return a == b;
+ }
+};
+
pub const Epoch = struct {
child: Allocator = std.heap.c_allocator,
/// Its own bookkeeping, never the epoch's.
meta: Allocator = std.heap.c_allocator,
- live: std.AutoHashMapUnmanaged(usize, Entry) = .empty,
+ live: std.HashMapUnmanaged(usize, Entry, Addr, std.hash_map.default_max_load_percentage) = .empty,
on: bool = false,
id: u32 = 0,
born: std.ArrayListUnmanaged(usize) = .empty,
@@ -190,7 +201,7 @@ pub const Copy = struct {
meta: Allocator = std.heap.c_allocator,
regions: std.ArrayListUnmanaged(Region) = .empty,
bytes: std.ArrayListUnmanaged(u8) = .empty,
- seen: std.AutoHashMapUnmanaged(Seen, void) = .empty,
+ seen: std.HashMapUnmanaged(Seen, void, SeenContext, std.hash_map.default_max_load_percentage) = .empty,
pins: std.ArrayListUnmanaged(Pin) = .empty,
held: bool = false,
epoch: ?*Epoch = null,
@@ -202,6 +213,14 @@ pub const Copy = struct {
const Region = struct { addr: usize, off: usize, len: usize };
const Pin = struct { addr: usize, len: usize, hash: u64, where: []const u8 };
const Seen = struct { addr: usize, ty: usize };
+ const SeenContext = struct {
+ pub fn hash(_: SeenContext, k: Seen) u64 {
+ return (@as(u64, k.addr) *% 0x9e3779b97f4a7c15) ^ (@as(u64, k.ty) *% 0xc2b2ae3d27d4eb4f);
+ }
+ pub fn eql(_: SeenContext, a: Seen, b: Seen) bool {
+ return a.addr == b.addr and a.ty == b.ty;
+ }
+ };
pub const Error = Allocator.Error;
pub fn deinit(c: *Copy) void {