Skip to content

Commit

Permalink
When deleting persistence journal entries through the common sql impl…
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
hirzraimund authored and madmonkey committed Jul 12, 2019
1 parent 3a63456 commit b4527f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,9 @@ SELECT MAX(u.SeqNr) as SequenceNr
SELECT m.{conventions.SequenceNrColumnName} as SeqNr FROM {conventions.FullMetaTableName} m WHERE m.{conventions.PersistenceIdColumnName} = @PersistenceId) as u";

DeleteBatchSql = $@"
DELETE FROM {conventions.FullJournalTableName}
DELETE FROM {conventions.FullJournalTableName}
WHERE {conventions.PersistenceIdColumnName} = @PersistenceId AND {conventions.SequenceNrColumnName} <= @ToSequenceNr;
DELETE FROM {conventions.FullMetaTableName}
WHERE {conventions.PersistenceIdColumnName} = @PersistenceId AND {conventions.SequenceNrColumnName} <= @ToSequenceNr;";

UpdateSequenceNrSql = $@"
Expand Down Expand Up @@ -908,8 +910,8 @@ protected virtual async Task HandleDeleteMessagesTo(DeleteMessagesTo req, TComma

command.CommandText = DeleteBatchSql;
command.Parameters.Clear();
AddParameter(command, "PersistenceId", DbType.String, persistenceId);
AddParameter(command, "ToSequenceNr", DbType.Int64, toSequenceNr);
AddParameter(command, "@PersistenceId", DbType.String, persistenceId);
AddParameter(command, "@ToSequenceNr", DbType.Int64, toSequenceNr);

await command.ExecuteNonQueryAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ SELECT MAX(u.SeqNr) as SequenceNr
SELECT m.{Configuration.SequenceNrColumnName} as SeqNr FROM {Configuration.FullMetaTableName} m WHERE m.{Configuration.PersistenceIdColumnName} = @PersistenceId) as u";

DeleteBatchSql = $@"
DELETE FROM {Configuration.FullJournalTableName}
DELETE FROM {Configuration.FullJournalTableName}
WHERE {Configuration.PersistenceIdColumnName} = @PersistenceId AND {Configuration.SequenceNrColumnName} <= @ToSequenceNr;
DELETE FROM {Configuration.FullMetaTableName}
WHERE {Configuration.PersistenceIdColumnName} = @PersistenceId AND {Configuration.SequenceNrColumnName} <= @ToSequenceNr;";

UpdateSequenceNrSql = $@"
Expand Down

0 comments on commit b4527f3

Please sign in to comment.