MySQL 9.1.0
Source Code Documentation
forwarding_processor.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2023, 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_FORWARDING_PROCESSOR_INCLUDED
27#define ROUTING_CLASSIC_FORWARDING_PROCESSOR_INCLUDED
28
29#include <chrono>
30
33#include "processor.h"
34
35/**
36 * a processor base class with helper functions.
37 */
39 public:
40 using Processor::Processor;
41
42 /**
43 * interval between connect-retries.
44 */
45 static constexpr const std::chrono::milliseconds kConnectRetryInterval{
46 std::chrono::milliseconds(100)};
47
48 protected:
49 /**
50 * forward the current packet from the server-side to the client-side.
51 *
52 * use 'noflush' if the next message is from the server side too to allow
53 * merging of multiple server-side packets into one "send-to-client".
54 *
55 * Useful for resultsets which is split into multiple packets.
56 *
57 * Pushes a ServerToClientForwarder to the processor-stack.
58 *
59 * @param noflush if true, it isn't required to wait until the packet is sent
60 * to the client.
61 */
63 bool noflush = false);
64
65 /**
66 * forward the current packet from the client-side to the server-side.
67 *
68 * Pushes a ClientToServerForwarder to the processor-stack.
69 *
70 * @param noflush if true, it isn't required to wait until the packet is sent
71 * to the server.
72 */
74 bool noflush = false);
75
76 /**
77 * check of the capabilities of the source and the destination are the same
78 * for this message.
79 *
80 * @param src_protocol the source protocol state
81 * @param dst_protocol the destination protocol state
82 * @param msg the message that shall be forwarded
83 *
84 * @retval true if the msg can be forwarded as is.
85 */
86 template <class T>
88 ClassicProtocolState &dst_protocol,
89 const T &msg [[maybe_unused]]) {
91
92 return (src_protocol.shared_capabilities() & mask) ==
93 (dst_protocol.shared_capabilities() & mask);
94 }
95
96 /**
97 * adjust the end-of-columns packet.
98 *
99 * if source and destination don't have the same CLIENT_DEPRECATE_EOF, the Eof
100 * packet has to be add/removed between columns and rows.
101 *
102 * @param no_flush if the packet is forwarded, don't force a send as there is
103 * more data coming.
104 */
106 skip_or_inject_end_of_columns(bool no_flush = false);
107
108 /**
109 * move the server connection to the pool.
110 */
112
113 /**
114 * reconnect a socket.
115 *
116 * pushes a ConnectProcessor on the processor stack.
117 *
118 * when finished, a socket is established.
119 *
120 * @retval Result::Again on success.
121 */
123 TraceEvent *parent_event);
124
125 /**
126 * reconnect a mysql classic connection.
127 *
128 * pushes a LazyConnector on the processor stack.
129 *
130 * when finished, a mysql connection is authenticated.
131 */
133 TraceEvent *parent_event);
134
135 /**
136 * handle error-code of a failed receive() from the server-socket and check
137 * the status of the client socket.
138 */
141
142 /**
143 * send a Error msg based on the reconnect_error().
144 *
145 * @retval Result::SendToClient on success.
146 */
148 Channel &src_channel, ClassicProtocolState &src_protocol);
149
150 template <class Proto>
153 return reconnect_send_error_msg(conn.channel(), conn.protocol());
154 }
155
156 /**
157 * set the reconnect error.
158 *
159 * may be called from handlers.
160 */
162 reconnect_error_ = std::move(err);
163 }
164
165 /**
166 * get the reconnect error.
167 */
169 return reconnect_error_;
170 }
171
172 /**
173 * check if the error is a transient error.
174 */
175 static bool connect_error_is_transient(
177
178 private:
179 /**
180 * reconnect error set by lazy_reconnect_start().
181 */
183};
184
185#endif
SSL aware socket buffers.
Definition: channel.h:65
protocol state of a classic protocol connection.
Definition: classic_protocol_state.h:40
classic_protocol::capabilities::value_type shared_capabilities() const
Definition: classic_protocol_state.h:174
a processor base class with helper functions.
Definition: forwarding_processor.h:38
stdx::expected< Processor::Result, std::error_code > reconnect_send_error_msg(TlsSwitchableConnection< Proto > &conn)
Definition: forwarding_processor.h:151
void reconnect_error(classic_protocol::message::server::Error err)
set the reconnect error.
Definition: forwarding_processor.h:161
classic_protocol::message::server::Error reconnect_error() const
get the reconnect error.
Definition: forwarding_processor.h:168
stdx::expected< Processor::Result, std::error_code > mysql_reconnect_start(TraceEvent *parent_event)
reconnect a mysql classic connection.
Definition: forwarding_processor.cc:112
stdx::expected< Processor::Result, std::error_code > reconnect_send_error_msg(Channel &src_channel, ClassicProtocolState &src_protocol)
send a Error msg based on the reconnect_error().
Definition: forwarding_processor.cc:150
stdx::expected< Processor::Result, std::error_code > socket_reconnect_start(TraceEvent *parent_event)
reconnect a socket.
Definition: forwarding_processor.cc:100
static bool message_can_be_forwarded_as_is(ClassicProtocolState &src_protocol, ClassicProtocolState &dst_protocol, const T &msg)
check of the capabilities of the source and the destination are the same for this message.
Definition: forwarding_processor.h:87
stdx::expected< bool, std::error_code > pool_server_connection()
move the server connection to the pool.
Definition: forwarding_processor.cc:59
stdx::expected< Result, std::error_code > forward_client_to_server(bool noflush=false)
forward the current packet from the client-side to the server-side.
Definition: forwarding_processor.cc:51
classic_protocol::message::server::Error reconnect_error_
reconnect error set by lazy_reconnect_start().
Definition: forwarding_processor.h:182
static bool connect_error_is_transient(const classic_protocol::message::server::Error &err)
check if the error is a transient error.
Definition: forwarding_processor.cc:170
stdx::expected< Result, std::error_code > forward_server_to_client(bool noflush=false)
forward the current packet from the server-side to the client-side.
Definition: forwarding_processor.cc:43
stdx::expected< Processor::Result, std::error_code > skip_or_inject_end_of_columns(bool no_flush=false)
adjust the end-of-columns packet.
Definition: forwarding_processor.cc:176
static constexpr const std::chrono::milliseconds kConnectRetryInterval
interval between connect-retries.
Definition: forwarding_processor.h:45
stdx::expected< Result, std::error_code > recv_server_failed_and_check_client_socket(std::error_code ec)
handle error-code of a failed receive() from the server-socket and check the status of the client soc...
Definition: forwarding_processor.cc:124
a processor base class with helper functions.
Definition: processor.h:91
a Connection that can be switched to TLS.
Definition: connection_base.h:264
Channel & channel()
Definition: connection_base.h:359
protocol_state_type & protocol()
Definition: connection_base.h:398
Codec for a type.
Definition: classic_protocol_codec_base.h:72
Definition: expected.h:286
static mi_bit_type mask[]
Definition: mi_packrec.cc:141
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
Definition: trace_span.h:35