bolty-0.1.0.2: Haskell driver for Neo4j (BOLT protocol 4.4-5.4)
Safe HaskellNone
LanguageGHC2021

Database.Bolty.Pool

Description

Connection pooling with health-check validation and retry configuration.

Synopsis

Documentation

data BoltPool Source #

A pool of Neo4j connections with health-check and retry configuration.

data PoolConfig Source #

Configuration for the connection pool.

Constructors

PoolConfig 

Fields

defaultPoolConfig :: PoolConfig Source #

Default pool configuration: 10 max connections, 60 second idle timeout, 1 ping retry.

data ValidationStrategy Source #

Strategy for validating connections when they are checked out of the pool.

Constructors

AlwaysPing

Always send RESET before use (current default, safest).

PingIfIdle !Int

Only ping if the connection has been idle for more than N seconds. Connections used within the last N seconds are assumed healthy.

NeverPing

Skip health check entirely (fastest, use only in trusted environments).

data RetryConfig Source #

Configuration for retry logic on transient failures.

Constructors

RetryConfig 

Fields

  • maxRetries :: !Int

    Maximum number of retry attempts. Default: 5.

  • initialDelay :: !Int

    Initial delay in microseconds before first retry. Default: 200000 (200ms).

  • maxDelay :: !Int

    Maximum delay in microseconds between retries. Default: 5000000 (5s).

Instances

Instances details
Show RetryConfig Source # 
Instance details

Defined in Database.Bolty.Pool

Eq RetryConfig Source # 
Instance details

Defined in Database.Bolty.Pool

defaultRetryConfig :: RetryConfig Source #

Default retry configuration: 5 retries, 200ms initial delay, 5s max delay.

data PoolCounters Source #

Snapshot of pool-level counters.

Constructors

PoolCounters 

Fields

Instances

Instances details
Show PoolCounters Source # 
Instance details

Defined in Database.Bolty.Pool

Eq PoolCounters Source # 
Instance details

Defined in Database.Bolty.Pool

createPool :: HasCallStack => ValidatedConfig -> PoolConfig -> IO BoltPool Source #

Create a new connection pool. If the server advertises connection.recv_timeout_seconds, the pool's idle timeout is capped to min(configured, hint - 5) so connections are recycled before the server closes them.

destroyPool :: BoltPool -> IO () Source #

Destroy the pool, closing all connections.

withConnection :: HasCallStack => BoltPool -> (Connection -> IO a) -> IO a Source #

Acquire a healthy connection from the pool, run an action, then release it. Validates the connection using the configured ValidationStrategy. On connection failure during the action, discards the dead connection and retries once with a fresh one.

data CheckedOutConnection Source #

A checked-out connection handle, bundling the connection with its local pool reference for proper release.

acquireConnection :: BoltPool -> IO CheckedOutConnection Source #

Acquire a validated connection from the pool. The caller is responsible for releasing it with releaseConnection or releaseConnectionOnError.

This is the low-level primitive behind withConnection. Prefer withConnection for simple request-response patterns. Use acquireConnection when you need the connection to outlive a callback (e.g. for streaming with bracketIO).

releaseConnection :: CheckedOutConnection -> IO () Source #

Release a connection back to the pool after successful use.

releaseConnectionOnError :: CheckedOutConnection -> IO () Source #

Release a connection after an error, destroying it instead of returning it to the pool (since it may be in a bad state).

poolCounters :: BoltPool -> IO PoolCounters Source #

Read a snapshot of the pool's lifetime counters.