Efcore: Microsoft.Data.Sqlite: BackupDatabase() should yield

Created on 13 Apr 2018  路  5Comments  路  Source: dotnet/efcore

Currently we call sqlite3_backup_step(backup, -1), but this will lock the database for the duration of the copy.

One of the main purposes of this API is to allow users to continue uninterrupted while a backup of the database is made.

To allow the backup to be made on a background thread while giving other threads opportunities to read, we should update it to step one page at a time and yield in between.

Unfortunately, this opens up the possibility of getting SQLITE_BUSY when stepping. This means we'll need to retry. The backup can even be automatically restarted. Which means it could take a very long time to complete. We'll need to think about timeouts and cancellation when we do this.

area-adonet-sqlite consider-for-current-release good first issue type-enhancement

Most helpful comment

Haha, make it next year. 馃ぃ

All 5 comments

What we currently have is useful when you want the copy done as quickly as possible. This is useful on UWP to export the database, or to save/load an in-memory database. But I don't think these scenarios would be degraded by yielding since there typically isn't concurrent access with them.

Triage: We decided to keep the existing method as is (no yielding), but to add additional methods/overloads for timeout, cancellation, and progress that yield.

Official SQLite documentation for reference: Using the SQLite Online Backup API.

I鈥檓 working on it, I hope to submit a pull request next week.

Haha, make it next year. 馃ぃ

Was this page helpful?
0 / 5 - 0 ratings