Skip to content

Commit

Permalink
Only wrap PostgreSQL temp tables in transactions.
Browse files Browse the repository at this point in the history
Making SQLite temp tables inside transactions leads to very long
exclusive locks during QG generation, causing timeouts in (at least)
ci_cpp.
  • Loading branch information
TallJimbo committed Dec 15, 2022
1 parent 1cafa6d commit d56e250
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions python/lsst/daf/butler/registry/databases/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ def transaction(
cursor.execute("SET TIME ZONE 0")
yield is_new

@contextmanager
def temporary_table(
self, spec: ddl.TableSpec, name: Optional[str] = None
) -> Iterator[sqlalchemy.schema.Table]:
# Docstring inherited.
with self.transaction(for_temp_tables=True):
with super().temporary_table(spec, name) as table:
yield table

def _lockTables(
self, connection: sqlalchemy.engine.Connection, tables: Iterable[sqlalchemy.schema.Table] = ()
) -> None:
Expand Down
7 changes: 4 additions & 3 deletions python/lsst/daf/butler/registry/interfaces/_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,14 @@ def temporary_table(
otherwise, but in that case they probably need to be modified to
support the full range of expected read-only butler behavior.
"""
with self._transaction_connection(for_temp_tables=True) as connection:
table = self._make_temporary_table(connection, spec=spec, name=name)
with self.session():
assert self._session_connection is not None, "Guaranteed by session()."
table = self._make_temporary_table(self._session_connection, spec=spec, name=name)
self._temp_tables.add(table.key)
try:
yield table
finally:
table.drop(connection)
table.drop(self._session_connection)
self._temp_tables.remove(table.key)

@contextmanager
Expand Down

0 comments on commit d56e250

Please sign in to comment.