Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database Lock Prevention #660

Merged
merged 17 commits into from
Dec 3, 2019
Merged

Conversation

groue
Copy link
Owner

@groue groue commented Dec 1, 2019

This pull request makes it possible to prevent acquisition of locks on a database.

It aims at providing the necessary ground-level work for the prevention of 0xdead10cc exception in iOS apps that store their database in the container on an App Group.

https://developer.apple.com/library/archive/technotes/tn2151/_index.html:

The exception code 0xdead10cc indicates that an application has been terminated by the OS because it held on to a file lock or sqlite database lock during suspension. If your application is performing operations on a locked file or sqlite database at suspension time, it must request additional background execution time to complete those operations and relinquish the lock before suspending.

We can thus prevent the 0xdead10cc exception if we can release and prevent locks between the notification that the additional background execution time is about to expire, and the end of the suspended state.

In this pull request, we only address the exclusive lock prevention itself, not its scheduling.

dbQueue.startPreventingLock() // or dbPool
dbQueue.stopPreventingLock()  // or dbPool

Those methods are public because they are defined on the DatabaseReader protocol. But they are not supposed to be used by the GRDB user. They won't be documented in the main README. They will be used by a future pull request which will target 0xdead10cc specifically.

Between startPreventingLock() and stopPreventingLock(), all database accesses may throw a DatabaseError of code SQLITE_INTERRUPT, or SQLITE_ABORT, except reads in WAL mode.


Update

The followup pull request #668 has changed the vocabulary used in this PR. We know talk about "suspended" databases, and the start/stop methods have been renamed, and made internal.

@groue groue changed the title Exclusive Lock Prevention Database Lock Prevention Dec 1, 2019
@groue groue merged commit 698dc26 into development Dec 3, 2019
@groue groue deleted the dev/startPreventingExclusiveLock branch December 3, 2019 18:08
@groue groue mentioned this pull request Dec 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant