fix(trail): record_count/summary/export include unflushed buffered records (#150) - #164
Merged
Conversation
…cords (#150) In buffered mode, all three read paths queried only the backend, so: - record_count was 0 until the next background flush - summary() reported stale provenance/freshness aggregates - export() silently omitted pending writes WriteBuffer gains __len__ (delegates to pending) and pending_records (thread-safe snapshot). record_count adds the pending count without flushing; summary() appends the snapshot to the backend records; export() flushes explicitly so its backend read is always complete. Also removes the stray # Added offset parameter comment left over from the [1.1.0] offset addition, and renames test_context_trail_query_supports_offset to reflect that it tests PaginatedMockTrail, not ContextTrail.query(). Closes #150
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
In buffered mode,
record_count,summary(), andexport()all queried only the backend, giving a stale view of the trail whenever records were sitting in the write buffer:record_countreturned 0 (or the flushed count) until the next background flushsummary()reported stale provenance/freshness/source aggregates — aMISSINGprovenance in the buffer was invisibleexport()silently omitted pending writes entirelyFix:
WriteBuffergains two helpers:__len__— delegates topendingso callers can uselen(buffer)pending_records— returns a thread-safe snapshot of the buffer contentsContextTrailchanges:record_countaddsself._buffer.pendingto the backend count without flushing (read-only)summary()appendsself._buffer.pending_recordsto the backend snapshot before aggregatingexport()callsself._buffer.flush()before reading — the export must be complete; a non-flushing approach would return an inconsistent snapshot hereAlso cleans up two leftover issues from the [1.1.0] offset addition:
# Added offset parameter to truly handle datasets of any size without hard capscomment intrail.pytest_context_trail_query_supports_offset→test_paginated_mock_trail_returns_distinct_pagesto reflect that it testsPaginatedMockTrail, notContextTrail.query()Checklist
ruff check src/ tests/passesruff format --check src/ tests/passesmypy src/provena/passespytestpasses with no failuresRelated Issues
Closes #150