Skip to content

Commit

Permalink
Fix archive order (#382)
Browse files Browse the repository at this point in the history
* Tiered reader returns events in wrong order, fixing it for 0.15
  • Loading branch information
alexeyzimarev authored Nov 7, 2024
1 parent b2c610f commit c876f28
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public async Task<StreamEvent[]> ReadEvents(StreamName streamName, StreamReadPos
var hotEvents = await LoadStreamEvents(hotReader, start, count).NoContext();

var archivedEvents = hotEvents.Length == 0 || hotEvents[0].Position > start.Value
? await LoadStreamEvents(archiveReader, start, count - hotEvents.Length).NoContext()
? await LoadStreamEvents(archiveReader, start, (int)hotEvents[0].Position).NoContext()
: Enumerable.Empty<StreamEvent>();

return hotEvents.Concat(archivedEvents.Select(x => x with { FromArchive = true })).Distinct(Comparer).ToArray();
return archivedEvents.Select(x => x with { FromArchive = true }).Concat(hotEvents).Distinct(Comparer).ToArray();

async Task<StreamEvent[]> LoadStreamEvents(IEventReader reader, StreamReadPosition startPosition, int localCount) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ protected async Task Should_load_hot_and_archive() {
var actual = loaded.Select(x => (TestEventForTiers)x.Payload!).ToArray();
actual.Should().BeEquivalentTo(testEvents);

loaded.Take(50).Select(x => x.FromArchive).Should().AllSatisfy(x => x.Should().BeFalse());
loaded.Skip(50).Select(x => x.FromArchive).Should().AllSatisfy(x => x.Should().BeTrue());
loaded.Take(50).Select(x => x.FromArchive).Should().AllSatisfy(x => x.Should().BeTrue());
loaded.Skip(50).Select(x => x.FromArchive).Should().AllSatisfy(x => x.Should().BeFalse());
}

readonly Fixture _fixture = new();
Expand Down

0 comments on commit c876f28

Please sign in to comment.