- Index
- »
- fan.sql
- »
- SqlConnPool
SqlConnPool
const class SqlConnPool : Obj
SqlConnPool manages a pool of reusable SQL connections
It-block construtor
autoCommit sets the autoCommit mode used by connections in the pool
Max time to block waiting for a connection to become available in the pool before raising TimeoutErr
Max time to wait when opening a new connection before raising TimeoutErr, or null to wait as long as the driver allows, which may be forever if the server stalls the handshake
How often the pool runs houseKeeping
How long an idle connection may sit before houseKeeping pings it, or null to never ping idle connections
Capture a stack trace at every checkout and include it in the
leakWarn warning
Time a connection may be held by an execute callback before a warning is logged that it may be stuck or leaked
Time to linger an idle connection before closing it
Logger
Max number of simultaneous connections to allow before blocking threads
Max lifetime of a connection before it is retired, regardless of how recently it was used
Connection password
Default timeout applied to every statement created on connections from this pool, or null for no timeout
Connection URI
Connection username
Ping a connection on checkout only if it has been idle at least this long, or null to never ping on checkout
Max time a liveness ping may take before the connection is treated as broken
Close all connections, stop houseKeeping, and raise exception on any new executes
Allocate a SQL connection inside the given callback
Return if close has been called
onClose is invoked just before a connection is closed by the pool
onOpen is invoked just after a connection is opened by the pool
Snapshot of the pool's gauges and cumulative counters
Bool : autoCommit
autoCommit sets the autoCommit mode used by connections in the pool. Applied when a connection is opened and restored when it is released, so a callback cannot leave the mode changed for the next borrower. Changing it at runtime takes effect per connection on its next release.
If auto-commit is true then each statement is executed and committed as an individual transaction. Otherwise statements are grouped into transaction which must be closed via SqlConn.commit or SqlConn.rollback.
const Duration : checkoutTimeout
Max time to block waiting for a connection to become available in the
pool before raising TimeoutErr. Opening a new connection is bounded
separately by connectTimeout.
Void close()
Close all connections, stop houseKeeping, and raise exception on any new executes
const Duration? : connectTimeout
Max time to wait when opening a new connection before raising TimeoutErr, or null to wait as long as the driver allows, which may be forever if the server stalls the handshake. Enforced by the driver via the 'connectTimeout' and 'socketTimeout' connection properties. JDBC resolves it in whole seconds; anything under a second is rounded up to one second.
Void execute(|SqlConn| f)
Allocate a SQL connection inside the given callback. If a connection cannot be acquired before checkoutTimeout elapses then a TimeoutErr is raised. Do not close the connection inside the callback.
const Duration : houseKeepingFreq
How often the pool runs houseKeeping: close connections idle past
linger, retire connections older than maxLifetime, ping idle
connections due a keepAlive, and warn about connections held past
leakWarn. Scheduled by the pool; callers do not drive it.
Bool isClosed()
Return if close has been called.
const Duration? : keepAliveFreq
How long an idle connection may sit before houseKeeping pings it, or
null to never ping idle connections. A failed ping evicts the
connection. Must be less than linger to have any effect. A ping
does not count as a use and does not defer linger.
const Bool : leakTrace
Capture a stack trace at every checkout and include it in the
leakWarn warning. Costs a stack fill per checkout, so it is off by
default.
const Duration : leakWarn
Time a connection may be held by an execute callback before a warning is logged that it may be stuck or leaked. The warning is logged once per checkout.
const Duration : linger
Time to linger an idle connection before closing it.
const Log : log
Logger
new make(|This|? f)
It-block construtor
const Int : maxConns
Max number of simultaneous connections to allow before blocking threads
const Duration : maxLifetime
Max lifetime of a connection before it is retired, regardless of how recently it was used. This protects against database and network infrastructure that kills long lived connections. Connections in use are never retired until released back to the pool.
virtual Void onClose(SqlConn c)
onClose is invoked just before a connection is closed by the pool.
virtual Void onOpen(SqlConn c)
onOpen is invoked just after a connection is opened by the pool.
const Str? : password
Connection password
const Duration? : queryTimeout
Default timeout applied to every statement created on connections from this pool, or null for no timeout. Restored when a connection is released, so a callback that changes the connection's timeout cannot leave it changed for the next borrower. Applies per execution, so a batch must complete within it. JDBC resolves it in whole seconds; anything under a second is rounded up to one second.
Str:Obj stats()
Snapshot of the pool's gauges and cumulative counters:
- total: Connections the pool holds, including slots still being opened
- active: Connections currently checked out. A slot reserved for a connection that is still opening counts here.
- idle: Connections available for checkout. A connection held by a keepAlive ping counts here.
- waiting: Threads blocked waiting for a connection
- maxConns: SqlConnPool.maxConns
- checkouts: Connections handed to an execute callback
- checkoutTimeouts: Checkouts that gave up after SqlConnPool.checkoutTimeout
- opened: Connections opened against the database
- retired: Connections closed for age: idle past SqlConnPool.linger, or older than SqlConnPool.maxLifetime
- evicted: Connections closed as broken: failed validation on checkout, failed after an execute callback raised, or failed a keepAlive ping
- leakWarnings: Warnings logged for connections held past SqlConnPool.leakWarn
const Str : uri
Connection URI
const Str? : username
Connection username
const Duration? : validateAfterIdle
Ping a connection on checkout only if it has been idle at least this long, or null to never ping on checkout. The ping costs a database round trip. Governs checkout only: a connection is always validated after an execute callback raises.
const Duration : validationTimeout
Max time a liveness ping may take before the connection is treated as broken. JDBC resolves this in whole seconds; anything under a second is rounded up to one second.