Fix incorrect aggregate version cached in DCB mode when using AxonServer#4463
Merged
smcvb merged 3 commits intoaxon-4.13.xfrom Apr 28, 2026
Merged
Fix incorrect aggregate version cached in DCB mode when using AxonServer#4463smcvb merged 3 commits intoaxon-4.13.xfrom
smcvb merged 3 commits intoaxon-4.13.xfrom
Conversation
…CB mode In a DCB context, AxonServer assigns sequence numbers globally at transaction commit time rather than per aggregate at event-apply time. As a result, the locally predicted sequence number on an aggregate does not match the value actually stored, causing stale or inconsistent state when the aggregate is later reconstructed from a cold cache. The fix registers a lazy supplier in the UnitOfWork during event appending. After commit, the CachingEventSourcingRepository calls the supplier to obtain the real server-assigned sequence and updates the cache entry accordingly. If a concurrent commit is detected the entry is removed to prevent stale data from being served. For non-DCB event stores the supplier is never registered and the existing behaviour is unchanged.
Several tests were leaving connection managers running after completion, causing background reconnection attempts to continue beyond the test lifetime. Added teardown to shut down the manager before the stub servers stop, so connections are closed cleanly in all cases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CachingEventSourcingRepositoryto cache the locally-predicted (wrong) version, leading to stale cache entries that would fail conflict detection on subsequent loads.COMMITTED_SEQUENCE_SUPPLIER_KEY_PREFIXUnitOfWork resource contract: after appending events,AxonServerEventStoreregisters a lazySupplier<Optional<Long>>on the root UoW per aggregate. InafterCommit,CachingEventSourcingRepositorycalls this supplier to obtain the actual server-assigned sequence number and replaces the cached entry.Optional.empty()(concurrent commit detected via message-id mismatch), the stale cache entry is evicted rather than left with an incorrect version.AxonServerConnectionManagerandConfigurationinstances are shut down in@AfterEach.