MySQL 8.3.0
Source Code Documentation
forwarding_processor.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2023, 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 also distributed 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 included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#ifndef ROUTING_CLASSIC_FORWARDING_PROCESSOR_INCLUDED
26#define ROUTING_CLASSIC_FORWARDING_PROCESSOR_INCLUDED
27
28#include <chrono>
29
31#include "processor.h"
32
33/**
34 * a processor base class with helper functions.
35 */
37 public:
38 using Processor::Processor;
39
40 /**
41 * interval between connect-retries.
42 */
43 static constexpr const std::chrono::milliseconds kConnectRetryInterval{
44 std::chrono::milliseconds(100)};
45
46 protected:
47 /**
48 * forward the current packet from the server-side to the client-side.
49 *
50 * use 'noflush' if the next message is from the server side too to allow
51 * merging of multiple server-side packets into one "send-to-client".
52 *
53 * Useful for resultsets which is split into multiple packets.
54 *
55 * Pushes a ServerToClientForwarder to the processor-stack.
56 *
57 * @param noflush if true, it isn't required to wait until the packet is sent
58 * to the client.
59 */
61 bool noflush = false);
62
63 /**
64 * forward the current packet from the client-side to the server-side.
65 *
66 * Pushes a ClientToServerForwarder to the processor-stack.
67 *
68 * @param noflush if true, it isn't required to wait until the packet is sent
69 * to the server.
70 */
72 bool noflush = false);
73
74 /**
75 * check of the capabilities of the source and the destination are the same
76 * for this message.
77 *
78 * @param src_protocol the source protocol state
79 * @param dst_protocol the destination protocol state
80 * @param msg the message that shall be forwarded
81 *
82 * @retval true if the msg can be forwarded as is.
83 */
84 template <class T>
86 ClassicProtocolState *dst_protocol,
87 const T &msg [[maybe_unused]]) {
89
90 return (src_protocol->shared_capabilities() & mask) ==
91 (dst_protocol->shared_capabilities() & mask);
92 }
93
94 /**
95 * adjust the end-of-columns packet.
96 *
97 * if source and destination don't have the same CLIENT_DEPRECATE_EOF, the Eof
98 * packet has to be add/removed between columns and rows.
99 *
100 * @param no_flush if the packet is forwarded, don't force a send as there is
101 * more data coming.
102 */
104 skip_or_inject_end_of_columns(bool no_flush = false);
105
106 /**
107 * move the server connection to the pool.
108 */
110
111 /**
112 * reconnect a socket.
113 *
114 * pushes a ConnectProcessor on the processor stack.
115 *
116 * when finished, a socket is established.
117 *
118 * @retval Result::Again on success.
119 */
121 TraceEvent *parent_event);
122
123 /**
124 * reconnect a mysql classic connection.
125 *
126 * pushes a LazyConnector on the processor stack.
127 *
128 * when finished, a mysql connection is authenticated.
129 */
131 TraceEvent *parent_event);
132
133 /**
134 * handle error-code of a failed receive() from the server-socket and check
135 * the status of the client socket.
136 */
139
140 /**
141 * send a Error msg based on the reconnect_error().
142 *
143 * @retval Result::SendToClient on success.
144 */
146 Channel *src_channel, ClassicProtocolState *src_protocol);
147
148 /**
149 * set the reconnect error.
150 *
151 * may be called from handlers.
152 */
154 reconnect_error_ = std::move(err);
155 }
156
157 /**
158 * get the reconnect error.
159 */
161 return reconnect_error_;
162 }
163
164 /**
165 * check if the error is a transient error.
166 */
167 static bool connect_error_is_transient(
169
170 private:
171 /**
172 * reconnect error set by lazy_reconnect_start().
173 */
175};
176
177#endif
SSL aware socket buffers.
Definition: channel.h:63
protocol state of a classic protocol connection.
Definition: classic_connection_base.h:54
classic_protocol::capabilities::value_type shared_capabilities() const
Definition: classic_connection_base.h:89
a processor base class with helper functions.
Definition: forwarding_processor.h:36
void reconnect_error(classic_protocol::message::server::Error err)
set the reconnect error.
Definition: forwarding_processor.h:153
classic_protocol::message::server::Error reconnect_error() const
get the reconnect error.
Definition: forwarding_processor.h:160
stdx::expected< Processor::Result, std::error_code > mysql_reconnect_start(TraceEvent *parent_event)
reconnect a mysql classic connection.
Definition: forwarding_processor.cc:138
stdx::expected< Processor::Result, std::error_code > socket_reconnect_start(TraceEvent *parent_event)
reconnect a socket.
Definition: forwarding_processor.cc:126
stdx::expected< bool, std::error_code > pool_server_connection()
move the server connection to the pool.
Definition: forwarding_processor.cc:84
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:50
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:178
classic_protocol::message::server::Error reconnect_error_
reconnect error set by lazy_reconnect_start().
Definition: forwarding_processor.h:174
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:198
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:85
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:42
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:204
static constexpr const std::chrono::milliseconds kConnectRetryInterval
interval between connect-retries.
Definition: forwarding_processor.h:43
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:150
a processor base class with helper functions.
Definition: processor.h:90
Codec for a type.
Definition: classic_protocol_codec_base.h:71
Definition: expected.h:943
static mi_bit_type mask[]
Definition: mi_packrec.cc:140
borrowable::message::server::Error< false > Error
Definition: classic_protocol_message.h:1410
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:926
Definition: trace_span.h:34