1
votes

I am seeing the following error in Jonathon Oliver's EventStore :

ERROR: 23505: duplicate key value violates unique constraint "ix_commits_revisions"

Any ideas why this is happening?

1

1 Answers

5
votes

Assuming the index is as I googled it:

CREATE UNIQUE INDEX IX_Commits_Revisions ON Commits (
     StreamId, StreamRevision, Items);

Two Saves have written equivalent changes, which represents an optimistic concurrency violation.

Typically this would be converted by a Common Domain (or similar) layer to an EventStore ConcurrencyException.

The solution is to re-apply the Command against a fresh Load of the events in the stream.

If you are caching the IEventRepository, you shouldn't be as everyone with write access to the database can equally write into the event stream.

How do I know all this? The Readme documents in the NuGet package explain the basis behind this very clearly and you're stealing from yourself/your employer if you don't read and re-read them until you can work this out yourself!