What causes the EventStore to throw the ConcurrencyException so easily?

Using JOliver EventStore 3.0 and just start with simple samples.

I have a simple pub / sub CQRS implementation using NServiceBus. The client sends commands on the bus, the domain server receives and processes the commands and stores events in the eventstore, which are then published on the bus by the eventstore dispatcher. the reader server then subscribes to these events to update the reader. Nothing fancy, pretty bookish.

It works, but only in simple tests I get a lot of concurrency exceptions (intermittently) on the domain server when the event is stored in the EventStore. It retries correctly, but sometimes it hits the 5 retry limit and the command ends up in an error queue.

Where can I start investigating to find out what is causing the concurrency exception? I remove the dispatcher and just focus on saving events and it has the same problem.

I am using RavenDB to save my EventStore. I don't do anything, just this:

using (var stream = eventStore.OpenStream(entityId, 0, int.MaxValue))
{
  stream.Add(new EventMessage { Body = myEvent });
  stream.CommitChanges(Guid.NewGuid());
}

      

The stack trace for the exception looks like this:

2012-03-17 18: 34: 01,166 [Work. 14] WARN NServiceBus.Unicast.UnicastBus [(null)] & ​​lt; (null)> - EmployeeCommandHandler failed to process message. EventStore.ConcurrencyException: Exception type The EventStore.ConcurrencyException event was thrown. at EventStore.OptimisticPipelineHook.PreCommit (attempted) at C: \ Code \ Public \ EventStore \ SRC \ projected \ EventStore.Core \ OptimisticPipelineHook.cs: line 55 on EventStore.OptimisticEventStore.Commit (attempted to commit) at C: \ Code \ Public \ EventStore \ SRC \ projected \ EventStore.Core \ OptimisticEventStore.cs: line 90 at EventStore.OptimisticEventStream.PersistChanges (Guid commitId) at C: \ Code \ Public \ EventStore \ SRC \ projected \ EventStore.Core \ OptimisticEventStream : line 168 on EventStore.OptimisticEventStream.CommitChanges (Guid commitId) in C:\ Code \ Public \ EventStore \ SRC \ projected \ EventStore.Core \ OptimisticEventStream.cs: line 149 at CQRSTest3.Domain.Extensions.StoreEvent (IStoreEvents eventStore, Guid entityId, Object evt) at C: \ dev \ test \ CQRSTest3 \ CQRSTest3 .Domain \ Extensions.cs: line 13 on CQRSTest3.Domain.ComandHandlers.EmployeeCommandHandler.Handle (ChangeEmployeeSalary message) in C: \ DEV \ test \ CQRSTest3 \ CQRSTest3.Domain \ ComandHandlers \ Emplo yeeCommandHandler.cs: line 55

+3


source to share


1 answer


I understood that. Had to dig in the source code to find it. I wish it were better documented! Here's my new eventstore:

EventStore = Wireup.Init()
          .UsingRavenPersistence("RavenDB")
          .ConsistentQueries()
          .InitializeStorageEngine()
          .Build();

      



I needed to add .ConsistentQueries () so that the raven constant duration provider would use WaitForNonStaleResults to search the event log that raven was doing.

Basically, when I add a new event and then try to add even before the raven had time to index, the stream update was not up to date. The second event will come first.

+10


source







All Articles