MySQL 9.0.0
Source Code Documentation
processor.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_PROCESSOR_INCLUDED
27#define ROUTING_CLASSIC_PROCESSOR_INCLUDED
28
30
31#include "trace_span.h"
32#include "tracer.h"
33
36
37/**
38 * base class of all the processors.
39 *
40 * Processor
41 *
42 * - have their own internal state
43 * - expose a process() function which will be called until
44 * it returns Result::Done
45 *
46 * Processors are stacked.
47 *
48 * The methods:
49 *
50 * - push_processor()
51 * - pop_processor()
52 *
53 * allow to add and remove elements for the stack.
54 *
55 * The top-most processor's process() function is called.
56 */
58 public:
59 enum class Result {
60 Again, // will invoke the process() of the top-most-processor
61 RecvFromClient, // wait for recv from client and invoke ...
62 SendToClient, // wait for send-to-client and invoke ...
63 RecvFromServer, // wait for recv from server and invoke ...
64 RecvFromBoth, // wait for recv from client and server and invoke ..
65 SendToServer, // wait for send-to-server and invoke ...
67
68 Suspend, // wait for explicit resume
69 Done, // pop this processor and invoke the top-most-processor's process()
70
71 Void,
72 };
73
75
76 virtual ~BasicProcessor() = default;
77
79
81
83
84 private:
86};
87
88/**
89 * a processor base class with helper functions.
90 */
91class Processor : public BasicProcessor {
92 public:
94
95 protected:
97 std::error_code ec);
98
100 std::error_code ec);
101
103 std::error_code ec);
104
106 std::error_code ec);
107
109 std::error_code ec);
110
112 std::error_code ec);
113
114 /**
115 * discard to current message.
116 *
117 * @pre ensure_full_frame() must true.
118 */
120 Channel &src_channel, ClassicProtocolState &src_protocol);
121
122 template <class Proto>
125 return discard_current_msg(conn.channel(), conn.protocol());
126 }
127
128 /**
129 * log a message with error-code as error.
130 */
131 static void log_fatal_error_code(const char *msg, std::error_code ec);
132
133 // see MysqlClassicConnection::trace()
134 [[deprecated(
135 "use 'if (auto &tr = tracer()) { tr.trace(...); } instead")]] void
137
138 Tracer &tracer();
139
140 /**
141 * start a span.
142 *
143 * @param parent_span parent span to nest this trace span in.
144 * @param prefix name of the span.
145 */
146 TraceEvent *trace_span(TraceEvent *parent_span,
147 const std::string_view &prefix);
148
149 /**
150 * end a span and set a status-code.
151 */
154
155 /**
156 * start a command span.
157 *
158 * @param prefix name of the command span.
159 */
160 TraceEvent *trace_command(const std::string_view &prefix);
161
162 /**
163 * start a connect-and-forward span.
164 */
166
167 /**
168 * start a connect span.
169 */
170 TraceEvent *trace_connect(TraceEvent *parent_span);
171
172 /**
173 * start a connect span.
174 */
176
177 /**
178 * start a forward span.
179 */
181
182 /**
183 * end a command span and set a status-code.
184 */
187};
188
189#endif
base class of all the processors.
Definition: processor.h:57
MysqlRoutingClassicConnectionBase * conn_
Definition: processor.h:85
virtual ~BasicProcessor()=default
MysqlRoutingClassicConnectionBase * connection()
Definition: processor.h:80
Result
Definition: processor.h:59
const MysqlRoutingClassicConnectionBase * connection() const
Definition: processor.h:78
BasicProcessor(MysqlRoutingClassicConnectionBase *conn)
Definition: processor.h:74
virtual stdx::expected< Result, std::error_code > process()=0
SSL aware socket buffers.
Definition: channel.h:65
protocol state of a classic protocol connection.
Definition: classic_protocol_state.h:39
Definition: classic_connection_base.h:56
a processor base class with helper functions.
Definition: processor.h:91
static void log_fatal_error_code(const char *msg, std::error_code ec)
log a message with error-code as error.
Definition: processor.cc:134
stdx::expected< Result, std::error_code > send_server_failed(std::error_code ec)
Definition: processor.cc:38
void trace_command_end(TraceEvent *event, TraceEvent::StatusCode status_code=TraceEvent::StatusCode::kUnset)
end a command span and set a status-code.
Definition: processor.cc:206
stdx::expected< Result, std::error_code > recv_client_failed(std::error_code ec)
Definition: processor.cc:67
stdx::expected< Result, std::error_code > client_socket_failed(std::error_code ec)
Definition: processor.cc:87
TraceEvent * trace_connect(TraceEvent *parent_span)
start a connect span.
Definition: processor.cc:181
TraceEvent * trace_command(const std::string_view &prefix)
start a command span.
Definition: processor.cc:160
void trace(Tracer::Event e)
Definition: processor.cc:139
stdx::expected< Result, std::error_code > recv_server_failed(std::error_code ec)
Definition: processor.cc:47
stdx::expected< Result, std::error_code > send_client_failed(std::error_code ec)
Definition: processor.cc:58
void trace_span_end(TraceEvent *event, TraceEvent::StatusCode status_code=TraceEvent::StatusCode::kUnset)
end a span and set a status-code.
Definition: processor.cc:152
stdx::expected< void, std::error_code > discard_current_msg(TlsSwitchableConnection< Proto > &conn)
Definition: processor.h:123
stdx::expected< Result, std::error_code > server_socket_failed(std::error_code ec)
Definition: processor.cc:78
TraceEvent * trace_span(TraceEvent *parent_span, const std::string_view &prefix)
start a span.
Definition: processor.cc:145
stdx::expected< void, std::error_code > discard_current_msg(Channel &src_channel, ClassicProtocolState &src_protocol)
discard to current message.
Definition: processor.cc:95
TraceEvent * trace_connect_and_forward_command(TraceEvent *parent_span)
start a connect-and-forward span.
Definition: processor.cc:171
void trace_set_connection_attributes(TraceEvent *ev)
start a connect span.
Definition: processor.cc:185
TraceEvent * trace_forward_command(TraceEvent *parent_span)
start a forward span.
Definition: processor.cc:202
Tracer & tracer()
Definition: processor.cc:143
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
Definition: tracer.h:61
traces the timestamps of events in a stderr log.
Definition: tracer.h:49
Definition: expected.h:284
required string event
Definition: replication_group_member_actions.proto:32
Definition: trace_span.h:35
StatusCode
Definition: trace_span.h:65