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

DeleteMessageFailure fails #3205

Closed
jalchr opened this issue Dec 2, 2017 · 3 comments
Closed

DeleteMessageFailure fails #3205

jalchr opened this issue Dec 2, 2017 · 3 comments

Comments

@jalchr
Copy link

jalchr commented Dec 2, 2017

Sometimes ... I get the following error. Why it is "inserting" on a delete operation ?

2017-12-02 13:25:24,757 [36] ERROR Archive.Video.Importer.Actors.FileHandler - [DeleteMessagesFailure]: shutting down !
System.Data.SqlClient.SqlException (0x80131904): Violation of PRIMARY KEY constraint 'PK_Metadata'. Cannot insert duplicate key in object 'dbo.Metadata'. The duplicate key value is (\\nas20\d$\archive\incoming\aptn\cctv025151_russia-scochinese premier.xml, 1).
The statement has been terminated.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption)
   at System.Data.SqlClient.SqlCommand.CompleteAsyncExecuteReader(Boolean isInternal, Boolean forDescribeParameterEncryption)
   at System.Data.SqlClient.SqlCommand.InternalEndExecuteNonQuery(IAsyncResult asyncResult, String endMethod, Boolean isInternal)
   at System.Data.SqlClient.SqlCommand.EndExecuteNonQueryInternal(IAsyncResult asyncResult)
   at System.Data.SqlClient.SqlCommand.EndExecuteNonQueryAsync(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Akka.Persistence.Sql.Common.Journal.AbstractQueryExecutor.<DeleteBatchAsync>d__49.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Akka.Persistence.Sql.Common.Journal.SqlJournal.<DeleteMessagesToAsync>d__49.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Akka.Util.Internal.AtomicState.<CallThrough>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Akka.Util.Internal.AtomicState.<CallThrough>d__8.MoveNext()
ClientConnectionId:18d2994b-b099-430e-adc4-4bf5c5ce5d08
Error Number:2627,State:1,Class:14
@Horusiath
Copy link
Contributor

When you're deleting an event journal history, there is a risk of loosing the last value of SequenceNr, which could potentially break a continuous history of your events. If this happens (usually when you clear event journal up to the current event), journal will store the last known SequenceNr for target persistence Id in a separate Metadata table.

This looks like a problem with SQL statement for that case, which should be insert or update, but (probably) is only insert right now.

hirzraimund added a commit to hirzraimund/akka.net that referenced this issue May 24, 2018
…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.
hirzraimund added a commit to hirzraimund/akka.net that referenced this issue May 24, 2018
…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.
@hirzraimund
Copy link
Contributor

I had the same problem and you are right, the existing update statement does only an insert. The easies solution which works on any SQL database is to delete the entries in metadata with the same where clause used for deleting the journal entries. This fix is implemented in my pull request.

@Aaronontheweb Aaronontheweb added this to the 1.3.12 milestone Mar 12, 2019
Aaronontheweb pushed a commit that referenced this issue Mar 13, 2019
…ementation 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. (#3468)
@Aaronontheweb
Copy link
Member

closed via #3468

madmonkey pushed a commit to madmonkey/akka.net that referenced this issue 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
Projects
None yet
Development

No branches or pull requests

4 participants