JasperFx / marten

.NET Transactional Document DB and Event Store on PostgreSQL

Home Page:https://martendb.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug? WaitForNonStaleProjectionDataAsync waits for all projections, inline and live, not only Async projections

Richard87 opened this issue · comments

When executing WaitForNonStaleProjectionDataAsync, it finds all projections, including Inline, and tries to wait for them to get past initial.EventSequenceNumber

projections.All(x => x.Sequence >= initial.EventSequenceNumber))

In my testing, inline projections doesn't get updated before a new event that is used by the projection is applied, so its almost always lagging. In those cases WaitForNonStaleProjectionDataAsync will fail.

Probably the most hacky and slow bugfix:

        Dictionary<string,string> shardNames = store.Advanced.AllAsyncProjectionShardNames()
            .ToDictionary(x => x.ProjectionName, x => x.Identity);

        var shardsToCheck = store.Options
            .Events
            .Projections()
            .Where(x => x.Lifecycle == ProjectionLifecycle.Async)
            .Select(x => shardNames[x.ProjectionName]);

///and

            if ((projections.Count >= projectionsCount &&
                 projections.Where(x => shardsToCheck.Contains(x.ShardName)).All(x => x.Sequence >= initial.EventSequenceNumber))
                || cancellationSource.IsCancellationRequested)
            {

@Richard87 I'm happy to take a pull request for that, but I'd just fix the AllAsyncProjectionShardNames() in the first place

Basically a duplicate with #3165