MySQL 8.0.40
Source Code Documentation
classic_lazy_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_LAZY_CONNECT_INCLUDED
27#define ROUTING_CLASSIC_LAZY_CONNECT_INCLUDED
28
29#include <system_error>
30
31#include "processor.h"
32
33/**
34 * attach a server connection and initialize it.
35 *
36 * - if a server-connection is attached to the client connection, leave.
37 * - otherwise,
38 * - if a connection can be taken from the pool, take it.
39 * - otherwise, connect to the server and authenticate.
40 * - set tracking session-vars
41 * - set the client's schema, if it differs from the server-connection's.
42 *
43 * Precondition:
44 *
45 * - the client's cleartext password must be known.
46 */
47class LazyConnector : public Processor {
48 public:
49 /**
50 * create a lazy-connector.
51 *
52 * @param conn a connection handle
53 * @param in_handshake if true, the client connection is in Greeting or
54 * ChangeUser right now.
55 * @param on_error function that's called if an error happened.
56 *
57 * If "in_handshake" the LazyConnector may ask the client for a
58 * "auth-method-switch" or a "plaintext-password".
59 */
61 MysqlRoutingClassicConnectionBase *conn, bool in_handshake,
62 std::function<void(const classic_protocol::message::server::Error &err)>
63 on_error)
64 : Processor(conn),
65 in_handshake_{in_handshake},
66 on_error_(std::move(on_error)) {}
67
68 enum class Stage {
69 Connect,
72 SetVars,
80
81 Done,
82 };
83
85
87 [[nodiscard]] Stage stage() const { return stage_; }
88
89 private:
101
103
105
106 std::function<void(const classic_protocol::message::server::Error &err)>
108};
109
110#endif
attach a server connection and initialize it.
Definition: classic_lazy_connect.h:47
stdx::expected< Processor::Result, std::error_code > authenticated()
Definition: classic_lazy_connect.cc:241
stdx::expected< Processor::Result, std::error_code > set_vars_done()
Definition: classic_lazy_connect.cc:340
stdx::expected< Processor::Result, std::error_code > connected()
the handshake part.
Definition: classic_lazy_connect.cc:191
stdx::expected< Processor::Result, std::error_code > set_server_option_done()
Definition: classic_lazy_connect.cc:368
stdx::expected< Processor::Result, std::error_code > process() override
Definition: classic_lazy_connect.cc:133
stdx::expected< Processor::Result, std::error_code > fetch_sys_vars_done()
Definition: classic_lazy_connect.cc:410
std::function< void(const classic_protocol::message::server::Error &err)> on_error_
Definition: classic_lazy_connect.h:107
stdx::expected< Processor::Result, std::error_code > set_schema_done()
Definition: classic_lazy_connect.cc:432
Stage stage_
Definition: classic_lazy_connect.h:102
stdx::expected< Processor::Result, std::error_code > set_schema()
Definition: classic_lazy_connect.cc:415
bool in_handshake_
Definition: classic_lazy_connect.h:104
stdx::expected< Processor::Result, std::error_code > fetch_sys_vars()
Definition: classic_lazy_connect.cc:374
stdx::expected< Processor::Result, std::error_code > set_server_option()
Definition: classic_lazy_connect.cc:346
Stage stage() const
Definition: classic_lazy_connect.h:87
Stage
Definition: classic_lazy_connect.h:68
stdx::expected< Processor::Result, std::error_code > connect()
Definition: classic_lazy_connect.cc:164
void stage(Stage stage)
Definition: classic_lazy_connect.h:86
stdx::expected< Processor::Result, std::error_code > set_vars()
Definition: classic_lazy_connect.cc:289
LazyConnector(MysqlRoutingClassicConnectionBase *conn, bool in_handshake, std::function< void(const classic_protocol::message::server::Error &err)> on_error)
create a lazy-connector.
Definition: classic_lazy_connect.h:60
Definition: classic_connection_base.h:221
a processor base class with helper functions.
Definition: processor.h:89
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