From cf7d0562bb37b9ef89f92b7192359f15b458d0ab Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Mon, 17 Aug 2026 12:49:56 -0500 Subject: [PATCH] archive: bytes_fetched in Result; slice_sync reports fetches + wire bytes Co-Authored-By: Claude Fable 5 --- examples/slice_sync.zig | 9 ++++----- src/archive_backfill.zig | 5 +++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/slice_sync.zig b/examples/slice_sync.zig index 7344f5a..8a2a1f3 100644 --- a/examples/slice_sync.zig +++ b/examples/slice_sync.zig @@ -21,7 +21,7 @@ const SliceStats = struct { by_collection: std.StringHashMapUnmanaged(usize) = .empty, arena: std.mem.Allocator, - pub fn onEvent(self: *@This(), event: jetstream_sdk.Event) bool { + pub fn onRow(self: *@This(), event: jetstream_sdk.Event) bool { self.rows += 1; if (self.first_time_us == 0) self.first_time_us = event.time_us; self.last_time_us = event.time_us; @@ -67,10 +67,9 @@ pub fn main(init: std.process.Init) !void { const started = std.Io.Timestamp.now(init.io, .awake).nanoseconds; var stats = SliceStats{ .arena = init.arena.allocator() }; - try jetstream_sdk.subscribe(init.io, allocator, .{ - .hosts = &.{"https://stream.waow.tech"}, + const result = try jetstream_sdk.ArchiveBackfill.run(init.io, allocator, .{ + .host = "https://stream.waow.tech", .after_seq = 0, - .snapshot_only = true, .dids = &.{did}, .collections = collections.items, // jim's sparse-backfill recipe: kind=commit changes the PLAN, not @@ -82,7 +81,7 @@ pub fn main(init: std.process.Init) !void { }, &stats); const elapsed_ms = @divFloor(std.Io.Timestamp.now(init.io, .awake).nanoseconds - started, std.time.ns_per_ms); - std.debug.print("\n{d} rows in {d}ms\n", .{ stats.rows, elapsed_ms }); + std.debug.print("\n{d} rows in {d}ms — {d} block fetches, {d} KB over the wire\n", .{ stats.rows, elapsed_ms, result.blocks_decoded, result.bytes_fetched / 1024 }); var it = stats.by_collection.iterator(); while (it.next()) |entry| { std.debug.print(" {s}: {d}\n", .{ entry.key_ptr.*, entry.value_ptr.* }); diff --git a/src/archive_backfill.zig b/src/archive_backfill.zig index bb12080..284ec16 100644 --- a/src/archive_backfill.zig +++ b/src/archive_backfill.zig @@ -106,6 +106,9 @@ pub const Result = struct { stopped: bool = false, events_delivered: u64 = 0, blocks_decoded: u64 = 0, + /// compressed bytes fetched over the wire (getBlock frames and + /// getSegment bodies), for IO accounting + bytes_fetched: u64 = 0, /// true when Options.max_blocks stopped the run before the plan was exhausted truncated: bool = false, /// last decoded block; feed to Options.start_after to resume @@ -188,6 +191,7 @@ pub fn run(io: Io, allocator: Allocator, options: Options, handler: anytype) !Re defer allocator.free(url); var fetched = try fetchWithRetry(io, &transport, url, authorization); defer fetched.deinit(allocator); + result.bytes_fetched += fetched.body.len; try deliverSegment(allocator, fetched.body, options, segment, handler, &result); } } @@ -275,6 +279,7 @@ const FetchWindow = struct { defer self.allocator.free(slot.url); var fetched = try slot.future.await(self.io); defer fetched.deinit(allocator); + result.bytes_fetched += fetched.body.len; try deliverFrame(allocator, fetched.body, options, slot.position, handler, result); } -- 2.51.2