Database.assertExclusiveLockPrevention mirrors assertNotInsideAbortedTransactionBlock

This commit is contained in:
Gwendal Roué committed 2019-12-01 18:34:51 +01:00
1 parent d1db8406f4
commit d85a7883bb
2 files changed
+19 -17

No files matched your search

+4 -14
View File
@@ -222,13 +222,8 @@ extension Database {
extension Database {
func executeUpdateStatement(_ statement: UpdateStatement) throws {
if preventsExclusiveLock.value && statement.createsExclusiveLock {
try? rollback()
throw DatabaseError(
resultCode: .SQLITE_ABORT,
message: "Can't acquire exclusive lock",
sql: statement.sql,
arguments: statement.arguments)
if statement.createsExclusiveLock {
try assertExclusiveLockPrevention(from: statement)
}
// In aborted transaction, forbid all statements but statements that
@@ -305,13 +300,8 @@ extension Database {
@inline(__always)
func selectStatementWillExecute(_ statement: SelectStatement) throws {
if preventsExclusiveLock.value && !statement.isReadonly {
try? rollback()
throw DatabaseError(
resultCode: .SQLITE_ABORT,
message: "Can't acquire exclusive lock",
sql: statement.sql,
arguments: statement.arguments)
if !statement.isReadonly {
try assertExclusiveLockPrevention(from: statement)
}
try assertNotInsideAbortedTransactionBlock(sql: statement.sql, arguments: statement.arguments)
+15 -3
View File
@@ -707,15 +707,27 @@ extension Database {
// - the rollback may fail, and a lock could remain.
//
// We work around this situation by issuing a rollback on next
// database access which requires an exclusive lock.
// See Database.executeUpdateStatement(_:) and
// Database.selectStatementWillExecute(_:).
// database access which requires an exclusive lock,
// in preventExclusiveLock(from:).
}
}
func stopPreventingExclusiveLock() {
preventsExclusiveLock.value = false
}
func assertExclusiveLockPrevention(from statement: Statement) throws {
if preventsExclusiveLock.value {
// Attempt at releasing eventual exclusive lock.
// See Database.startPreventingExclusiveLock()
try? rollback()
throw DatabaseError(
resultCode: .SQLITE_ABORT,
message: "Can't acquire exclusive lock",
sql: statement.sql,
arguments: statement.arguments)
}
}
}
extension Database {