Skip to content

Commit

Permalink
Revert "Disable aggressive locking for read-only SQLite databases."
Browse files Browse the repository at this point in the history
This reverts commit fa5c840.
  • Loading branch information
TallJimbo committed Dec 14, 2022
1 parent b2761e7 commit 2dd5c7f
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions python/lsst/daf/butler/registry/databases/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ def _onSqlite3Connect(
cursor.execute("PRAGMA busy_timeout = 300000;") # in ms, so 5min (way longer than should be needed)


def _onSqlite3Begin(connection: sqlalchemy.engine.Connection) -> sqlalchemy.engine.Connection:
assert connection.dialect.name == "sqlite"
# Replace pysqlite's buggy transaction handling that never BEGINs with our
# own that does, and tell SQLite to try to acquire a lock as soon as we
# start a transaction (this should lead to more blocking and fewer
# deadlocks).
connection.execute(sqlalchemy.text("BEGIN IMMEDIATE"))
return connection


class SqliteDatabase(Database):
"""An implementation of the `Database` interface for SQLite3.
Expand Down Expand Up @@ -180,16 +190,6 @@ def creator() -> sqlite3.Connection:

engine = sqlalchemy.engine.create_engine(uri, creator=creator)

def _onSqlite3Begin(connection: sqlalchemy.engine.Connection) -> sqlalchemy.engine.Connection:
assert connection.dialect.name == "sqlite"
# Replace pysqlite's buggy transaction handling that never BEGINs
# with our own that does, and tell SQLite to try to acquire a lock
# as soon as we start a transaction (this should lead to more
# blocking and fewer deadlocks).
if writeable:
connection.execute(sqlalchemy.text("BEGIN IMMEDIATE"))
return connection

sqlalchemy.event.listen(engine, "connect", _onSqlite3Connect)
sqlalchemy.event.listen(engine, "begin", _onSqlite3Begin)

Expand Down

0 comments on commit 2dd5c7f

Please sign in to comment.