MySQL 9.3.0
Source Code Documentation
classic_connect.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 2025, 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" // DestinationManager
37#include "processor.h"
38
40 public:
43 std::function<void(const classic_protocol::message::server::Error &err)>
44 on_error,
45 TraceEvent *parent_event)
46 : Processor(conn),
47 io_ctx_{conn->client_conn().connection()->io_ctx()},
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 mysql_harness::Destination &dest) const;
75
76 private:
88
91
93
95
98
99 std::unique_ptr<Destination> destination_{nullptr};
100
101 std::vector<mysql_harness::DestinationEndpoint> endpoints_;
102 std::vector<mysql_harness::DestinationEndpoint>::iterator endpoints_it_;
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:39
stdx::expected< Processor::Result, std::error_code > init_endpoint()
Definition: classic_connect.cc:309
std::chrono::steady_clock::time_point connect_started_
Definition: classic_connect.h:113
stdx::expected< Processor::Result, std::error_code > error()
Definition: classic_connect.cc:1055
Stage
Definition: classic_connect.h:53
stdx::expected< Processor::Result, std::error_code > connect_finish()
Definition: classic_connect.cc:792
TraceEvent * trace_event_socket_from_pool_
Definition: classic_connect.h:118
mysql_harness::DestinationEndpoint server_endpoint_
Definition: classic_connect.h:97
std::unique_ptr< Destination > destination_
Definition: classic_connect.h:99
bool is_destination_good(const mysql_harness::Destination &dest) const
Definition: classic_connect.cc:923
stdx::expected< Processor::Result, std::error_code > init_destination()
Definition: classic_connect.cc:127
stdx::expected< Processor::Result, std::error_code > resolve()
Definition: classic_connect.cc:215
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:387
std::vector< mysql_harness::DestinationEndpoint >::iterator endpoints_it_
Definition: classic_connect.h:102
Stage stage_
Definition: classic_connect.h:92
std::vector< mysql_harness::DestinationEndpoint > endpoints_
Definition: classic_connect.h:101
bool all_quarantined_
Definition: classic_connect.h:104
void stage(Stage stage)
Definition: classic_connect.h:71
ConnectProcessor(MysqlRoutingClassicConnectionBase *conn, std::function< void(const classic_protocol::message::server::Error &err)> on_error, TraceEvent *parent_event)
Definition: classic_connect.h:41
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:1016
net::io_context & io_ctx_
Definition: classic_connect.h:94
stdx::expected< Processor::Result, std::error_code > init_connect()
Definition: classic_connect.cc:319
TraceEvent * parent_event_
Definition: classic_connect.h:115
Stage stage() const
Definition: classic_connect.h:72
stdx::expected< Processor::Result, std::error_code > next_destination()
Definition: classic_connect.cc:941
stdx::expected< Processor::Result, std::error_code > process() override
Definition: classic_connect.cc:53
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:356
stdx::expected< Processor::Result, std::error_code > next_endpoint()
Definition: classic_connect.cc:880
stdx::expected< Processor::Result, std::error_code > connect()
Definition: classic_connect.cc:576
Definition: classic_connection_base.h:57
a processor base class with helper functions.
Definition: processor.h:91
Definition: destination_endpoint.h:38
Definition: destination.h:95
Definition: io_context.h:61
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:905
Definition: gcs_xcom_synode.h:64
Definition: trace_span.h:35