summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/replica.zig31
-rw-r--r--core/rollback.zig16
2 files changed, 43 insertions, 4 deletions
diff --git a/core/replica.zig b/core/replica.zig
index 4ba08849..c895618d 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -7124,6 +7124,37 @@ test "a 9P open the session made over a copy taken ahead, replayed after a rollb
try agrees(a, r);
}
+test "a script's half line held over a copy taken ahead, its next write run and its rest moved to the front in place, put back by a rollback: the line replayed is the session's" {
+ var n = try NinepJoin.init("one\n", TestHost.host());
+ defer n.deinit();
+ try n.join();
+ const r = n.late.?;
+ const exec = n.node(.exec);
+ const h = (try n.serve(.{ .tag = 1, .op = .open, .node = exec, .omode = 1 }, true)).handle;
+ _ = try n.serve(.{ .tag = 2, .op = .write, .node = exec, .handle = h, .data = "Ta" }, true);
+ r.ready();
+ // Replayed over the copy and kept: `Tab 8` runs, `Un` is held where
+ // `Ta` was, in the buffer the copy holds.
+ _ = try n.serve(.{ .tag = 3, .op = .write, .node = exec, .handle = h, .data = "b 8\nUn" }, true);
+ try std.testing.expect(r.copy.held and r.since.items.len > 0);
+ var sent: std.ArrayListUnmanaged([]u8) = .empty;
+ defer {
+ for (sent.items) |m| std.testing.allocator.free(m);
+ sent.deinit(std.testing.allocator);
+ }
+ try key(r, 'l', &sent);
+ try std.testing.expectEqual(@as(usize, 1), r.applied);
+ // The session's key first: a rollback, the write replayed again.
+ try n.send(try n.a.local(.{ .key = .{ .cp = 'j', .text = "j" } }));
+ try std.testing.expect(r.stats.foreign > 0);
+ try n.send(try n.a.take(sent.items[0]));
+ _ = try n.serve(.{ .tag = 4, .op = .write, .node = exec, .handle = h, .data = "do\n" }, true);
+ _ = try n.serve(.{ .tag = 5, .op = .release, .node = exec, .handle = h, .opened = true }, true);
+ if (r.diverged) |why| std.debug.print("diverged: {s}\n", .{why});
+ try std.testing.expect(r.diverged == null and r.quiet());
+ try n.agree();
+}
+
// Del with a pane above and below asks which way the space goes, its
// question shown once a delay is up (builtins.zig): its time was the
// host's clock read in the step, an answering entry a speculation stops at.
diff --git a/core/rollback.zig b/core/rollback.zig
index c7d0a4e8..a55d3c87 100644
--- a/core/rollback.zig
+++ b/core/rollback.zig
@@ -404,9 +404,7 @@ pub const Copy = struct {
},
.@"struct" => |s| {
if (comptime walk.machinery(T)) return;
- // A terminal: the authority's (its emulator is never written
- // by a speculation: terminal.zig's guards).
- if (comptime @hasDecl(T, "digest") and @TypeOf(T.digest) == fn (*const T, *walk.Hasher) void) return;
+ if (comptime unwalked(T)) return;
if (s.layout == .@"packed") return;
// std's lists (a safe build's have a third field, a lock).
if (comptime walk.isList(T)) {
@@ -467,7 +465,7 @@ pub const Copy = struct {
if (comptime walk.machinery(P)) return;
const addr = @intFromPtr(ptr);
if (try c.reached(P, addr)) return;
- if (comptime @hasDecl(P, "digest") and @TypeOf(P.digest) == fn (*const P, *walk.Hasher) void) return;
+ if (comptime unwalked(P)) return;
if (c.epoch.?.owns(addr) != null) {
_ = try c.reached(void, addr);
try c.fields(P, ptr);
@@ -513,6 +511,16 @@ pub const Copy = struct {
}
};
+/// A type that hashes itself and says nothing of its fields (`replica`):
+/// a terminal, the authority's (its emulator is never written by a
+/// speculation: terminal.zig's guards), or a location row, made again and
+/// never written. One that says its fields' kinds is walked by them,
+/// whatever digest it has (the 9P state, fs.Namespace and a pane's: a
+/// replayed request writes its buffers in place).
+fn unwalked(comptime T: type) bool {
+ return @hasDecl(T, "digest") and @TypeOf(T.digest) == fn (*const T, *walk.Hasher) void and !@hasDecl(T, "replica");
+}
+
fn annotatedStruct(comptime T: type) bool {
return @typeInfo(T) == .@"struct" and @hasDecl(T, "replica");
}