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

Same Event Applied Twice when Generating Aggregate Snapshot #1408

Closed
pmclellan opened this issue Apr 15, 2020 · 7 comments
Closed

Same Event Applied Twice when Generating Aggregate Snapshot #1408

pmclellan opened this issue Apr 15, 2020 · 7 comments
Assignees
Labels
Priority 1: Must Highest priority. A release cannot be made if this issue isn’t resolved. Status: Resolved Use to signal that work on this issue is done. Type: Bug Use to signal issues that describe a bug within the system.
Milestone

Comments

@pmclellan
Copy link

Hi,

I'm currently experiencing some unexpected behaviour related to aggregate snapshotting and I suspect it may be due to a bug.

I'm using the EventCountSnapshotTriggerDefinition to control when aggregate snapshots are created. This is working fine and snapshots are being triggered when required. However, when the AggregateSnapshotter constructs the snapshot event it publishes the most recent event twice. For example, if the event count threshold is set to 100 then the snapshotter will publish event 99 twice. In most cases this is not an issue. However, there are some events in my current implementation for which the handling is not idempotent and this is creating aggregates with an invalid state.

When I debug the snapshotting process I can see that the duplicate event is being added to the event stream when a call is made to AbstractEventBus.queuedMessages() This method returns a list of all events held by the current unit of work and its parents. In our case, the parent BatchingUnitOfWork and its child DefaultUnitOfWork both hold a reference to the same event, which leads to it being duplicated in the resultant list.

Please let me know if you require any further details regarding this issue.

Thanks,
Paul

@abuijze
Copy link
Member

abuijze commented Apr 15, 2020

Hi Paul,

thanks for the elaborate report. Since you mentioned the BatchingUnitOfWork and the DefaultUnitOfWork, am I correct in assuming you're using an in-process snapshotter? In other words, you did not configure an ExecutorService on the snapshotter?

@pmclellan
Copy link
Author

Hi Allard,

thanks for the prompt response. You're correct, we haven't specified an ExecutorService for the snapshotter. We're using the SpringAggregateSnapshotterFactoryBean with its default configuration.

@abuijze abuijze added Priority 1: Must Highest priority. A release cannot be made if this issue isn’t resolved. Type: Bug Use to signal issues that describe a bug within the system. labels Apr 15, 2020
@abuijze abuijze added this to the Release 4.3.2 milestone Apr 15, 2020
@abuijze
Copy link
Member

abuijze commented Apr 16, 2020

Hi Paul,

I'm unable to reproduce the problem on the master branch. Looking at the code, it seems that Axon already takes into account that some of the events in the "staged events" may overlap with what's returning from the Event Store, as these events may, or may not have been stored there yet.

Which version of Axon are you seeing this behavior on?

@pmclellan
Copy link
Author

pmclellan commented Apr 16, 2020

Hi,

we're currently using version 4.3. I think the problem we're seeing isn't due to an overlap between "staged events" and the contents of the event store, it's an overlap between the "staged events" held by units of work with a parent->child relationship. In our case the parent BatchingUnitOfWork and its child DefaultUnitOrWork hold the same staged event so the queuedMessages method is adding it to the list twice.

@smcvb smcvb added the Status: In Progress Use to signal this issue is actively worked on. label Apr 17, 2020
abuijze added a commit that referenced this issue Apr 21, 2020
Events are staged in a Unit of Work when they are published. However, when a Unit of Work is nested, committing a UoW, will stage the events in a parent UoW. When reading staged events during a commit, it is possible that staged events have already been promoted to the parent UoW and are then being read, causing duplicates.

This commit prevents the occurrence of duplicates when reading staged events from a Unit of Work.

Resolved issue #1408
@abuijze
Copy link
Member

abuijze commented Apr 21, 2020

Thanks for the clarification. I managed to find the culprit and resolved it in #1416

@abuijze abuijze added Status: Resolved Use to signal that work on this issue is done. and removed Status: In Progress Use to signal this issue is actively worked on. labels Apr 21, 2020
@pmclellan
Copy link
Author

Great! Thanks Allard.

@smcvb
Copy link
Member

smcvb commented Apr 22, 2020

Closing this issue as it has been resolved in pull request #1416.

@smcvb smcvb closed this as completed Apr 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority 1: Must Highest priority. A release cannot be made if this issue isn’t resolved. Status: Resolved Use to signal that work on this issue is done. Type: Bug Use to signal issues that describe a bug within the system.
Projects
None yet
Development

No branches or pull requests

3 participants