Skip to content

Commit

Permalink
Correct the account file filtering filtering logic
Browse files Browse the repository at this point in the history
  • Loading branch information
InKryption committed Jul 10, 2024
1 parent 71d247d commit f59b5a7
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/accountsdb/db.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2029,11 +2029,17 @@ pub const AccountsDB = struct {
defer serializable_file_map.deinit();
try serializable_file_map.ensureTotalCapacity(file_map.count());

const is_incremental = bank_fields_inc.snapshot_persistence != null;

for (file_map.values()) |*account_file_rw| {
const account_file, var account_file_lg = account_file_rw.readWithLock();
defer account_file_lg.unlock();

if (account_file.slot > max_rooted_slot) continue;
if (is_incremental) {
if (account_file.slot != max_rooted_slot) continue;
} else {
if (account_file.slot > max_rooted_slot) continue;
}

serializable_file_map.putAssumeCapacityNoClobber(account_file.slot, .{
.id = account_file.id,
Expand Down Expand Up @@ -2209,7 +2215,7 @@ pub fn writeSnapshotTarWithFields(
const account_file, var account_file_lg = account_file_rw.readWithLock();
defer account_file_lg.unlock();

if (account_file.slot < slot) continue;
if (!snapshot_fields.accounts_db_fields.file_map.contains(account_file.slot)) continue;

const name_bounded = sig.utils.fmt.boundedFmt("accounts/{d}.{d}", .{ slot, file_id.toInt() });
try sig.utils.tar.writeTarHeader(writer, .regular, name_bounded.constSlice(), account_file.memory.len);
Expand Down Expand Up @@ -2245,6 +2251,15 @@ fn testWriteSnapshot(
var accounts_db = try AccountsDB.init(allocator, .noop, .{});
defer accounts_db.deinit(true);

var acc_file = blk: {
var acc_file_fd = try std.fs.cwd().openFile("test_data/accounts/200.3", .{ .mode = .read_write });
errdefer acc_file_fd.close();
break :blk try AccountFile.init(acc_file_fd, .{ .id = 3, .length = (try acc_file_fd.stat()).size }, 200);
};
defer acc_file.deinit();

try accounts_db.putAccountFile(&acc_file, 1);

{
var accounts_dir = try snapshot_dir.openDir("accounts", .{ .iterate = true });
defer accounts_dir.close();
Expand Down

0 comments on commit f59b5a7

Please sign in to comment.