I'm currently working with akka on a new project. But now I'm stuck with a problem.
I added a mongo db to my project and set the journal and snapshotstore. I can persist events and the events will be stored in the database. That works great.
But when I restart the application and the actor starts to recovering the events, the actor only restore the first event. It seems that the Recovery upper SequenceNr Limit is set to 1 but I've already checked that. After the recovery of this first event the actor received the message RecoveryCompleted and the recovery process is finished.
The recovery methods
private void recovers()
{
Recover<TenantCreated>(evt =>
{
applyEvent(evt);
Context.System.EventStream.Publish(evt);
});
Recover<TenantDeleted>(evt =>
{
applyEvent(evt);
Context.System.EventStream.Publish(evt);
});
Recover<SnapshotOffer>(snapshot =>
{
this.state = (TenantCollection)snapshot.Snapshot;
});
Recover<RecoveryCompleted>(msg =>
{
});
}
One method that persists an event
Command<CreateTenant>(command =>
{
Persist(new TenantCreated(command.Id, command.UserId, command.Name, new Guid(command.Id).ToString("N")), evt =>
{
var newTenant = applyEvent(evt);
newTenant.Tell(command);
persistAndPublishEvent(evt);
});
});
My akka configuration. The connectionString will be loaded with a fallback. With this I can set the connectionString as an environment variable.
persistence {
journal {
plugin = "akka.persistence.journal.mongodb"
mongodb {
class = "Akka.Persistence.MongoDb.Journal.MongoDbJournal, Akka.Persistence.MongoDb"
collection = "EventJournal"
plugin-dispatcher = "akka.actor.default-dispatcher"
}
}
snapshot-store {
plugin = "akka.persistence.snapshot-store.mongodb"
mongodb {
class = "Akka.Persistence.MongoDb.Snapshot.MongoDbSnapshotStore, Akka.Persistence.MongoDb"
collection = "SnapshotStore"
plugin-dispatcher = "akka.actor.default-dispatcher"
}
}
}
What is the problem?
Does anyone has the same problem?
Yep, looks like this is a bug after all - deleting the metadata table exposed it.
It's because we don't apply indexes to the collections by default (and haven't ever, by the looks of it - which we missed because the configurations in our test suites are different:) https://github.com/akkadotnet/Akka.Persistence.MongoDB/blob/552a29eed4c839fe4f91fceeb70bb29eb17d1315/src/Akka.Persistence.MongoDb/reference.conf#L11
So this was really helpful - turns out our large users never had this issue because they ran with auto-initialize=on
in their configurations this entire time. You were affected by the defaults being different.
https://github.com/akkadotnet/Akka.Persistence.MongoDB/releases/tag/1.4.21 - we released Akka.NET v1.4.21 which fixes this.