Class OptimisticConcurrencyRetryPolicy
- Namespace
- MailFathom.Application.Persistence
- Assembly
- MailFathom.Application.dll
Replays a safe local write after an optimistic concurrency conflict or a transient database failure.
public sealed class OptimisticConcurrencyRetryPolicy
- Inheritance
-
OptimisticConcurrencyRetryPolicy
- Inherited Members
Remarks
This policy is the only place where a conflict is an expected control-flow branch rather than a failure. Callers opt in by supplying a write that is idempotent and safe to repeat from a fresh read; once the configured attempts are exhausted the conflict leaves the policy as PersistenceConcurrencyConflictException so no intermediate use-case code has to restate it.
A database failure that can clear on its own is replayed by the same loop, wherever in the attempt it was raised — by a statement a write issued, by the save, or by the commit round trip. The unit of work is the only thing that can be repeated: a dropped connection takes its transaction with it, so nothing below this can retry a statement and nothing above this holds the staging body. It is the same attempt bound and the same backoff, for the same reason a caller already accepted — that this body may run more than once. The failure of the last allowed attempt leaves the policy as PersistenceTransientFailureException.
This is the one layer around a local write, which is what keeps the single layer of retry outbound resilience requires checkable: no database call runs under a resilience pipeline, and EF Core's own retrying execution strategy stays off.
Constructors
- OptimisticConcurrencyRetryPolicy(IPersistenceSessionFactory, PersistenceConcurrencyOptions, TimeProvider)
Initializes a retry policy from the deployment-wide concurrency bound.
Methods
- CommitAsync(Func<IPersistenceSession, CancellationToken, Task>, CancellationToken)
Stages and commits a complete local write in a fresh session for every attempt.
- CommitAsync<TResult>(Func<IPersistenceSession, CancellationToken, Task<TResult>>, CancellationToken)
Stages and commits a complete local write that answers with what it wrote.