MySQL 9.1.0
Source Code Documentation
classic_connect.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTING_CLASSIC_CONNECT_INCLUDED
27#define ROUTING_CLASSIC_CONNECT_INCLUDED
28
29#include <chrono>
31#include "destination.h" // RouteDestination
35#include "processor.h"
36
38 public:
41 std::function<void(const classic_protocol::message::server::Error &err)>
42 on_error,
43 TraceEvent *parent_event)
44 : Processor(conn),
45 io_ctx_{conn->client_conn().connection()->io_ctx()},
46 destinations_{conn->current_destinations()},
48 on_error_(std::move(on_error)),
49 parent_event_(parent_event) {}
50
52
53 enum class Stage {
55 Resolve,
61 Connect,
64
65 Error,
66 Done,
67 };
68
70
72 [[nodiscard]] Stage stage() const { return stage_; }
73
74 bool is_destination_good(const std::string &hostname, uint16_t port) const;
75
76 private:
88
91
93
95
98
103
104 bool all_quarantined_{false};
105 std::error_code destination_ec_;
106
107 // stack of errors.
108 std::vector<std::pair<std::string, std::error_code>> connect_errors_;
109
110 std::function<void(const classic_protocol::message::server::Error &err)>
112
113 std::chrono::steady_clock::time_point connect_started_;
114
119};
120
121#endif
const MysqlRoutingClassicConnectionBase * connection() const
Definition: processor.h:78
Definition: classic_connect.h:37
stdx::expected< Processor::Result, std::error_code > init_endpoint()
Definition: classic_connect.cc:320
std::chrono::steady_clock::time_point connect_started_
Definition: classic_connect.h:113
net::ip::tcp::resolver::results_type endpoints_
Definition: classic_connect.h:101
stdx::expected< Processor::Result, std::error_code > error()
Definition: classic_connect.cc:1002
server_protocol_type::endpoint server_endpoint_
Definition: classic_connect.h:97
Stage
Definition: classic_connect.h:53
stdx::expected< Processor::Result, std::error_code > connect_finish()
Definition: classic_connect.cc:743
Destinations & destinations_
Definition: classic_connect.h:99
TraceEvent * trace_event_socket_from_pool_
Definition: classic_connect.h:118
stdx::expected< Processor::Result, std::error_code > init_destination()
Definition: classic_connect.cc:140
stdx::expected< Processor::Result, std::error_code > resolve()
Definition: classic_connect.cc:231
TraceEvent * trace_event_connect_
Definition: classic_connect.h:116
std::function< void(const classic_protocol::message::server::Error &err)> on_error_
Definition: classic_connect.h:111
stdx::expected< Processor::Result, std::error_code > from_pool()
Definition: classic_connect.cc:394
net::ip::tcp::resolver::results_type::iterator endpoints_it_
Definition: classic_connect.h:102
Stage stage_
Definition: classic_connect.h:92
bool all_quarantined_
Definition: classic_connect.h:104
void stage(Stage stage)
Definition: classic_connect.h:71
bool is_destination_good(const std::string &hostname, uint16_t port) const
Definition: classic_connect.cc:886
ConnectProcessor(MysqlRoutingClassicConnectionBase *conn, std::function< void(const classic_protocol::message::server::Error &err)> on_error, TraceEvent *parent_event)
Definition: classic_connect.h:39
std::vector< std::pair< std::string, std::error_code > > connect_errors_
Definition: classic_connect.h:108
stdx::expected< Processor::Result, std::error_code > connected()
Definition: classic_connect.cc:971
net::io_context & io_ctx_
Definition: classic_connect.h:94
stdx::expected< Processor::Result, std::error_code > init_connect()
Definition: classic_connect.cc:330
TraceEvent * parent_event_
Definition: classic_connect.h:115
Destinations::iterator destinations_it_
Definition: classic_connect.h:100
Stage stage() const
Definition: classic_connect.h:72
stdx::expected< Processor::Result, std::error_code > next_destination()
Definition: classic_connect.cc:903
stdx::expected< Processor::Result, std::error_code > process() override
Definition: classic_connect.cc:68
TraceEvent * trace_event_socket_connect_
Definition: classic_connect.h:117
std::error_code destination_ec_
Definition: classic_connect.h:105
net::ip::tcp::resolver resolver_
Definition: classic_connect.h:96
void assign_server_side_connection_after_pool(ConnectionPool::ServerSideConnection server_conn)
Definition: classic_connect.cc:364
stdx::expected< Processor::Result, std::error_code > next_endpoint()
Definition: classic_connect.cc:837
stdx::expected< Processor::Result, std::error_code > connect()
Definition: classic_connect.cc:564
A forward iterable container of destinations.
Definition: destination.h:107
typename container_type::iterator iterator
Definition: destination.h:111
Definition: classic_connection_base.h:56
a processor base class with helper functions.
Definition: processor.h:91
Definition: io_context.h:61
Definition: internet.h:678
Definition: internet.h:542
const_iterator iterator
Definition: internet.h:550
Definition: internet.h:608
TCP protocol.
Definition: internet.h:1155
Definition: expected.h:286
borrowable::message::server::Error< false > Error
Definition: classic_protocol_message.h:1411
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:908
const char * begin(const char *const c)
Definition: base64.h:44
Definition: gcs_xcom_synode.h:64
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:33
Definition: trace_span.h:35