diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 14:11:56 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 19:16:19 -0300 |
| commit | 4e096f6dc6db043caa630514fa75bd18438cb15b (patch) | |
| tree | 2628101ed3a7e432030918b019935e47240b1c64 /src/pardes.zig | |
| parent | 38d21b0cb34ef1f555e5bda8155150bda9bfbaee (diff) | |
| download | pardes-4e096f6dc6db043caa630514fa75bd18438cb15b.tar.gz pardes-4e096f6dc6db043caa630514fa75bd18438cb15b.zip | |
store: Recent is a value of the user's state file, `pardes.xitdb` in the DumpDir (src/Db.zig: the xitdb database the architecture's §14 puts everything pardes keeps on disk in), which every session shares: read at a session's start (now after the startup config, whose DumpDir says where the file is) and again on use when the file's committed size has moved, written at the end of a step that changed it in one transaction under the file's lock, taken without waiting (busy, the next step tries again), another session's commit read and merged under this one's changes first; not fsynced, as the `recent` file was not (a xitdb commit costs 20 us without fsync and 5.2 ms with its two on this btrfs); a file there that is no database of pardes's is kept aside as `pardes.xitdb.broken` and a new one started; Store.zig keeps the closed panes alone (its file half goes: the path and its inode/size/mtime stamp, load, refresh, read, flush and write, and W4's one-time read of the old `store`, which comes back with the migration), Options.recent_path becomes Options.state (off, disk, memory), main.recentPath goes, a Restore's new core takes the old one's database, and the test host's sessions keep theirs in a `.memory` database, the same code; measured (Debug, 200 files listed): flush after an open 133-135 us (W4's file: 124), refresh after another session's write 239-247 us (198), refresh with nothing new 3 us (1), a session started on it 1144-1194 us (1214), and a Recent change adds 12,325 bytes to the file (its 12,089 bytes of lines and 236 of xitdb's); tests: Store.zig's four Recent tests become Db.zig's three (two windows sharing Recent through a busy lock, the newest 200, a file that is no database kept aside; the old store's migration test goes with that read), the closed-pane test keeps its second window on a state file in its DumpDir, the behaviour suite gains 'two sessions on one state file share Recent', and the process tests and the canary look for the state file where they looked for `recent`
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/pardes.zig')
| -rw-r--r-- | src/pardes.zig | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/src/pardes.zig b/src/pardes.zig index 16dd794e..b42bf643 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -19,6 +19,7 @@ pub const tagline = @import("tagline.zig"); pub const exec = @import("exec.zig"); const recent_files = @import("recent.zig"); const Store = @import("Store.zig"); +const Db = @import("Db.zig"); pub const mouse = @import("mouse.zig"); pub const normal = @import("normal.zig"); pub const edit = @import("edit.zig"); @@ -449,6 +450,7 @@ test { _ = @import("upgrade.zig"); _ = @import("recent.zig"); _ = @import("Store.zig"); + _ = @import("Db.zig"); _ = @import("pager.zig"); _ = @import("Places.zig"); _ = @import("FrameStats.zig"); @@ -3223,10 +3225,10 @@ pub const Options = struct { ninep_tcp: ?[]const u8 = null, mounts: []const filesystem.Mount = &.{}, config_dir: ?[]const u8 = null, - /// Recent's file, which every session of the user's shares (Store.zig). - /// Set by the host that has a state directory; none, Recent lasts as - /// long as the session. - recent_path: ?[]const u8 = null, + /// Where what outlives the session is kept (Db.zig): the user's state + /// file, set by a host that has one; none, Recent lasts as long as the + /// session; memory, the test host's. + state: Db.Kind = .off, startup_config_path: ?[]const u8 = null, image_allocator: ?std.mem.Allocator = null, pdf_allocator: ?std.mem.Allocator = null, @@ -3303,9 +3305,10 @@ pub const Pardes = struct { /// The files opened lately, closed ones too (recent.zig): `Recent`, /// /recent, and the jumplist's way back to a closed pane. recent: recent_files.List = .{}, - /// Recent's file, shared with every other session, and the panes this - /// session closed, which Panes brings back (Store.zig). + /// The panes this session closed, which Panes brings back (Store.zig). store: Store = .{}, + /// The user's state file, which every session shares: Recent's (Db.zig). + db: Db = .{}, /// acme's Incl: the directories a look at a name that is nowhere else /// (`stdio.h`, `<foo.h>`) is tried in, in order. The session's, seeded /// with C's (/usr/include, /usr/local/include), kept in a dump. @@ -3602,11 +3605,11 @@ pub const Pardes = struct { "opts", "dump_out", }, .derived = .{ "shell_rows", "diff_output", "locations_cache", "retired_panes", "tty_filter_palette", "body_chrome" }, - // The host's handles, the 9P server's fids and log, Recent's file - // every session of the user shares (and Recent read from it) with - // this session's closed panes, and the files of a host with no file + // The host's handles, the 9P server's fids and log, the state file + // every session of the user shares (and Recent read from it), this + // session's closed panes, and the files of a host with no file // system of its own. - .authority = .{ "host", "fs", "store", "recent", "fallback" }, + .authority = .{ "host", "fs", "store", "recent", "db", "fallback" }, .len = .{ .{ "jumps", "njumps" }, .{ "look_src", "n_look_src" }, .{ "leader_keys", "leader_n" }, .{ "col_x", "ncol" }, .{ "col_w", "ncol" }, .{ "session_dir", "session_dir_len" } }, }; @@ -3644,6 +3647,7 @@ pub const Pardes = struct { .scratch = .init(gpa), .frame_arena = .init(opts.frame_allocator orelse gpa), .fallback = .{ .gpa = gpa }, + .db = .{ .kind = opts.state }, }; errdefer p.deinit(); p.fs.started = ctlfs.events.now(); @@ -3759,7 +3763,6 @@ pub const Pardes = struct { }, } p.sync(); - p.loadRecent(); for (config.default_incl) |dir| { const copy = try gpa.dupe(u8, dir); p.incl.append(gpa, copy) catch |err| { @@ -3768,6 +3771,8 @@ pub const Pardes = struct { }; } exec.applyStartupConfig(p); + // After the startup config, whose DumpDir says where the state file is. + p.loadRecent(); colors.finishThemeInitialization(p); p.sync(); // A config init that opens a file with `Look …` armed the pulse before @@ -3795,17 +3800,17 @@ pub const Pardes = struct { return std.heap.smp_allocator; } - /// Recent's file read once at start: a new session's. + /// Recent read from the state file once at start: a new session's. pub fn loadRecent(p: *Pardes) void { - // A replica's store is its own, in memory: the recording session's - // file is every session's of its user (src/tape.zig). - p.store = .{ .path = if (tape.replaying()) null else p.opts.recent_path }; - p.store.load(p); + // A replica's Recent is its own, in memory: the recording session's + // state file is every session's of its user (src/tape.zig). + if (tape.replaying()) p.db.kind = .off; + p.db.readRecent(p); } /// What changed written out, at the end of a step and at the end. pub fn saveRecent(p: *Pardes) void { - p.store.flush(p, false); + p.db.writeRecent(p, false); } /// Whether `path` is one Recent keeps: a file on this host's disk, not @@ -3817,7 +3822,7 @@ pub const Pardes = struct { /// A file, PDF or image pane closing: its place noted in Recent, when /// Recent keeps it. - fn noteClosed(p: *Pardes, pane: *const Pane) void { + pub fn noteClosed(p: *Pardes, pane: *const Pane) void { const d = recentPlace(pane) orelse return; // The host asked first, always: what Recent holds is the // authority's, and a step that asked only when it did not know the @@ -3900,7 +3905,8 @@ pub const Pardes = struct { if (std.c.getenv("PARDES_FRAMES")) |path| p.frames.dump(std.mem.span(path)); // Every file open now is closed with its dot, and the list kept. for (p.panes) |slot| if (slot) |pane| p.noteClosed(pane); - p.store.flush(p, true); + p.db.writeRecent(p, true); + p.db.deinit(); p.store.deinit(p.recentGpa()); p.recent.deinit(p.recentGpa()); for (p.incl.items) |dir| p.gpa.free(dir); |
