Skip to content

Commit

Permalink
fix deadlock handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lonvia committed Jul 28, 2024
1 parent e589f4e commit 65f863f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib-sql/indices.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CREATE INDEX IF NOT EXISTS idx_placex_geometry ON placex
-- Index is needed during import but can be dropped as soon as a full
-- geometry index is in place. The partial index is almost as big as the full
-- index.
---
DROP INDEX IF EXISTS idx_placex_geometry_lower_rank_ways;
---
CREATE INDEX IF NOT EXISTS idx_placex_geometry_reverse_lookupPolygon
Expand Down Expand Up @@ -60,7 +61,6 @@ CREATE INDEX IF NOT EXISTS idx_postcode_postcode
---
DROP INDEX IF EXISTS idx_placex_geometry_address_area_candidates;
DROP INDEX IF EXISTS idx_placex_geometry_buildings;
DROP INDEX IF EXISTS idx_placex_geometry_lower_rank_ways;
DROP INDEX IF EXISTS idx_placex_wikidata;
DROP INDEX IF EXISTS idx_placex_rank_address_sector;
DROP INDEX IF EXISTS idx_placex_rank_boundaries_sector;
Expand Down
8 changes: 8 additions & 0 deletions src/nominatim_db/db/query_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
class QueryPool:
""" Pool to run SQL queries in parallel asynchronous execution.
All queries are run in autocommit mode. If parallel execution leads
to a deadlock, then the query is repeated.
The results of the queries is discarded.
"""
def __init__(self, dsn: str, pool_size: int = 1, **conn_args: Any) -> None:
Expand Down Expand Up @@ -50,8 +52,14 @@ async def finish(self) -> None:
await asyncio.wait(self.pool)
self.wait_time += time.time() - tstart

for task in self.pool:
excp = task.exception()
if excp is not None:
raise excp


async def _worker_loop(self, dsn: str, **conn_args: Any) -> None:
conn_args['autocommit'] = True
aconn = await psycopg.AsyncConnection.connect(dsn, **conn_args)
async with aconn:
async with aconn.cursor() as cur:
Expand Down

0 comments on commit 65f863f

Please sign in to comment.