Skip to content

Fix incorrect aggregate version cached in DCB mode when using AxonServer#4463

Merged
smcvb merged 3 commits intoaxon-4.13.xfrom
fix/4153-dcb-aggregate-cache-version
Apr 28, 2026
Merged

Fix incorrect aggregate version cached in DCB mode when using AxonServer#4463
smcvb merged 3 commits intoaxon-4.13.xfrom
fix/4153-dcb-aggregate-cache-version

Conversation

@abuijze
Copy link
Copy Markdown
Contributor

@abuijze abuijze commented Apr 25, 2026

Summary

  • In DCB mode, AxonServer assigns global sequence numbers at commit time rather than per-aggregate sequence numbers at event-apply time. This caused CachingEventSourcingRepository to cache the locally-predicted (wrong) version, leading to stale cache entries that would fail conflict detection on subsequent loads.
  • Introduced a COMMITTED_SEQUENCE_SUPPLIER_KEY_PREFIX UnitOfWork resource contract: after appending events, AxonServerEventStore registers a lazy Supplier<Optional<Long>> on the root UoW per aggregate. In afterCommit, CachingEventSourcingRepository calls this supplier to obtain the actual server-assigned sequence number and replaces the cached entry.
  • If the supplier returns Optional.empty() (concurrent commit detected via message-id mismatch), the stale cache entry is evicted rather than left with an incorrect version.
  • Also fixed resource leaks in several test classes by ensuring AxonServerConnectionManager and Configuration instances are shut down in @AfterEach.

abuijze added 3 commits April 25, 2026 19:56
…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.
@abuijze abuijze requested a review from smcvb April 25, 2026 19:37
@abuijze abuijze added this to the Release 4.13.1 milestone Apr 25, 2026
@smcvb smcvb added Type: Enhancement Use to signal an issue enhances an already existing feature of the project. Priority 1: Must Highest priority. A release cannot be made if this issue isn’t resolved. labels Apr 28, 2026
Copy link
Copy Markdown
Contributor

@smcvb smcvb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

@smcvb smcvb merged commit 2921ba7 into axon-4.13.x Apr 28, 2026
6 of 7 checks passed
@smcvb smcvb deleted the fix/4153-dcb-aggregate-cache-version branch April 28, 2026 08:40
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. Type: Enhancement Use to signal an issue enhances an already existing feature of the project.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants