Skip to content
Snippets Groups Projects

Port to psycopg3

Closed Nicolas Dandrimont requested to merge olasd/swh-provenance:mr/psycopg3 into main
2 unresolved threads

Cc. @marmoute

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
35 35 self._db = Db(db)
36
37 # See comment below
38 self._db.cursor().execute("SET TIME ZONE 'UTC'")
39 36 else:
40 self._pool = psycopg2.pool.ThreadedConnectionPool(
41 min_pool_conns, max_pool_conns, db
37 self._pool = psycopg_pool.ConnectionPool(
38 conninfo=db,
39 min_size=min_pool_conns,
40 max_size=max_pool_conns,
41 open=False,
42 42 )
43 # Wait for the first connection to be ready, and raise the
44 # appropriate exception if connection fails
45 self._pool.open(wait=True, timeout=1)
  • Comment on lines +43 to +45

    Do we really need this here? Because the test does not seems to depends on it, and in most case we don't do it (e.g. the scheduler does it, but the storage don't).

    If we really want this, self._pool.wait() seems more appropriate (it open a bit more connections, but the semantic seems more appropriate), and we should consider doing it in all case too.

    (side note, this pattern of db/connection pool seems repeated in various places and could probably be factored out for consistency).

  • Maybe we should offer a wait function on the PostgresqlProvenance object itself to let the caller wait explicitly if the context warrants it?

  • Author Maintainer

    This is the only way to check whether the configuration of the database is correct or not (rather than have it deferred to the first postgresql access), so I think we should do that everywhere, yeah.

  • I just realized that the open=False is changing the behavior making it more needed. So I'll add it everywhere (in addition to open=False).

  • Author Maintainer

    Ah! Yeah, you're right. The problem with open=True was two-fold:

    • You get the default 30 second timeout even on the initial connection (which is probably okay to recover from transient issues, but not great for initial connection checking)
    • But open=True tells the /background/ workers to connect, so you need to call wait anyway if you want an exception on a badly configured connection (and you'll only get it after the 30s timeout)

    So creating the pool with open=False + an explicit open(wait=True, timeout=1) ended up being the best compromise.

  • I would lean toward using open=True to preserve what we are currently doing in the storage so far. Are you saying we need open=True and a call to wait to make sure we get a proper error?

  • Author Maintainer

    We want a short timeout on initialization then a longer timeout on operation, so we can't use open=True.

  • !199 (merged) should be ready now.

  • Please register or sign in to reply
  • Pierre-Yves David mentioned in merge request !199 (merged)

    mentioned in merge request !199 (merged)

  • Author Maintainer

    Closed in favor of !199 (merged)

  • Please register or sign in to reply
    Loading