From 1e71dc6082fb5d4893e96e6984ec52b385ddc21f Mon Sep 17 00:00:00 2001 From: Trevor Berrange Sanchez Date: Thu, 12 Dec 2024 00:20:20 +0100 Subject: [PATCH] Simplify the full field, and remove some functions --- src/accountsdb/bank.zig | 2 +- src/accountsdb/db.zig | 4 ++-- src/accountsdb/snapshots.zig | 45 +++++++++++------------------------- src/cmd/cmd.zig | 6 ++--- src/rpc/server.zig | 2 +- 5 files changed, 20 insertions(+), 39 deletions(-) diff --git a/src/accountsdb/bank.zig b/src/accountsdb/bank.zig index d2268fb0f..b00dcc4e0 100644 --- a/src/accountsdb/bank.zig +++ b/src/accountsdb/bank.zig @@ -73,7 +73,7 @@ test "core.bank: load and validate from test snapshot" { const snapshot_files = try sig.accounts_db.db.findAndUnpackTestSnapshots(1, snapdir); const boundedFmt = sig.utils.fmt.boundedFmt; - const full_manifest_path = boundedFmt("snapshots/{0}/{0}", .{snapshot_files.full_info.slot}); + const full_manifest_path = boundedFmt("snapshots/{0}/{0}", .{snapshot_files.full.slot}); const full_manifest_file = try snapdir.openFile(full_manifest_path.constSlice(), .{}); defer full_manifest_file.close(); diff --git a/src/accountsdb/db.zig b/src/accountsdb/db.zig index 0c929b1ae..398bfe86c 100644 --- a/src/accountsdb/db.zig +++ b/src/accountsdb/db.zig @@ -3363,7 +3363,7 @@ pub fn findAndUnpackTestSnapshots( const snapshot_files = try SnapshotFiles.find(allocator, test_data_dir); { - const full_name_bounded = snapshot_files.full().snapshotArchiveName(); + const full_name_bounded = snapshot_files.full.snapshotArchiveName(); const full_name = full_name_bounded.constSlice(); const full_archive_file = try test_data_dir.openFile(full_name, .{}); defer full_archive_file.close(); @@ -4402,7 +4402,7 @@ pub const BenchmarkAccountsDBSnapshotLoad = struct { else |err| switch (err) { else => |e| return e, error.FileNotFound => if (attempt == 0) { - const archive_file = try snapshot_dir.openFile(snapshot_files.full().snapshotArchiveName().constSlice(), .{}); + const archive_file = try snapshot_dir.openFile(snapshot_files.full.snapshotArchiveName().constSlice(), .{}); defer archive_file.close(); try parallelUnpackZstdTarBall( allocator, diff --git a/src/accountsdb/snapshots.zig b/src/accountsdb/snapshots.zig index 12cce0a28..4566cd70b 100644 --- a/src/accountsdb/snapshots.zig +++ b/src/accountsdb/snapshots.zig @@ -1920,20 +1920,6 @@ pub const FullSnapshotFileInfo = struct { slot: Slot, hash: Hash, - pub fn from(sah: SlotAndHash) FullSnapshotFileInfo { - return .{ - .slot = sah.slot, - .hash = sah.hash, - }; - } - - pub fn slotAndHash(self: FullSnapshotFileInfo) SlotAndHash { - return .{ - .slot = self.slot, - .hash = self.hash, - }; - } - const SnapshotArchiveNameFmtSpec = sig.utils.fmt.BoundedSpec("snapshot-{[slot]d}-{[hash]s}.tar.zst"); pub const SnapshotArchiveNameStr = SnapshotArchiveNameFmtSpec.BoundedArrayValue(.{ @@ -2053,14 +2039,6 @@ pub const IncrementalSnapshotFileInfo = struct { slot: Slot, hash: Hash, - pub fn from(base_slot: Slot, sah: SlotAndHash) IncrementalSnapshotFileInfo { - return .{ - .base_slot = base_slot, - .slot = sah.slot, - .hash = sah.hash, - }; - } - /// Returns the incremental slot and hash. pub fn slotAndHash(self: IncrementalSnapshotFileInfo) SlotAndHash { return .{ @@ -2212,16 +2190,16 @@ pub const IncrementalSnapshotFileInfo = struct { }; pub const SnapshotFiles = struct { - full_info: SlotAndHash, + full: FullSnapshotFileInfo, incremental_info: ?SlotAndHash, - pub fn full(snapshot_files: SnapshotFiles) FullSnapshotFileInfo { - return FullSnapshotFileInfo.from(snapshot_files.full_info); - } - pub fn incremental(snapshot_files: SnapshotFiles) ?IncrementalSnapshotFileInfo { const inc_info = snapshot_files.incremental_info orelse return null; - return IncrementalSnapshotFileInfo.from(snapshot_files.full_info.slot, inc_info); + return .{ + .base_slot = snapshot_files.full.slot, + .slot = inc_info.slot, + .hash = inc_info.hash, + }; } pub fn fromFileInfos( @@ -2232,7 +2210,7 @@ pub const SnapshotFiles = struct { std.debug.assert(inc.base_slot == full_info.slot); } return .{ - .full_info = full_info.slotAndHash(), + .full = full_info, .incremental_info = if (maybe_incremental_info) |inc| inc.slotAndHash() else null, }; } @@ -2272,7 +2250,10 @@ pub const SnapshotFiles = struct { count += 1; } - return fromFileInfos(latest_full_snapshot, maybe_latest_incremental_snapshot); + return fromFileInfos( + latest_full_snapshot, + maybe_latest_incremental_snapshot, + ); } }; @@ -2295,7 +2276,7 @@ pub const AllSnapshotFields = struct { const logger = logger_.withScope(@typeName((Self))); // unpack const full_fields = blk: { - const rel_path_bounded = sig.utils.fmt.boundedFmt("snapshots/{0}/{0}", .{files.full_info.slot}); + const rel_path_bounded = sig.utils.fmt.boundedFmt("snapshots/{0}/{0}", .{files.full.slot}); const rel_path = rel_path_bounded.constSlice(); logger.info().logf("reading snapshot fields from: {s}", .{sig.utils.fmt.tryRealPath(snapshot_dir, rel_path)}); @@ -2557,7 +2538,7 @@ test "parse snapshot fields" { const snapshot_files = try sig.accounts_db.db.findAndUnpackTestSnapshots(1, snapdir); - const full_slot = snapshot_files.full_info.slot; + const full_slot = snapshot_files.full.slot; const full_manifest_path_bounded = sig.utils.fmt.boundedFmt("snapshots/{0}/{0}", .{full_slot}); const full_manifest_path = full_manifest_path_bounded.constSlice(); diff --git a/src/cmd/cmd.zig b/src/cmd/cmd.zig index 11b1be027..209a124e7 100644 --- a/src/cmd/cmd.zig +++ b/src/cmd/cmd.zig @@ -1375,7 +1375,7 @@ fn loadSnapshot( result.snapshot_fields = all_snapshot_fields; logger.info().logf("full snapshot: {s}", .{ - sig.utils.fmt.tryRealPath(snapshot_dir, snapshot_files.full().snapshotArchiveName().constSlice()), + sig.utils.fmt.tryRealPath(snapshot_dir, snapshot_files.full.snapshotArchiveName().constSlice()), }); if (snapshot_files.incremental()) |inc_snap| { logger.info().logf("incremental snapshot: {s}", .{ @@ -1607,10 +1607,10 @@ fn getOrDownloadSnapshots( // if accounts/ doesnt exist then we unpack the found snapshots // TODO: delete old accounts/ dir if it exists timer.reset(); - logger.info().logf("unpacking {s}...", .{snapshot_files.full().snapshotArchiveName().constSlice()}); + logger.info().logf("unpacking {s}...", .{snapshot_files.full.snapshotArchiveName().constSlice()}); { const archive_file = try snapshot_dir.openFile( - snapshot_files.full().snapshotArchiveName().constSlice(), + snapshot_files.full.snapshotArchiveName().constSlice(), .{}, ); defer archive_file.close(); diff --git a/src/rpc/server.zig b/src/rpc/server.zig index d6258b17c..c2d17c0e4 100644 --- a/src/rpc/server.zig +++ b/src/rpc/server.zig @@ -410,7 +410,7 @@ test Server { const SnapshotFiles = sig.accounts_db.snapshots.SnapshotFiles; const snap_files = try SnapshotFiles.find(allocator, test_data_dir); - const full_snap_name_bounded = snap_files.full().snapshotArchiveName(); + const full_snap_name_bounded = snap_files.full.snapshotArchiveName(); const maybe_inc_snap_name_bounded = if (snap_files.incremental()) |inc| inc.snapshotArchiveName() else null;