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

Database.Bolty.Routing

Description

Cluster-aware routing: automatic server discovery and failover for Neo4j causal clusters.

Synopsis

Routing table

getRoutingTable :: HasCallStack => Connection -> Maybe Text -> IO RoutingTable Source #

Fetch a routing table from the server. The connection must be in Ready state.

data RoutingTable Source #

A parsed routing table returned by the ROUTE message.

Constructors

RoutingTable 

Fields

  • ttl :: !Int64

    Seconds to cache this routing table.

  • db :: !Text

    Database name this routing table is for.

  • routers :: !(Vector Text)

    "host:port" addresses for ROUTE role.

  • readers :: !(Vector Text)

    "host:port" addresses for READ role.

  • writers :: !(Vector Text)

    "host:port" addresses for WRITE role.

Access mode

data AccessMode Source #

Access mode for routing: determines whether to use reader or writer servers.

Constructors

ReadAccess 
WriteAccess 

Instances

Instances details
Show AccessMode Source # 
Instance details

Defined in Database.Bolty.Routing

Eq AccessMode Source # 
Instance details

Defined in Database.Bolty.Routing

Routing pool

data RoutingPool Source #

A routing-aware connection pool that directs connections based on access mode.

data RoutingPoolConfig Source #

Configuration for a routing-aware connection pool.

Constructors

RoutingPoolConfig 

Fields

defaultRoutingPoolConfig :: RoutingPoolConfig Source #

Default routing pool configuration.

createRoutingPool :: ValidatedConfig -> RoutingPoolConfig -> IO RoutingPool Source #

Create a routing-aware connection pool. Connects to the seed address, fetches the initial routing table, and sets up per-address pools.

destroyRoutingPool :: RoutingPool -> IO () Source #

Destroy all per-address pools in the routing pool.

withRoutingConnection :: HasCallStack => RoutingPool -> AccessMode -> (Connection -> IO a) -> IO a Source #

Acquire a connection routed by access mode, run an action, then release. On connection failure, tries the next address in round-robin order until all addresses are exhausted.

acquireRoutingConnection :: HasCallStack => RoutingPool -> AccessMode -> IO CheckedOutConnection Source #

Acquire a routed connection by access mode. Returns a CheckedOutConnection that must be released by the caller. Tries addresses in round-robin order, failing over on unavailable servers.

withRoutingTransaction :: HasCallStack => RoutingPool -> AccessMode -> (Connection -> IO a) -> IO a Source #

Run a retrying transaction routed by access mode. Re-acquires routing table and connection on each retry attempt, so that routing errors (NotALeader) and transient errors trigger fresh routing.

invalidateRoutingTable :: RoutingPool -> IO () Source #

Invalidate the cached routing table, forcing a refresh on the next operation. Use this when a routing error (e.g. NotALeader) indicates the table is stale.

Internals (exported for testing)

parseAddress :: Text -> (Text, Word16) Source #

Parse "host:port" into (host, port). Falls back to default port 7687.