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

Akka.Persistence.Sql.Common: DeleteMessages when journal is empty causes duplicate key SQL exception #3721

Closed
Aaronontheweb opened this issue Feb 18, 2019 · 3 comments

Comments

@Aaronontheweb
Copy link
Member

Version: Akka.NET v1.3.11

Use case: when using an AtLeastOnceDeliveryActor, I'm not using the journal at all - but I do save snapshots of my AtLeastOnceDelivery state regularly.

When I receive a SaveSnapshotSuccess message, I call:

Command<SaveSnapshotSuccess>(saved =>
            {
                var seqNo = saved.Metadata.SequenceNr;
                DeleteMessages(seqNo);
                DeleteSnapshots(new SnapshotSelectionCriteria(seqNo,
                    saved.Metadata.Timestamp.AddMilliseconds(-1))); // delete all but the most current snapshot
            });

Out of a force of habit from my other actors that use Akka.Persistence.

The DeleteMessages call in this case causes a SqlException to be raised in the Metadata table used by the Akka.Persistence.Sql.Common driver, due to this line in the driver:

if (highestSeqNr <= toSequenceNr)
{
using (var updateCommand = GetCommand(connection, UpdateSequenceNrSql))
{
updateCommand.Transaction = tx;
AddParameter(updateCommand, "@PersistenceId", DbType.String, persistenceId);
AddParameter(updateCommand, "@SequenceNr", DbType.Int64, highestSeqNr);
await updateCommand.ExecuteNonQueryAsync(cancellationToken);
tx.Commit();
}
}

Since the sequence numbers are both 0, the driver tries to insert another (persistenceId, 0) record into the Metadata table even though one already exists.

I'll send a repo along for this shortly.

@ismaelhamed
Copy link
Member

GH-3468

@Aaronontheweb
Copy link
Member Author

@ismaelhamed good to know - I'll go back and review that PR again

@Aaronontheweb
Copy link
Member Author

closed via #3468

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

No branches or pull requests

2 participants