Aggregate not found in the event store

I recently enabled OpenTelemetry for an application. Something I noticed was that lots of errors started popping up related to CachingEventSourcingRepository.load:

The aggregate was not found in the event store

However, when looking at the regular error logging (Prometheus) these errors don’t seem to appear. I’m not sure whether this is an issue or not as the application seems to behave just fine. I was wondering how I could prevent these errors from popping up? Any thoughts?

Here’s the full stack trace as logged by OpenTelemetry:

at org.axonframework.eventsourcing.EventSourcingRepository.doLoadWithLock(
at org.axonframework.eventsourcing.CachingEventSourcingRepository.doLoadWithLock(
at org.axonframework.eventsourcing.CachingEventSourcingRepository.doLoadWithLock(
at org.axonframework.modelling.command.LockingRepository.doLoad(
at org.axonframework.modelling.command.LockingRepository.doLoad(
at org.axonframework.modelling.command.AbstractRepository.lambda$null$6(
at java.util.HashMap.computeIfAbsent(Unknown Source)
at org.axonframework.modelling.command.AbstractRepository.lambda$load$8(
at org.axonframework.tracing.Span.runSupplier(
at org.axonframework.modelling.command.AbstractRepository.load(
at org.axonframework.modelling.command.AggregateAnnotationCommandHandler$AggregateCommandHandler.handle(
at org.axonframework.modelling.command.AggregateAnnotationCommandHandler$AggregateCommandHandler.handle(
at org.axonframework.messaging.DefaultInterceptorChain.proceed(
at be.cegeka.vconsult.notification.infrastructure.axon.ExceptionWrappingHandlerInterceptor.handle(
at org.axonframework.messaging.DefaultInterceptorChain.proceed(
at org.axonframework.messaging.unitofwork.DefaultUnitOfWork.executeWithResult(
at org.axonframework.commandhandling.SimpleCommandBus.lambda$handle$3(
at org.axonframework.commandhandling.SimpleCommandBus.handle(
at org.axonframework.commandhandling.SimpleCommandBus.doDispatch(
at org.axonframework.commandhandling.SimpleCommandBus.dispatch(
at org.axonframework.extensions.jgroups.commandhandling.JGroupsConnector.processDispatchMessage(
at org.axonframework.extensions.jgroups.commandhandling.JGroupsConnector.lambda$receive$7(
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$ Source)
at Source)

Thanks in advance.

Seeing the stack trace, the exception is triggered by a command coming into your JGroupsConnector.
Whenever this catches an exception, it should wrap that as a reply to the node that dispatched the command.
So, perhaps straightforward, but have you checked the logs of your other instances?

Thanks for your response.
Meanwhile I found out why this error message appears in the traces and not in logs. It’s due to a bad legacy implementation that exists in the code base, which is not related to Axon. I have some refactoring ahead of me :wink:

1 Like

Maybe another question: is there a way to reliably know whether a particular aggregate exists before sending a command to it, given a JGroups distributed command bus scenario? Or whenever it doesn’t exist, somehow a create command can be sent before the actual command itself?

Perhaps we need to rethink how the aggregate needs to be created related to the current commands.

Ah, great that you’ve found the predicament!

I think the @CreationPolicy annotation is your best bet here, @JanVanRyswyck.
You can pair that annotation together with the @CommandHandler annotation, providing either of the following policies:

  3. NEVER

So, by annotating a command handler with @CreationPolicy(AggregateCreationPolicy.CREATE_IF_MISSING), the framework will construct the aggregate if an aggregate for the provided aggregate identifier does not exist.

Although this is a very powerful tool, it does come with a performance penalty.
Your Repository will need to check all the aggregate identifiers in the Event Store before it can be certain the provided identifier does not exist.
Hence, depending on the size of the store, a create-if-missing can be quick or slow.
Regardless of speed, the performance penalty is higher than knowing before hand that the aggregate does (not) exist.

Concluding, I think this will solve your predicament, @JanVanRyswyck. But, use this option with caution would be my recommendation.

Thx for the feedback Steven. I’m going to have a look a this.

1 Like