Duplicate entry with Axon 2?

79 views
Skip to first unread message

Mellow Hide

unread,
Oct 18, 2016, 8:46:26 AM10/18/16
to Axon Framework Users
Hi,

we get an exception 'Duplicate entry' for key 'PRIMARY'.

I just thought this is not possible anymore with Axon 2 anymore. How can I solve that?

Thanks.



2016-10-18T14:28:03.60+0200 [App/0]      OUT Caused by: org.axonframework.eventstore.EventStoreException: Exception occurred while attempting to persist an event
2016-10-18T14:28:03.60+0200 [App/0]      OUT at org.axonframework.eventstore.jdbc.DefaultEventEntryStore.persistEvent(DefaultEventEntryStore.java:183)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at org.axonframework.eventstore.jdbc.JdbcEventStore.appendEvents(JdbcEventStore.java:159)
2016-10-18T14:28:03.60+0200 [App/0]      OUT ... 84 common frames omitted
2016-10-18T14:28:03.60+0200 [App/0]      OUT Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '045aab58-1467-4205-ad88-d43270ced362-614-Delivery' for key 'PRIMARY'
2016-10-18T14:28:03.60+0200 [App/0]      OUT at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at com.mysql.jdbc.Util.getInstance(Util.java:387)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:934)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5098)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994)
2016-10-18T14:28:03.60+0200 [App/0]      OUT at org.axonframework.eventstore.jdbc.DefaultEventEntryStore.persistEvent(DefaultEventEntryStore.java:181)
2016-10-18T14:28:03.60+0200 [App/0]      OUT ... 85 common frames omitted

Allard Buijze

unread,
Oct 18, 2016, 2:48:27 PM10/18/16
to Axon Framework Users
Hi,

even in Axon 2, there are a few cases in which this can happen. When an aggregate is being modified on two nodes simultaneously, both nodes may attempt to append the event with the same sequence number. Only the first will succeed. The second will fail with this exception.

The other scenario is when the underlying database (mysql is known to do this) uses a repeatable read isolation level by default. Mysql, for example, uses the state of the database at transaction start to return data in queries. So when the second thread waits for the aggregate to be released, and gets a green light, the database will not show any changes made by the other thread.

The solution to this is to configure the connection (pool) to use read committed instead of the default repeatable read.

Cheers,

Allard

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages