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.
This PR adds a new
TableLockPolicy
enum to SQift to enable table lock error handling internally forexecute
,prepare
, andstep
operations.Problem Statement
Table lock errors are
SQLITE_ERROR
types thrown byexecute
,prepare
, andstep
operations. These errors can occur when the database is configured with a WAL journal mode as well as a shared cache. When one connection has obtained a lock on a table, another connection running on a different thread will receive table lock errors until the previous lock is released. In these situations, there are a couple of ways to proceed. The error can either be immediately thrown and handled by the client, or the calling thread can poll the operation until the lock is released.Solution
The
TableLockPolicy
defines two different ways to handle table lock errors. The first option is to poll on the calling thread at a specified interval until the lock is released. The other option is to immediately fast fail by throwing the table lock error as soon as it is encountered.Connection
,ConnectionPool
, andDatabase
types are set to.fastFail
by default.In order to enable polling for table lock errors, all that needs to be done is to set the policy in the
Connection
orDatabase
initializer.Testing
I've added as many tests as possible that reproduce the table lock error behavior. We've also been shipping these changes at scale in NRC and NTC over the past couple of months to ensure the
TableLockPolicy
does catch all the potential edge cases for table lock errors. We have now eliminated all the table lock errors in both apps and feel these changes are ready for release.