diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/replica.zig | 16 | ||||
| -rw-r--r-- | src/tape.zig | 32 |
2 files changed, 17 insertions, 31 deletions
diff --git a/src/replica.zig b/src/replica.zig index 4a93ec3d..5c46f5c2 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -207,8 +207,8 @@ pub const Authority = struct { a.out.clearRetainingCapacity(); try a.out.appendNTimes(a.gpa, 0, unit_head); unitHeader(a.out.items, origin, seq); - try a.out.appendSlice(a.gpa, tape.taken(&a.t)); - tape.clearTaken(&a.t); + try a.out.appendSlice(a.gpa, a.t.buf.items); + a.t.buf.clearRetainingCapacity(); return a.out.items; } @@ -799,7 +799,7 @@ pub const Replica = struct { // derived field's) shows here, at the input that did it, // not at some later unit replayed. if (lastDigest(u.tape)) |d| { - tape.checkDigest(&r.t, d); + r.t.check(d); if (r.t.diverged) |why| { trace(r.gpa, "replica {d}: its input {d} came to another state than the session's: {s}\n", .{ r.id, u.seq, why }, &.{u.tape}); return r.fail(why); @@ -979,8 +979,8 @@ pub const Replica = struct { } r.stats.speculated += 1; if (r.stats.samples) r.stats.spec_ns.append(r.gpa, dt) catch {}; - p.spec = r.gpa.dupe(u8, tape.taken(&r.t)) catch return false; - tape.clearTaken(&r.t); + p.spec = r.gpa.dupe(u8, r.t.buf.items) catch return false; + r.t.buf.clearRetainingCapacity(); r.applied += 1; return true; } @@ -1779,14 +1779,14 @@ pub const Peers = struct { /// What was recorded since the last unit, to every client as one, its /// digest at its end. fn unit(ps: *Peers, origin: u16, seq: u32) void { - if (tape.taken(&ps.t).len == 0) return; + if (ps.t.buf.items.len == 0) return; tape.recordDigest(&ps.t); - const bytes = tape.taken(&ps.t); + const bytes = ps.t.buf.items; unitHeader(&ps.head, origin, seq); trace(ps.gpa, "session: unit {d}/{d}, {d} bytes, to {d} clients:\n", .{ origin, seq, bytes.len, ps.count() }, &.{bytes}); const head = wire.header(@backingInt(wire.ServerTag.unit), unit_head + bytes.len); for (ps.list) |slot| if (slot) |peer| peer.send(&.{ &head, &ps.head, bytes }); - tape.clearTaken(&ps.t); + ps.t.buf.clearRetainingCapacity(); // The sizes its steps gave terminals, now: the next flush says so. if (ps.t.core) |core| terminal.resizeDeferred(core); } diff --git a/src/tape.zig b/src/tape.zig index 3774261c..ced8b9bf 100644 --- a/src/tape.zig +++ b/src/tape.zig @@ -403,7 +403,7 @@ pub const Tape = struct { .input => t.apply(&rec.payload), .set => t.applySet(&rec.payload), .host => t.skipHost(), - .digest => t.check(&rec.payload), + .digest => t.check(rec.payload.bytes), .done => return t.diverge("a host call's records are out of order", .{}), } } @@ -435,7 +435,7 @@ pub const Tape = struct { .set => t.applySet(&rec.payload), .host => if (t.headless) t.skipHost() else return t.diverge("the core did not make the host call {d} the tape has", .{std.mem.bytesToValue(u16, rec.payload.bytes[0..2])}), .input => t.apply(&rec.payload), - .digest => t.check(&rec.payload), + .digest => t.check(rec.payload.bytes), .ret => return t.diverge("the core's input ended before the recorded one", .{}), } } @@ -456,7 +456,7 @@ pub const Tape = struct { }, .input => t.apply(&rec.payload), .set => t.applySet(&rec.payload), - .digest => t.check(&rec.payload), + .digest => t.check(rec.payload.bytes), .host, .done => { t.diverge("a host call's records are out of order", .{}); return false; @@ -483,9 +483,11 @@ pub const Tape = struct { return t.finishHost(); } - /// A recorded digest against the replica's own. - fn check(t: *Tape, r: *walk.Reader) void { - const want = walk.decode([]const u64, r, t.arena.allocator()) catch return; + /// A digest record's payload (a unit's last) against the core's own: a + /// difference is `diverged`, its fields named when the record has them. + pub fn check(t: *Tape, payload: []const u8) void { + var r: walk.Reader = .{ .bytes = payload }; + const want = walk.decode([]const u64, &r, t.arena.allocator()) catch return; const p = t.core orelse return; var parts: Parts = undefined; const whole = [1]u64{digestOf(p)}; @@ -954,13 +956,6 @@ pub fn recordDigest(t: *Tape) void { t.record(.digest, []const u64, &d); } -/// The core's digest against a digest record's payload (a unit's last): a -/// difference is `diverged`, its fields named when the record has them. -pub fn checkDigest(t: *Tape, payload: []const u8) void { - var r: walk.Reader = .{ .bytes = payload }; - t.check(&r); -} - /// A core made outside the tape (a replica client's, from a dump) is the /// one it replays into. pub fn adoptCore(t: *Tape, p: *Pardes) void { @@ -1094,15 +1089,6 @@ pub fn release(t: *Tape) void { if (t.kept_arena) |*k| k.deinit(); } -/// What was recorded since the last take; the tape's to reuse after. -pub fn taken(t: *Tape) []const u8 { - return t.buf.items; -} - -pub fn clearTaken(t: *Tape) void { - t.buf.clearRetainingCapacity(); -} - /// The records of `bytes`, top-level inputs and all, applied to the /// tape's core as the authority applied them, each digest checked; why /// they diverged, or null. @@ -1120,7 +1106,7 @@ pub fn replayUnit(t: *Tape, bytes: []const u8) ?[]const u8 { _ = t.arena.reset(.retain_capacity); }, .set => t.applySet(&rec.payload), - .digest => t.check(&rec.payload), + .digest => t.check(rec.payload.bytes), .host, .ret, .done => t.diverge("a {t} record at the top", .{kind}), } } |
