Lightweight 0.20260921.0
Loading...
Searching...
No Matches
Connection Pooling

A thread-safe pool of DataMapper instances, configured at compile time. More...

Classes

struct  Lightweight::PoolConfig
 
class  Lightweight::Pool< Config >
 
class  Lightweight::Pool< Config >::PooledDataMapper
 

Enumerations

enum class  Lightweight::GrowthStrategy : uint8_t { GrowthStrategy::BoundedWait , GrowthStrategy::BoundedOverflow , GrowthStrategy::UnboundedGrow }
 
enum class  Lightweight::ValidateOnBorrow : uint8_t { ValidateOnBorrow::No , ValidateOnBorrow::Yes }
 
enum class  Lightweight::PoolError : uint8_t { PoolError::Timeout }
 

Detailed Description

A thread-safe pool of DataMapper instances, configured at compile time.

The growth strategy, initial size and maximum size are supplied as a PoolConfig template parameter, so the policy is fixed at the type level rather than at runtime.

Enumeration Type Documentation

◆ GrowthStrategy

enum class Lightweight::GrowthStrategy : uint8_t
strong

Enum to define growth strategies of the pool

Enumerator
BoundedWait 

Pre-create initialSize objects. Allow the total count to grow up to maxSize. Once maxSize objects exist, callers BLOCK until one is returned.

BoundedOverflow 

Pre-create initialSize objects. The pool stores up to maxSize objects. If none are idle, a fresh object is ALWAYS created (no waiting). On return: kept if the idle set is below maxSize, otherwise destroyed.

UnboundedGrow 

Pre-create initialSize objects. Grow without limit. Every returned object is always kept in the pool.

Definition at line 37 of file Pool.hpp.

◆ ValidateOnBorrow

enum class Lightweight::ValidateOnBorrow : uint8_t
strong

Whether the pool checks that a connection is still live before handing it to a caller.

Enumerator
No 

Hand the connection out without checking it.

Yes 

Check SqlConnection::IsAlive() first and discard a connection reported dead, transparently serving the caller from the next idle connection or a freshly created one.

The check reads the driver-local SQL_ATTR_CONNECTION_DEAD attribute, so it costs no round trip to the server. By the same token it is only as good as the driver's own bookkeeping: several drivers mark a connection dead only after an operation has already failed, so a connection whose peer vanished silently (a firewall or NAT dropping the flow without sending FIN or RST) can still pass this check. Pair it with PoolConfig::maxIdleTimeMs to retire such connections before they are ever handed out.

Definition at line 57 of file Pool.hpp.

◆ PoolError

enum class Lightweight::PoolError : uint8_t
strong

Reason an Pool::Acquire call with a timeout failed to produce a data mapper.

Enumerator
Timeout 

The timeout elapsed before a data mapper became available.

Definition at line 76 of file Pool.hpp.