Skip to content

Commit

Permalink
Simplify the full field, and remove some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
InKryption committed Dec 13, 2024
1 parent d72a4f3 commit 1e71dc6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/accountsdb/bank.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/accountsdb/db.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
45 changes: 13 additions & 32 deletions src/accountsdb/snapshots.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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(.{
Expand Down Expand Up @@ -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 .{
Expand Down Expand Up @@ -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(
Expand All @@ -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,
};
}
Expand Down Expand Up @@ -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,
);
}
};

Expand All @@ -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)});
Expand Down Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions src/cmd/cmd.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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}", .{
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 1e71dc6

Please sign in to comment.