Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest releases #159

Merged
merged 30 commits into from
Nov 26, 2020
Merged

Update to latest releases #159

merged 30 commits into from
Nov 26, 2020

Conversation

eaba
Copy link
Contributor

@eaba eaba commented Nov 12, 2020

We have Akka.Persistence.MongoDB plugin stuck on older releases of Akka.NET - this is because of some changes we made to the Akka.Persistence.TCK in Akka.NET v1.4.10.

@Arkatufus
Copy link
Contributor

All in all, the codes looks good, just need some minor tweaks.

@eaba
Copy link
Contributor Author

eaba commented Nov 14, 2020

Ok @Arkatufus. Can you direct me to what blocks of codes need tweaking?

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of the Timestamp field. Ordering already does this and the clock is set by the MongoDb server by default, which is a better practice than setting it on the client.

@Arkatufus
Copy link
Contributor

@eaba One last changes from my side:
#159 (comment)


namespace Akka.Persistence.MongoDb.Tests
{
class MongoDbAllCurrentEventsSpec
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a spec you're still working on?

@Aaronontheweb
Copy link
Member

The current test failures with the "AllEventsSpec" - is this because the events are being returned out of order? I only briefly checked the error messages but haven't looked at the detailed logs.

@eaba
Copy link
Contributor Author

eaba commented Nov 17, 2020

It is being caused by Message mismatch

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far but we have some major changes that need to be made to the MongoDb queries. Avoid table scans and use the indices we have.

@@ -113,8 +110,6 @@ protected override void PreStart()

public override async Task ReplayMessagesAsync(IActorContext context, string persistenceId, long fromSequenceNr, long toSequenceNr, long max, Action<IPersistentRepresentation> recoveryCallback)
{
NotifyNewPersistenceIdAdded(persistenceId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

public override async Task<long> ReadHighestSequenceNrAsync(string persistenceId, long fromSequenceNr)
{
NotifyNewPersistenceIdAdded(persistenceId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

}
}

internal sealed class LivePersistenceIdsPublisher : ActorPublisher<string>, IWithUnboundedStash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}
private async Task<long> CountTotalRows()
{
return await Task.Run(() =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than do this, why now just use CountAsync on the MongoDb driver itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now deleted that...I only created it while I was trying to understand the issue with ReplayAllEventsAsyn

}

private async Task<long> GetHighestOrdering()
{
return await Task.Run(() =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as below - just use the MaxAsync call

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this query can be rewritten in a much less expensive way:

var modelWithOrdering = new CreateIndexModel<JournalEntry>(
Builders<JournalEntry>
.IndexKeys
.Ascending(entry => entry.Ordering));

We have a sorted index built on top of the Ordering column. Just select the maximum value from it. Don't do an entire table scan. That turns this into a O(1) query rather than an O(n) query.

@@ -400,7 +423,7 @@ private async Task SetHighSequenceId(IList<AtomicWrite> messages)
SequenceNr = highSequenceId
};

await _metadataCollection.Value.ReplaceOneAsync(filter, metadataEntry, new UpdateOptions() { IsUpsert = true });
await _metadataCollection.Value.ReplaceOneAsync(filter, metadataEntry, new ReplaceOptions() { IsUpsert = true });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, since we are replacing the metadataentry outright

{
_allPersistenceIdSubscribers.Add(subscriber);
}
subscriber.Tell(new CurrentPersistenceIds(GetAllPersistenceIds()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good

readFilter &= builder.Lte(x => x.Ordering, new BsonTimestamp(toSeqNo));
var sort = Builders<JournalEntry>.Sort.Ascending(x => x.Ordering);

await _journalCollection.Value.Find(readFilter)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}

subscriptions.Add(subscriber);
}

private IEnumerable<string> GetAllPersistenceIds()
{
return _journalCollection.Value.AsQueryable()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to query the _metadataCollection instead - that will be a tremendously less expensive query than scanning the entire journal.

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Aaronontheweb Aaronontheweb merged commit 6fdab40 into akkadotnet:dev Nov 26, 2020
@Aaronontheweb
Copy link
Member

nice work @eaba

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants