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

When deleting SQL journal entries also delete corresponding metadata entries #3468

Merged
merged 3 commits into from
Mar 13, 2019

Conversation

hirzraimund
Copy link
Contributor

When deleting persistence journal entries through the common sql implementation also delete the entries in the metadata table. This solves #3205 (violation of primary key constraint when the value already exists) and ensures that there exists at most one entry per PersistenceId value.

Added @ in front of the parameters for the DeleteBatchSql command to be in line with the other usage of AddParameter.

…ementation also delete the entries in the metadata table. This solves akkadotnet#3205 (violation of primary key constraint when the value already exists) and ensures that there exists at most one entry per PersistenceId value.
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.

Looks good to me. Do we have any specs to verify that the contents of this table have been cleaned up? cc @Horusiath

Copy link
Contributor

@Horusiath Horusiath left a comment

Choose a reason for hiding this comment

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

The main reason for the metadata table to exist in the first place is keep the information about the latest sequence number for given persistence id - so that we don't accidentally drop track of actor's sequence number when we decide to delete all events.

This PR in it's current implementation, defeats the whole purpose of having that table at all.

@Aaronontheweb
Copy link
Member

Good to know.

@hirzraimund
Copy link
Contributor Author

I am pretty sure that it still works as intended since in the methods AbstractQueryExecutor.DeleteBatchAsync and in BatchingSqlJournal.HandleDeleteMessagesTo , which are the only places where the delete query is used, the highest sequence number is insert into metadata table if it is inside the deleted range. The insert is done inside the same transaction as the delete and therefore it is ensured that both or none of these commands are executed.

@hirzraimund
Copy link
Contributor Author

@Horusiath

@Aaronontheweb
Copy link
Member

@hirzraimund @Horusiath I'll reopen the PR, but ya'll need to get to the bottom of what's really going on under the covers here before I close it again or merge it :p

Unit test it, IMHO.

@Aaronontheweb Aaronontheweb reopened this May 30, 2018
@ismaelhamed
Copy link
Member

ismaelhamed commented Jun 2, 2018

@Aaronontheweb @Horusiath @hirzraimund In the current state, maybe it should be advisable for plugins to resolve this with the proper upsert (i.e, a MERGE in Sql Server and Oracle).

Another option would be to get rid of the Metadata table all together, and make a soft delete on the last event instead (the jdbc plugin way). By keeping just the last event for reference, this keeps track of the highest sequence number in case the user cleans up the journal while remaining as an internal implementation detail.

@Horusiath
Copy link
Contributor

@ismaelhamed We could do a proper upsert in metadata table as a separate PR (only there, as event journal is append only). Regarding removal of Metadata table. It could be done' but I'm not sure if we wouldn't break backward compatibility this way.

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.

I'd like to see some sort of spec that covers this change in behavior; I'm sure we might already have one but I'd like to look it over before merging this.

@Aaronontheweb
Copy link
Member

LGTM

@Aaronontheweb Aaronontheweb merged commit b058e7d into akkadotnet:dev Mar 13, 2019
madmonkey pushed a commit to madmonkey/akka.net that referenced this pull request Jul 12, 2019
…ementation also delete the entries in the metadata table. This solves akkadotnet#3205 (violation of primary key constraint when the value already exists) and ensures that there exists at most one entry per PersistenceId value. (akkadotnet#3468)
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.

4 participants