Skip to content

Commit

Permalink
refactor(gossip): dump service in own thread
Browse files Browse the repository at this point in the history
make the gossip dump service work like the other gossip components, where a thread is spawned, and the entire thing exits if it dies.
  • Loading branch information
dnut committed Mar 26, 2024
1 parent 5427991 commit 4ecf365
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/gossip/dump_service.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub const GossipDumpService = struct {

const Self = @This();

pub fn run(self: *Self) !void {
pub fn run(self: Self) !void {
const start_time = std.time.timestamp();
const dir = try std.fmt.allocPrint(self.allocator, "gossip-dumps/{}", .{start_time});
defer self.allocator.free(dir);
Expand All @@ -29,7 +29,7 @@ pub const GossipDumpService = struct {
}
}

fn dumpGossip(self: *Self, dir: []const u8, start_time: i64) !void {
fn dumpGossip(self: *const Self, dir: []const u8, start_time: i64) !void {
const data = blk: {
var gossip_table_lock = self.gossip_table_rw.read();
defer gossip_table_lock.unlock();
Expand Down
16 changes: 7 additions & 9 deletions src/gossip/service.zig
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,13 @@ pub const GossipService = struct {
});
defer self.joinAndExit(&responder_handle);

if (dump) {
var dump_svc = GossipDumpService{
.allocator = self.allocator,
.logger = self.logger,
.gossip_table_rw = &self.gossip_table_rw,
.exit = self.exit,
};
try dump_svc.run();
}
var dump_handle = if (dump) try Thread.spawn(.{}, GossipDumpService.run, .{.{
.allocator = self.allocator,
.logger = self.logger,
.gossip_table_rw = &self.gossip_table_rw,
.exit = self.exit,
}}) else null;
defer if (dump_handle) |*h| self.joinAndExit(h);
}

fn sortSlices(slices: anytype) void {
Expand Down

0 comments on commit 4ecf365

Please sign in to comment.