Skip to content

Commit

Permalink
adding more temporary debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivansete-status committed Sep 27, 2024
1 parent 73f1669 commit 67d6d43
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions waku/common/databases/db_postgres/pgasyncpool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ type
state: PgAsyncPoolState
conns: seq[PgDbConn]

proc `$`(self: PgDbConn): string =
if not isNil(self):
let adddr =
if not isNil(self.dbConn):
$cast[uint](addr(self.dbConn))
else:
"nil"
return
"dbConn: " & adddr & " " & (if self.open: "open " else: "closed ") &
(if self.busy: "busy" else: "free")
return "nil"

proc new*(T: type PgAsyncPool, dbUrl: string, maxConnections: int): DatabaseResult[T] =
var connString: string

Expand Down Expand Up @@ -158,14 +170,19 @@ proc pgQuery*(
let connIndex = (await pool.getConnIndex()).valueOr:
return err("connRes.isErr in query: " & $error)

debug "pgQuery", conns = $pool.conns

let queryStartTime = getNowInNanosecondTime()
let conn = pool.conns[connIndex].dbConn
defer:
pool.releaseConn(conn)
let queryDuration = getNowInNanosecondTime() - queryStartTime
if queryDuration > SlowQueryThresholdInNanoSeconds:
debug "pgQuery slow query",
query_duration_secs = (queryDuration / 1_000_000_000), query, requestId
query_duration_secs = (queryDuration / 1_000_000_000),
query,
requestId,
conns = $pool.conns

(await conn.dbConnQuery(sql(query), args, rowCallback, requestId)).isOkOr:
return err("error in asyncpool query: " & $error)
Expand All @@ -189,6 +206,8 @@ proc runStmt*(
## rowCallback != nil when it is expected to retrieve info from the database.
## rowCallback == nil for queries that change the database state.

debug "runStmt", conns = $pool.conns

let connIndex = (await pool.getConnIndex()).valueOr:
return err("Error in runStmt: " & $error)

Expand All @@ -202,7 +221,8 @@ proc runStmt*(
debug "runStmt slow query",
query_duration = queryDuration / 1_000_000_000,
query = stmtDefinition,
requestId
requestId,
conns = $pool.conns

if not pool.conns[connIndex].preparedStmts.contains(stmtName):
# The connection doesn't have that statement yet. Let's create it.
Expand Down

0 comments on commit 67d6d43

Please sign in to comment.