Database dispatch queues now have labels

This commit is contained in:
Gwendal Roué committed 2018-06-14 13:36:42 +02:00
1 parent 4e7fc83ad5
commit 2e80db8aed
5 files changed
+16 -9

No files matched your search

+6 -2
View File
@@ -47,7 +47,8 @@ public final class DatabasePool: DatabaseWriter {
writer = try SerializedDatabase(
path: path,
configuration: configuration,
schemaCache: SimpleDatabaseSchemaCache())
schemaCache: SimpleDatabaseSchemaCache(),
label: "GRDB.DatabasePool.Writer")
// Activate WAL Mode unless readonly
if !configuration.readonly {
@@ -77,11 +78,14 @@ public final class DatabasePool: DatabaseWriter {
readerConfig.readonly = true
readerConfig.defaultTransactionKind = .deferred // Make it the default for readers. Other transaction kinds are forbidden by SQLite in read-only connections.
readerConfig.allowsUnsafeTransactions = false // Because there's no guarantee that one can get the same reader in order to close its opened transaction.
var readerCount = 0
readerPool = Pool(maximumCount: configuration.maximumReaderCount, makeElement: { [unowned self] in
readerCount += 1 // protected by pool's ReadWriteBox (undocumented behavior and protection)
let reader = try SerializedDatabase(
path: path,
configuration: self.readerConfig,
schemaCache: SimpleDatabaseSchemaCache())
schemaCache: SimpleDatabaseSchemaCache(),
label: "GRDB.DatabasePool.Reader.\(readerCount)")
reader.sync { self.setupDatabase($0) }
return reader
})
+4 -2
View File
@@ -39,7 +39,8 @@ public final class DatabaseQueue: DatabaseWriter {
writer = try SerializedDatabase(
path: path,
configuration: configuration,
schemaCache: SimpleDatabaseSchemaCache())
schemaCache: SimpleDatabaseSchemaCache(),
label: "GRDB.DatabaseQueue")
}
/// Opens an in-memory SQLite database.
@@ -54,7 +55,8 @@ public final class DatabaseQueue: DatabaseWriter {
writer = try! SerializedDatabase(
path: ":memory:",
configuration: configuration,
schemaCache: SimpleDatabaseSchemaCache())
schemaCache: SimpleDatabaseSchemaCache(),
label: "GRDB.DatabaseQueue")
}
#if os(iOS)
+2 -1
View File
@@ -20,7 +20,8 @@ public class DatabaseSnapshot : DatabaseReader {
serializedDatabase = try SerializedDatabase(
path: path,
configuration: configuration,
schemaCache: SimpleDatabaseSchemaCache())
schemaCache: SimpleDatabaseSchemaCache(),
label: "GRDB.DatabaseSnapshot")
try serializedDatabase.sync { db in
// Assert WAL mode
+2 -2
View File
@@ -30,8 +30,8 @@ final class SchedulingWatchdog {
allowedDatabases = [database]
}
static func makeSerializedQueue(allowingDatabase database: Database) -> DispatchQueue {
let queue = DispatchQueue(label: "GRDB.SerializedDatabase")
static func makeSerializedQueue(allowingDatabase database: Database, label: String) -> DispatchQueue {
let queue = DispatchQueue(label: label)
let watchdog = SchedulingWatchdog(allowedDatabase: database)
queue.setSpecific(key: specificKey, value: watchdog)
return queue
+2 -2
View File
@@ -16,7 +16,7 @@ final class SerializedDatabase {
/// The dispatch queue
private let queue: DispatchQueue
init(path: String, configuration: Configuration = Configuration(), schemaCache: DatabaseSchemaCache) throws {
init(path: String, configuration: Configuration = Configuration(), schemaCache: DatabaseSchemaCache, label: String) throws {
// According to https://www.sqlite.org/threadsafe.html
//
// > SQLite support three different threading modes:
@@ -38,7 +38,7 @@ final class SerializedDatabase {
config.threadingMode = .multiThread
db = try Database(path: path, configuration: config, schemaCache: schemaCache)
queue = SchedulingWatchdog.makeSerializedQueue(allowingDatabase: db)
queue = SchedulingWatchdog.makeSerializedQueue(allowingDatabase: db, label: label)
self.path = path
try queue.sync {
try db.setup()