Mark opportunities for snapshot creation failure (including #1383)

This commit is contained in:
Gwendal Roué committed 2023-06-01 17:26:04 +02:00
1 parent abd3ba39b1
commit cedcfbe330
2 files changed
+4

No files matched your search

+3
View File
@@ -669,6 +669,7 @@ extension DatabasePool: DatabaseReader {
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER && (compiler(>=5.7.1) || !(os(macOS) || targetEnvironment(macCatalyst))))
/// Returns a long-lived WAL snapshot transaction on a reader connection.
func walSnapshotTransaction() throws -> WALSnapshotTransaction {
// TODO #1383: might fail if wal file is truncated
guard let readerPool else {
throw DatabaseError.connectionIsClosed()
}
@@ -687,6 +688,7 @@ extension DatabasePool: DatabaseReader {
/// - important: The `completion` argument is executed in a serial
/// dispatch queue, so make sure you use the transaction asynchronously.
func asyncWALSnapshotTransaction(_ completion: @escaping (Result<WALSnapshotTransaction, Error>) -> Void) {
// TODO #1383: might fail if wal file is truncated
guard let readerPool else {
completion(.failure(DatabaseError.connectionIsClosed()))
return
@@ -904,6 +906,7 @@ extension DatabasePool {
/// if this method is called from a database access where a write
/// transaction is open.
public func makeSnapshotPool() throws -> DatabaseSnapshotPool {
// TODO #1383: might fail if wal file is truncated
try unsafeReentrantRead { db in
try DatabaseSnapshotPool(db)
}
+1
View File
@@ -186,6 +186,7 @@ public final class DatabaseSnapshotPool {
/// - configuration: A configuration.
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
public init(path: String, configuration: Configuration = Configuration()) throws {
// TODO #1383: might fail if wal file is truncated
var configuration = Self.configure(configuration)
// Acquire and hold WAL snapshot