Sourcing::X::OptimisticLocked
Exception thrown when optimistic locking fails during event emission. Indicates that another process has modified the aggregate state since the expected version was read.
Attributes
| Attribute | Type | Description |
|---|---|---|
$.type | Mu:U | The aggregation type that failed to emit |
$.ids | Hash | The projection IDs of the aggregate instance |
$.expected-version | Int | The version the command expected |
$.actual-version | Int | The version actually found in the store |
Message
The exception message includes all context for debugging:
<sourcing optimistic locked: type=BankAccount, ids={:account-id(1)}, expected-version=2, actual-version=3>
When It's Thrown
- Inside the
is commandretry loop when a concurrent modification is detected - After all 5 retry attempts have been exhausted (re-thrown to the caller)
- When calling the version-checked
emitmethod directly with a stale version
Handling the Exception
try {
$account.withdraw(100);
CATCH {
when Sourcing::X::OptimisticLocked {
say "Concurrent modification detected";
say "Expected version: ", .expected-version;
say "Actual version: ", .actual-version;
# Retry manually or inform the user
}
}
}
See Also
- Optimistic Locking Concept — how concurrency control works
- Commands Concept — the automatic retry behavior
- Sourcing::Plugin::Memory — where the CAS check happens