Repository navigation
[DB-2273]: Cap stream reads at the last event number they report - #5822
timothycoleman wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
A stream read that overlapped an append to the same stream could return events past the last event number it reported (#5816). Before this change, a read took the stream's last event number from the cache, then read the requested range from the index. If an append completed in between, the index already held the new events, so the read returned them along with the older last event number. Reads now cap the index range at the last event number they report, so events appended during the read are left for the next read. In the $maxAge path, the gap loop still looks for the next index entry without the cap. TryGetNextEntry matches on the stream hash and can land on a colliding stream's entry past the last event number, so capping there would skip the stream's last event. Instead, the first page leaves out the stream's own entries past the last event number. The cap in the $maxAge binary search is defensive: it only matters when hashes collide. We didn't raise the reported last event number to the last event returned instead, because that mixes two points in time. A page can end partway through an append, so the reported last event number could be one the stream never had, and the $maxCount lower bound would still come from the older last event number. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
b3e76d3 to
3552c72
Compare
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the change to keep stream-read results and pagination metadata consistent during overlapping appends.
No open issues 🎉
What changed in this PR
Fixes #5816 by capping stream reads at their reported last event number, keeping returned events and pagination metadata consistent when reads overlap appends.
Changes:
- Caps forward, backward, and
$maxAgeread ranges while preserving hash-collision handling. - Adds deterministic regression tests for an index ahead of the cached last event number and
$maxAgegaps involving colliding streams. - Clarifies how PR descriptions should distinguish previous buggy behavior from current behavior.
| File | Description |
|---|---|
src/KurrentDB.Core/Services/Storage/ReaderIndex/IndexReader.cs |
Caps returned events at the reported last event number across stream-read paths. |
src/KurrentDB.Core.Tests/Services/Storage/ReadIndex/when_reading_a_stream_while_its_index_is_ahead_of_the_cached_last_event_number.cs |
Tests read bounds and pagination when the index is ahead of the cache. |
src/KurrentDB.Core.Tests/Services/Storage/ReadIndex/when_reading_a_max_age_stream_whose_index_gap_leads_to_a_colliding_stream.cs |
Tests that collision-related gaps preserve the last valid event without returning newer events. |
CLAUDE.md |
Adds wording guidance for explaining pre-fix behavior in PR descriptions. |
Review effort: Balanced
Fixes #5816
A stream read that ran while an append to the same stream was committing could return events past the last stream position it reported, for example events 0..10 with
last_stream_position8. A client that pages by comparing the two would read again and get an empty page. After this change, every stream read reports a last stream position at or above every event it returns. Events appended while the read runs are left for the next read.Design decisions
$maxCountlower bound would still come from the older value.$maxAgegap loop left as it was:TryGetNextEntrymatches on the stream hash and can land on a colliding stream's entry past the last event number. Capping there would skip the stream's last event, so the first page leaves out the stream's own entries past the last event number instead.Risk
Low. Only stream reads that overlap an append change: they return fewer events, ending at the last event number they report. Subscriptions weren't affected, since they drop anything at or below their checkpoint. No data format, compatibility or config changes, and the read path gains only a few integer comparisons.
🤖 Generated with Claude Code