Skip to content

Commit

Permalink
all tests passing / misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sobeston committed Jan 16, 2025
1 parent c7ff601 commit e25e45c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 150 deletions.
1 change: 0 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ pub fn build(b: *Build) void {
.optimize = optimize,
.filters = filters orelse &.{},
.sanitize_thread = enable_tsan,
.test_runner = b.path("src/test_runner.zig"),
});
b.installArtifact(unit_tests_exe);
unit_tests_exe.root_module.addImport("base58-zig", base58_module);
Expand Down
9 changes: 8 additions & 1 deletion src/accountsdb/buffer_pool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ pub const BufferPool = struct {
return error.CannotOverwriteAliveInfo;
}

self.frames_metadata.freq[f_idx] = 0;
self.frames_metadata.freqSetToZero(f_idx);
self.frames_metadata.in_queue[f_idx] = .none;
self.frames_metadata.rc[f_idx].reset();

Expand Down Expand Up @@ -603,6 +603,8 @@ pub const FramesMetadata = struct {
}

fn freqDecrement(self: FramesMetadata, index: FrameIndex) void {
// note for reviewers: I myself do not trust this code, have a think about it

const old_freq = @atomicRmw(u2, &self.freq[index], .Add, 1, .acq_rel);
if (old_freq == 3) {
// we overflowed (0->3), set back to min
Expand All @@ -620,6 +622,11 @@ pub const FramesMetadata = struct {
// note for reviewers: I myself do not trust this code, have a think about it
@atomicStore(u2, &self.freq[index], 1, .release);
}

fn freqSetToZero(self: FramesMetadata, index: FrameIndex) void {
// note for reviewers: I myself do not trust this code, have a think about it
@atomicStore(u2, &self.freq[index], 0, .release);
}
};

/// This cache is S3-FIFO inspired, with some important modifications to reads
Expand Down
21 changes: 15 additions & 6 deletions src/accountsdb/db.zig
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ pub const AccountsDB = struct {
{
const file_map, var file_map_lg = self.file_map.writeWithLock();
defer file_map_lg.unlock();
for (file_map.values()) |v| v.deinit();
file_map.deinit(self.allocator);
}
{
Expand Down Expand Up @@ -664,6 +665,9 @@ pub const AccountsDB = struct {
};
errdefer accounts_file.deinit();

const file_id = file_info.id;
file_map.putAssumeCapacityNoClobber(file_id, accounts_file);

// index the account file
var slot_references = std.ArrayListUnmanaged(AccountRef).initBuffer(
references_buf[n_accounts_total..],
Expand Down Expand Up @@ -705,7 +709,7 @@ pub const AccountsDB = struct {
const geyser_writer = self.geyser_writer.?; // SAFE: will always be set if geyser_is_enabled

// ! reset memory for the next slot
defer geyser_storage.reset();
defer geyser_storage.reset(self.allocator);

const data_versioned: sig.geyser.core.VersionedAccountPayload = .{
.AccountPayloadV1 = .{
Expand All @@ -717,8 +721,6 @@ pub const AccountsDB = struct {
try geyser_writer.writePayloadToPipe(data_versioned);
}

const file_id = file_info.id;
file_map.putAssumeCapacityNoClobber(file_id, accounts_file);
self.largest_file_id = FileId.max(self.largest_file_id, file_id);
_ = self.largest_rooted_slot.fetchMax(slot, .release);
self.largest_flushed_slot.store(self.largest_rooted_slot.load(.acquire), .release);
Expand Down Expand Up @@ -1937,7 +1939,9 @@ pub const AccountsDB = struct {
accounts_alive_size,
slot,
);
defer new_file.close();
// don't close file if it ends up in file_map
var new_file_in_map = false;
defer if (!new_file_in_map) new_file.close();

var file_size: usize = 0;
account_iter.reset();
Expand Down Expand Up @@ -1983,6 +1987,7 @@ pub const AccountsDB = struct {
new_account_file.number_of_accounts = accounts_alive_count;

file_map.putAssumeCapacityNoClobber(new_file_id, new_account_file);
new_file_in_map = true;
}

// update the references
Expand Down Expand Up @@ -3199,16 +3204,20 @@ pub const GeyserTmpStorage = struct {
self.pubkeys.deinit();
}

pub fn reset(self: *Self) void {
pub fn reset(
self: *Self,
allocator: std.mem.Allocator,
) void {
for (self.accounts.items) |account| account.deinit(allocator);
self.accounts.clearRetainingCapacity();
self.pubkeys.clearRetainingCapacity();
}

pub fn cloneAndTrack(self: *Self, allocator: std.mem.Allocator, account_in_file: AccountInFile) Error!void {
// doesn't feel great allocating this?
const account = try account_in_file.toOwnedAccount(allocator);
errdefer account.deinit(allocator);
self.accounts.append(account) catch return Error.OutOfGeyserArrayMemory;
errdefer _ = self.accounts.pop();
self.pubkeys.append(account_in_file.pubkey().*) catch return Error.OutOfGeyserArrayMemory;
}
};
Expand Down
142 changes: 0 additions & 142 deletions src/test_runner.zig

This file was deleted.

0 comments on commit e25e45c

Please sign in to comment.