26#ifndef MYSQLROUTER_CONNECTION_POOL_INCLUDED
27#define MYSQLROUTER_CONNECTION_POOL_INCLUDED
46#include "../../routing/src/ssl_mode.h"
56 : conn_{
std::move(conn)},
58 is_authenticated_{false},
59 endpoint_{conn_->endpoint()} {}
62 : conn_{
std::move(conn)},
64 is_authenticated_{true},
65 endpoint_{conn_->endpoint()} {}
72 std::unique_ptr<ConnectionBase> &
connection() {
return conn_; }
74 const std::unique_ptr<ConnectionBase> &
connection()
const {
return conn_; }
83 const Ssl &
ssl()
const {
return ssl_; }
91 void remover(std::function<
void()> remover) { remover_ = std::move(remover); }
120 void async_idle(std::chrono::milliseconds
idle_timeout);
125 void async_recv_message();
132 std::unique_ptr<ConnectionBase>
conn_;
141 bool is_authenticated_{
false};
156 std::optional<classic_protocol::message::server::Greeting>
158 SslMode ssl_mode, std::string username, std::string schema,
159 std::string attributes)
161 server_caps_{server_caps},
162 client_caps_{client_caps},
163 server_greeting_{
std::move(server_greeting)},
165 username_{
std::move(username)},
166 schema_{
std::move(schema)},
167 attributes_{
std::move(attributes)} {}
174 return server_caps_ & client_caps_;
179 return server_greeting_;
185 std::string
schema()
const {
return schema_; }
215 std::chrono::milliseconds idle_timeout)
216 : max_pooled_connections_(max_pooled_connections),
217 idle_timeout_(idle_timeout) {}
241 template <
class UnaryPredicate>
242 std::optional<connection_type>
pop_if(UnaryPredicate pred) {
245 &pred](
auto &pool) -> std::optional<ConnectionPool::connection_type> {
246 auto it = std::find_if(pool.begin(), pool.end(), pred);
248 if (it == pool.end())
return {};
250 auto pooled_conn = std::move(*it);
265 [[nodiscard]] uint32_t current_pooled_connections()
const;
268 return max_pooled_connections_;
272 return idle_timeout_;
283 void erase(container_type::iterator it);
std::vector< uint8_t, default_init_allocator< uint8_t > > recv_buffer_type
Definition: connection_base.h:47
connection pool of mysql connections.
Definition: connection_pool.h:210
ConnectionPool & operator=(const ConnectionPool &)=delete
~ConnectionPool()=default
uint32_t max_pooled_connections() const
Definition: connection_pool.h:267
std::chrono::milliseconds idle_timeout() const
Definition: connection_pool.h:271
const uint32_t max_pooled_connections_
Definition: connection_pool.h:285
std::list< connection_type > container_type
Definition: connection_pool.h:281
ConnectionPool(uint32_t max_pooled_connections, std::chrono::milliseconds idle_timeout)
Definition: connection_pool.h:214
uint64_t reused_connections() const
total number of reused connections.
Definition: connection_pool.h:278
const std::chrono::milliseconds idle_timeout_
Definition: connection_pool.h:286
ConnectionPool(ConnectionPool &&)=delete
ConnectionPool & operator=(ConnectionPool &&)=delete
std::optional< connection_type > pop_if(UnaryPredicate pred)
get a connection from the pool that matches a predicate.
Definition: connection_pool.h:242
ConnectionPool(const ConnectionPool &)=delete
Monitor pattern.
Definition: monitor.h:39
Definition: connection_pool.h:146
std::string attributes_
Definition: connection_pool.h:198
std::string schema_
Definition: connection_pool.h:197
PooledClassicConnection(std::unique_ptr< ConnectionBase > conn, Ssl ssl, caps_type server_caps, caps_type client_caps, std::optional< classic_protocol::message::server::Greeting > server_greeting, SslMode ssl_mode, std::string username, std::string schema, std::string attributes)
Definition: connection_pool.h:153
SslMode ssl_mode() const
Definition: connection_pool.h:182
std::string username_
Definition: connection_pool.h:196
PooledClassicConnection(std::unique_ptr< ConnectionBase > conn)
Definition: connection_pool.h:150
caps_type client_capabilities() const
Definition: connection_pool.h:169
std::optional< classic_protocol::message::server::Greeting > server_greeting() const
Definition: connection_pool.h:177
SslMode ssl_mode_
Definition: connection_pool.h:194
caps_type shared_capabilities() const
Definition: connection_pool.h:173
std::string schema() const
Definition: connection_pool.h:185
caps_type server_capabilities() const
Definition: connection_pool.h:171
classic_protocol::capabilities::value_type caps_type
Definition: connection_pool.h:148
std::optional< classic_protocol::message::server::Greeting > server_greeting_
Definition: connection_pool.h:192
std::string username() const
Definition: connection_pool.h:184
std::string attributes() const
Definition: connection_pool.h:186
pooled connection.
Definition: connection_pool.h:51
std::unique_ptr< ConnectionBase > & connection()
access to conn_.
Definition: connection_pool.h:72
Ssl ssl_
Definition: connection_pool.h:135
const std::unique_ptr< ConnectionBase > & connection() const
Definition: connection_pool.h:74
ConnectionBase::recv_buffer_type recv_buf_
Definition: connection_pool.h:138
PooledConnection(std::unique_ptr< ConnectionBase > conn)
Definition: connection_pool.h:55
PooledConnection(std::unique_ptr< ConnectionBase > conn, Ssl ssl)
Definition: connection_pool.h:61
Ssl & ssl()
access to ssl_.
Definition: connection_pool.h:81
mysql_harness::Ssl Ssl
Definition: connection_pool.h:53
bool is_authenticated() const
a pooled connection may be authenticated or not.
Definition: connection_pool.h:112
const Ssl & ssl() const
Definition: connection_pool.h:83
std::string endpoint_
Definition: connection_pool.h:143
std::function< void()> remover_
Definition: connection_pool.h:133
void remover(std::function< void()> remover)
set a remove-callback.
Definition: connection_pool.h:91
std::unique_ptr< ConnectionBase > conn_
Definition: connection_pool.h:132
std::string endpoint() const
Definition: connection_pool.h:114
#define CONNECTION_POOL_EXPORT
Definition: connection_pool_export.h:15
std::string HARNESS_EXPORT reset()
get 'reset attributes' ESC sequence.
Definition: vt100.cc:37
constexpr value_type ssl
Definition: classic_protocol_constants.h:49
std::bitset< 32 > value_type
Definition: classic_protocol_constants.h:73
std::unique_ptr< SSL, mysql_harness::impl::Deleter_SSL > Ssl
Definition: tls_types.h:48
static mysql_service_status_t add(reference_caching_channel channel, const char *implementation_name) noexcept
Definition: component.cc:135
Definition: gcs_xcom_synode.h:64
SslMode
Definition: ssl_mode.h:29