MySQL 8.4.2
Source Code Documentation
ConnectionPool Class Reference

connection pool of mysql connections. More...

#include <connection_pool.h>

Classes

struct  Stashed
 connection on the stash. More...
 

Public Types

using ServerSideConnection = TlsSwitchableConnection< ServerSideClassicProtocolState >
 
using connection_type = PooledConnection< ServerSideConnection >
 
using ConnectionIdentifier = void *
 

Public Member Functions

 ConnectionPool (uint32_t max_pooled_connections, std::chrono::milliseconds idle_timeout)
 
 ConnectionPool (const ConnectionPool &)=delete
 
ConnectionPooloperator= (const ConnectionPool &)=delete
 
 ConnectionPool (ConnectionPool &&)=delete
 
ConnectionPooloperator= (ConnectionPool &&)=delete
 
 ~ConnectionPool ()=default
 
void add (ServerSideConnection conn)
 add a connection to the pool. More...
 
std::optional< ServerSideConnectionadd_if_not_full (ServerSideConnection conn)
 add connection to the pool if the poll isn't full. More...
 
std::optional< ServerSideConnectionpop_if (const std::string &ep, std::predicate< const ServerSideConnection & > auto pred)
 get a connection from the pool that matches a predicate. More...
 
uint32_t current_pooled_connections () const
 number of currently pooled connections. More...
 
uint32_t max_pooled_connections () const
 
std::chrono::milliseconds idle_timeout () const
 
void stash (ServerSideConnection conn, ConnectionIdentifier from, std::chrono::milliseconds delay)
 add a server-side connection to the stash. More...
 
void discard_all_stashed (ConnectionIdentifier from)
 
std::optional< ServerSideConnectionunstash_if (const std::string &ep, std::function< bool(const ServerSideConnection &)> pred, bool ignore_sharing_delay=false)
 
std::optional< ServerSideConnectionunstash_mine (const std::string &ep, ConnectionIdentifier conn_id)
 
size_t current_stashed_connections () const
 number of server-side connections on the stash. More...
 
uint64_t reused_connections () const
 total number of reused connections. More...
 

Protected Types

using pool_type = std::unordered_multimap< std::string, PooledConnection< ServerSideConnection > >
 
using stash_type = std::unordered_multimap< std::string, Stashed >
 

Protected Member Functions

void erase (pool_type::iterator it)
 
void erase_from_stash (stash_type::iterator it)
 

Protected Attributes

const uint32_t max_pooled_connections_
 
const std::chrono::milliseconds idle_timeout_
 
Monitor< pool_typepool_ {{}}
 
Monitor< stash_typestash_ {{}}
 
uint64_t reused_ {}
 

Detailed Description

connection pool of mysql connections.

It can contain connections:

  • classic protocol
  • to any tcp endpoint.

It has:

  • a pool, which contains server-side connections without a client-connection
  • a stash, which contains server-side connections with a client-connection

Member Typedef Documentation

◆ connection_type

◆ ConnectionIdentifier

◆ pool_type

using ConnectionPool::pool_type = std::unordered_multimap<std::string, PooledConnection<ServerSideConnection> >
protected

◆ ServerSideConnection

◆ stash_type

using ConnectionPool::stash_type = std::unordered_multimap<std::string, Stashed>
protected

Constructor & Destructor Documentation

◆ ConnectionPool() [1/3]

ConnectionPool::ConnectionPool ( uint32_t  max_pooled_connections,
std::chrono::milliseconds  idle_timeout 
)
inline

◆ ConnectionPool() [2/3]

ConnectionPool::ConnectionPool ( const ConnectionPool )
delete

◆ ConnectionPool() [3/3]

ConnectionPool::ConnectionPool ( ConnectionPool &&  )
delete

◆ ~ConnectionPool()

ConnectionPool::~ConnectionPool ( )
default

Member Function Documentation

◆ add()

void ConnectionPool::add ( ConnectionPool::ServerSideConnection  conn)

add a connection to the pool.

if the pool is full, the connection will be close.

◆ add_if_not_full()

std::optional< ConnectionPool::ServerSideConnection > ConnectionPool::add_if_not_full ( ConnectionPool::ServerSideConnection  conn)

add connection to the pool if the poll isn't full.

◆ current_pooled_connections()

uint32_t ConnectionPool::current_pooled_connections ( ) const

number of currently pooled connections.

◆ current_stashed_connections()

size_t ConnectionPool::current_stashed_connections ( ) const

number of server-side connections on the stash.

◆ discard_all_stashed()

void ConnectionPool::discard_all_stashed ( ConnectionIdentifier  from)

◆ erase()

void ConnectionPool::erase ( pool_type::iterator  it)
protected

◆ erase_from_stash()

void ConnectionPool::erase_from_stash ( stash_type::iterator  it)
protected

◆ idle_timeout()

std::chrono::milliseconds ConnectionPool::idle_timeout ( ) const
inline

◆ max_pooled_connections()

uint32_t ConnectionPool::max_pooled_connections ( ) const
inline

◆ operator=() [1/2]

ConnectionPool & ConnectionPool::operator= ( ConnectionPool &&  )
delete

◆ operator=() [2/2]

ConnectionPool & ConnectionPool::operator= ( const ConnectionPool )
delete

◆ pop_if()

std::optional< ServerSideConnection > ConnectionPool::pop_if ( const std::string &  ep,
std::predicate< const ServerSideConnection & > auto  pred 
)
inline

get a connection from the pool that matches a predicate.

Returns
a connection if one exists.

◆ reused_connections()

uint64_t ConnectionPool::reused_connections ( ) const
inline

total number of reused connections.

◆ stash()

void ConnectionPool::stash ( ServerSideConnection  conn,
ConnectionIdentifier  from,
std::chrono::milliseconds  delay 
)

add a server-side connection to the stash.

Parameters
connserver-side connection to be stashed.
fromopaque connection-identifier
delayallow sharing with other connection after 'delay' milliseconds.

◆ unstash_if()

std::optional< ConnectionPool::ServerSideConnection > ConnectionPool::unstash_if ( const std::string &  ep,
std::function< bool(const ServerSideConnection &)>  pred,
bool  ignore_sharing_delay = false 
)

◆ unstash_mine()

std::optional< ConnectionPool::ServerSideConnection > ConnectionPool::unstash_mine ( const std::string &  ep,
ConnectionIdentifier  conn_id 
)

Member Data Documentation

◆ idle_timeout_

const std::chrono::milliseconds ConnectionPool::idle_timeout_
protected

◆ max_pooled_connections_

const uint32_t ConnectionPool::max_pooled_connections_
protected

◆ pool_

Monitor<pool_type> ConnectionPool::pool_ {{}}
protected

◆ reused_

uint64_t ConnectionPool::reused_ {}
protected

◆ stash_

Monitor<stash_type> ConnectionPool::stash_ {{}}
protected

The documentation for this class was generated from the following files: