╭ changed ────╮ │src/event.zig│ ╰─────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1928 pub fn CommitIterator(comptime repo_kind: rp.RepoKind, comptime repo_opts: rp.RepoOpts(repo_kind)) type {│ │1929 return struct { │ │1930 const DB = EventDB(repo_opts.hash); │ │1931 + // a plain file is used for the scratch db because each write outside │ │1932 + // a transaction is synced anyway, so buffering would gain nothing │ │1933 + const TempDB = xit.xitdb.Database(.file, hash.HashInt(repo_opts.hash)); │ │1934 const db_name = "haxy-repo-events.db"; │ │1935 │ │1936 repo_dir: std.Io.Dir, │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────╮ │1937 db_file: std.Io.File, │ │1935 - db: *DB, │ │1938 + db: *TempDB, │ │1939 // map of each object id to its children │ │1937 - parent_to_children: DB.HashMap(.read_write), │ │1940 + parent_to_children: TempDB.HashMap(.read_write), │ │1941 // tracking pending parents is necessary because a child can only │ │1942 // be returned after all of its unconsumed parents have been returned│ │1940 - child_to_pending_parents: DB.HashMap(.read_write), │ │1943 + child_to_pending_parents: TempDB.HashMap(.read_write), │ │1944 // queue of object ids that are ready to be returned from `next` │ │1942 - ready_queue: DB.ArrayList(.read_write), │ │1945 + ready_queue: TempDB.ArrayList(.read_write), │ │1946 ready_queue_index: u64, │ │1947 // the object id at the tip of this branch │ │1948 newest_object_id: ?[hash.byteLen(repo_opts.hash)]u8, │ ╰───────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────╮ │1961 db_file.close(io); │ │1962 state.core.repo_dir.deleteFile(io, db_name) catch {}; │ │1963 } │ │1961 - │ │1962 - const buffer_ptr = try allocator.create(std.Io.Writer.Allocating);│ │1963 - errdefer allocator.destroy(buffer_ptr); │ │1964 │ │1965 - buffer_ptr.* = std.Io.Writer.Allocating.init(allocator); │ │1966 - errdefer buffer_ptr.deinit(); │ │1967 - │ │1968 - const db_ptr = try allocator.create(DB); │ │1965 + // cursors point at the db, so it needs a stable address │ │1966 + const db_ptr = try allocator.create(TempDB); │ │1967 errdefer allocator.destroy(db_ptr); │ │1968 // the db is scratch state that gets deleted after iteration, so │ │1969 // there is nothing worth fsyncing │ ╰────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1972 - db_ptr.* = try DB.init(.{ .io = io, .file = db_file, .buffer = buffer_ptr, .fsync = false }); │ │1970 + db_ptr.* = try TempDB.init(.{ .io = io, .file = db_file, .fsync = false }); │ │1971 │ │1974 - const map = try DB.HashMap(.read_write).init(db_ptr.rootCursor()); │ │1972 + const map = try TempDB.HashMap(.read_write).init(db_ptr.rootCursor()); │ │1973 │ │1974 const parent_to_children_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "parent->children")); │ │1977 - const parent_to_children = try DB.HashMap(.read_write).init(parent_to_children_cursor); │ │1975 + const parent_to_children = try TempDB.HashMap(.read_write).init(parent_to_children_cursor); │ │1976 │ │1977 const child_to_pending_parents_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "child->pending-parents"));│ │1980 - const child_to_pending_parents = try DB.HashMap(.read_write).init(child_to_pending_parents_cursor); │ │1978 + const child_to_pending_parents = try TempDB.HashMap(.read_write).init(child_to_pending_parents_cursor); │ │1979 │ │1980 const ready_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "ready-queue")); │ │1983 - const ready_queue = try DB.ArrayList(.read_write).init(ready_queue_cursor); │ │1981 + const ready_queue = try TempDB.ArrayList(.read_write).init(ready_queue_cursor); │ │1982 │ │1983 var self = CommitIterator(repo_kind, repo_opts){ │ │1984 .repo_dir = state.core.repo_dir, │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │2000 │ │2001 pub fn deinit(self: *CommitIterator(repo_kind, repo_opts), io: std.Io, allocator: std.mem.Allocator) void {│ │2002 self.db_file.close(io); │ │2005 - self.db.core.memory.buffer.deinit(); │ │2006 - allocator.destroy(self.db.core.memory.buffer); │ │2003 self.repo_dir.deleteFile(io, db_name) catch {}; │ │2004 allocator.destroy(self.db); │ │2005 } │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │2022 consumed_object_ids: DB.HashMap(.read_only), │ │2023 ref: rf.Ref, │ │2024 ) !void { │ │2029 - const map = try DB.HashMap(.read_write).init(self.db.rootCursor()); │ │2025 + const map = try TempDB.HashMap(.read_write).init(self.db.rootCursor()); │ │2026 │ │2027 const walk_queue_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "walk-queue")); │ │2032 - const walk_queue = try DB.ArrayList(.read_write).init(walk_queue_cursor); │ │2028 + const walk_queue = try TempDB.ArrayList(.read_write).init(walk_queue_cursor); │ │2029 var walk_queue_index: u64 = 0; │ │2030 │ │2031 const seen_object_ids_cursor = try map.putCursor(hash.hashInt(repo_opts.hash, "seen-object-ids"));│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │2036 - const seen_object_ids = try DB.HashSet(.read_write).init(seen_object_ids_cursor); │ │2032 + const seen_object_ids = try TempDB.HashSet(.read_write).init(seen_object_ids_cursor); │ │2033 │ │2034 const head_oid_hex = (try rf.readRecur(repo_kind, repo_opts, state, io, .{ .ref = ref })) orelse return error.OidNotFound;│ │2035 var head_oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │2078 } │ │2079 │ │2080 const children_cursor = try self.parent_to_children.putCursor(parent_oid_int);│ │2085 - const children = try DB.HashSet(.read_write).init(children_cursor); │ │2081 + const children = try TempDB.HashSet(.read_write).init(children_cursor); │ │2082 try children.put(oid_int, .{ .bytes = &oid }); │ │2083 pending_parent_count += 1; │ │2084 } │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │2094 fn enqueueChildren(self: *CommitIterator(repo_kind, repo_opts), oid: *const [hash.byteLen(repo_opts.hash)]u8) !void {│ │2095 const oid_int = hash.bytesToInt(repo_opts.hash, oid); │ │2096 const children_cursor = try self.parent_to_children.getCursor(oid_int) orelse return; │ │2101 - const children = try DB.HashSet(.read_only).init(children_cursor); │ │2097 + const children = try TempDB.HashSet(.read_only).init(children_cursor); │ │2098 var children_iter = try children.iterator(); │ │2099 │ │2100 while (try children_iter.next()) |*child_cursor| { │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │2113 } │ │2114 } │ │2115 │ │2120 - fn readOidFromList(list: DB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 { │ │2116 + fn readOidFromList(list: TempDB.ArrayList(.read_only), index: u64) ![hash.byteLen(repo_opts.hash)]u8 {│ │2117 const oid_cursor = try list.getCursor(index) orelse return error.CursorNotFound; │ │2118 var oid: [hash.byteLen(repo_opts.hash)]u8 = undefined; │ │2119 _ = try oid_cursor.readBytes(&oid); │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯