MySQL 8.0.40
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 : Processor(conn),
44 io_ctx_{conn->socket_splicer()->client_conn().connection()->io_ctx()},
45 destinations_{conn->current_destinations()},
47 on_error_(std::move(on_error)) {}
48
50
51 enum class Stage {
53 Resolve,
59 Connect,
62
63 Error,
64 Done,
65 };
66
68
70 [[nodiscard]] Stage stage() const { return stage_; }
71
72 bool is_destination_good(const std::string &hostname, uint16_t port) const;
73
74 private:
86
88
90
93
98
99 bool all_quarantined_{false};
100 std::error_code destination_ec_;
101
102 // stack of errors.
103 std::vector<std::pair<std::string, std::error_code>> connect_errors_;
104
105 std::function<void(const classic_protocol::message::server::Error &err)>
107
108 std::chrono::steady_clock::time_point connect_started_;
109};
110
111#endif
const MysqlRoutingClassicConnectionBase * connection() const
Definition: processor.h:76
Definition: classic_connect.h:37
stdx::expected< Processor::Result, std::error_code > init_endpoint()
Definition: classic_connect.cc:267
std::chrono::steady_clock::time_point connect_started_
Definition: classic_connect.h:108
net::ip::tcp::resolver::results_type endpoints_
Definition: classic_connect.h:96
stdx::expected< Processor::Result, std::error_code > error()
Definition: classic_connect.cc:760
server_protocol_type::endpoint server_endpoint_
Definition: classic_connect.h:92
Stage
Definition: classic_connect.h:51
stdx::expected< Processor::Result, std::error_code > connect_finish()
Definition: classic_connect.cc:546
Destinations & destinations_
Definition: classic_connect.h:94
stdx::expected< Processor::Result, std::error_code > init_destination()
Definition: classic_connect.cc:134
stdx::expected< Processor::Result, std::error_code > resolve()
Definition: classic_connect.cc:182
std::function< void(const classic_protocol::message::server::Error &err)> on_error_
Definition: classic_connect.h:106
ConnectProcessor(MysqlRoutingClassicConnectionBase *conn, std::function< void(const classic_protocol::message::server::Error &err)> on_error)
Definition: classic_connect.h:39
stdx::expected< Processor::Result, std::error_code > from_pool()
Definition: classic_connect.cc:293
net::ip::tcp::resolver::results_type::iterator endpoints_it_
Definition: classic_connect.h:97
Stage stage_
Definition: classic_connect.h:87
bool all_quarantined_
Definition: classic_connect.h:99
void stage(Stage stage)
Definition: classic_connect.h:69
bool is_destination_good(const std::string &hostname, uint16_t port) const
Definition: classic_connect.cc:676
std::vector< std::pair< std::string, std::error_code > > connect_errors_
Definition: classic_connect.h:103
stdx::expected< Processor::Result, std::error_code > connected()
Definition: classic_connect.cc:740
net::io_context & io_ctx_
Definition: classic_connect.h:89
stdx::expected< Processor::Result, std::error_code > init_connect()
Definition: classic_connect.cc:277
Destinations::iterator destinations_it_
Definition: classic_connect.h:95
Stage stage() const
Definition: classic_connect.h:70
stdx::expected< Processor::Result, std::error_code > next_destination()
Definition: classic_connect.cc:693
stdx::expected< Processor::Result, std::error_code > process() override
Definition: classic_connect.cc:65
std::error_code destination_ec_
Definition: classic_connect.h:100
net::ip::tcp::resolver resolver_
Definition: classic_connect.h:91
stdx::expected< Processor::Result, std::error_code > next_endpoint()
Definition: classic_connect.cc:636
stdx::expected< Processor::Result, std::error_code > connect()
Definition: classic_connect.cc:374
A forward iterable container of destinations.
Definition: destination.h:97
typename container_type::iterator iterator
Definition: destination.h:101
Definition: classic_connection_base.h:221
a processor base class with helper functions.
Definition: processor.h:89
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:944
borrowable::message::server::Error< false > Error
Definition: classic_protocol_message.h:1399
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:910
Definition: gcs_xcom_synode.h:64
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:33