-
Notifications
You must be signed in to change notification settings - Fork 196
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
Sort events before applying them to aggregate #411
base: main
Are you sure you want to change the base?
Conversation
Hey, why the decision to do this manual kind of sorting instead of using the sort package? |
The idea is to take advantage of the event structure to improve performance because there was a concern about it. |
This reverts commit 9fbf958.
Add order to mongodb_v2 eventstore
Today we suffer in tests from this bug, so I take a new look into it. I reverted original solution and I provided now a new more modular one. Basically the mongodb_v2 implementation of the event store will warrant the event order. For other implementation, a EventSorter wrapper is provided that sort events got by |
I'm unfortunately not a maintainer, was just asking a question while browsing the repo. @maxekman needs to have a look at this. |
Description
When an aggregate is materialized, events are read from the event source. In the case of the MongoDB implementation, the way they are read does not guarrants the event order.
This change sort events before applying them.
Affected Components
Related Issues
#409
Solution and Design
Events are sorted by version number before being applied. Because version number is an integer between A and B, being A the first version read, and B the last, the sort uses the version position to insert in an slice of size B-A+1.
Solution was benchmarked:
Steps to test and verify
aggregatestore_sort_test.go was added.
You can also configure an aggregate with a MongoDB-2 event store.