Faithlife / FaithlifeData

Helpers for querying ADO.NET-compatible databases.
https://faithlife.github.io/FaithlifeData/
MIT License
6 stars 4 forks source link

Support automatic deadlock retry #47

Open ejball opened 2 years ago

ejball commented 2 years ago

A RetryDbConnector could retry operations on transient and/or deadlock exceptions.

This would work well with ExecuteTransaction (#46) but not with BeginTransaction etc. Should RetryDbConnector.BeginTransaction throw?

The settings should integrate well with Polly, ideally without taking a dependency on it.

Expose a Retry(Async) method that allows the caller to create their own retry units?

We would probably need protected overrides on DbConnector to which command operations would delegate so that we can retry queries.

ejball commented 2 years ago

Retrying deadlocks can be done with the same IDbConnection, but retrying other transient errors necessitates a new IDbConnection, which is not something safely done automatically for anything but the first command, since there may be session state that needs to be retained.

ejball commented 2 years ago

Reducing the scope of this issue to retrying deadlocks. RetryDeadlockDbConnector (or RetryTransactionDbConnector?) might be a better name. Throwing on BeginTransaction would create a pit of success. Needs #46.