Skip to content

Commit 1654497

Browse files
authored
Keep the trade-ledger cache at its default cap on report-sink runs and assemble the report in one pass (#590)
This lands two engine pull requests as one change, verified and measured once on the combined tree: - #611 engine: keep the trade-ledger read cache at the default cap on report-sink runs, so closed-trade reads on report-sink runs stop re-reading the disk on every access - #590 run_json: assemble the report from one pass over the sink spools #611 is closed as landed here.
1 parent f85ce18 commit 1654497

22 files changed

Lines changed: 11300 additions & 546 deletions

‎docker/pf_sink.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ def parse_verified(self, line: bytes) -> Record:
296296
class SinkReader:
297297
"""One-pass, bounded-memory iterator. Exhaustion verifies the entire sink."""
298298

299-
def __init__(self, path: str | Path | None = None, *, stream: BinaryIO | None = None):
299+
def __init__(self, path: str | Path | None = None, *,
300+
stream: BinaryIO | None = None, keep_open: bool = False):
300301
if (path is None) == (stream is None):
301302
raise TypeError("supply exactly one of path and stream")
302303
self.header: dict[str, Any] = {}
@@ -307,6 +308,7 @@ def __init__(self, path: str | Path | None = None, *, stream: BinaryIO | None =
307308
self._hash = hashlib.sha256()
308309
self._file: BinaryIO | None = None
309310
self._failed = False
311+
self._keep_open = bool(keep_open)
310312
try:
311313
self._file = stream if stream is not None else open(path, "rb")
312314
value, line = self._readline()
@@ -352,7 +354,8 @@ def _finish(self, value: dict[str, Any]) -> None:
352354
raise SinkFormatError("trailer SHA-256 mismatch")
353355
if self._file is None or self._file.read(1):
354356
raise SinkFormatError("bytes after the trailer")
355-
self.close()
357+
if not self._keep_open:
358+
self.close()
356359
self.trailer = value
357360
self.sha256 = digest
358361
self.complete = True

0 commit comments

Comments
 (0)