MySQL 9.3.0
Source Code Documentation
routing_simulator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, 2025, 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, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
19 * the GNU General Public License, version 2.0, 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 Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef ROUTER_SRC_ROUTING_GUIDELINES_SRC_ROUTING_SIMULATOR_H_
27#define ROUTER_SRC_ROUTING_GUIDELINES_SRC_ROUTING_SIMULATOR_H_
28
29#include <memory>
30#include <string>
31#include <string_view>
32#include <unordered_map>
33
34#ifdef RAPIDJSON_NO_SIZETYPEDEFINE
35#include "my_rapidjson_size_t.h"
36#endif
37
38#include <rapidjson/document.h>
39#include <rapidjson/error/en.h>
40
42#include "rpn.h"
43
44namespace routing_guidelines {
45
47 public:
48 explicit Routing_simulator(
49 rpn::Context *external_context = nullptr,
50 Routing_guidelines_engine::ResolveCache *external_cache = nullptr);
51
53
54 private:
55 stdx::expected<void, std::string> parse_router(const rapidjson::Document &d);
57 const rapidjson::Document &d, std::string_view expected_name);
59 const rapidjson::Document &d, std::string_view expected_name);
60 stdx::expected<void, std::string> parse_sql(const rapidjson::Document &d,
61 std::string_view expected_name);
62
63 std::unique_ptr<Routing_guidelines_engine> rpd_;
64
65 // External context + variables to keep it valid
72
73 // Tracking many destinations and sources
74 std::unordered_map<std::string, Server_info> destinations_;
75 std::string last_destination_;
76 std::unordered_map<int, Session_info> sources_;
77 int64_t last_source_{-1};
78};
79
80} // namespace routing_guidelines
81
82#endif // ROUTER_SRC_ROUTING_GUIDELINES_SRC_ROUTING_SIMULATOR_H_
std::unordered_map< std::string, net::ip::address > ResolveCache
Map with preprocessed resolved hostnames.
Definition: routing_guidelines.h:188
Definition: routing_simulator.h:46
std::unordered_map< std::string, Server_info > destinations_
Definition: routing_simulator.h:74
std::string last_destination_
Definition: routing_simulator.h:75
std::unordered_map< int, Session_info > sources_
Definition: routing_simulator.h:76
Session_info session_
Definition: routing_simulator.h:69
Routing_guidelines_engine::ResolveCache * external_cache_
Definition: routing_simulator.h:67
stdx::expected< void, std::string > parse_source(const rapidjson::Document &d, std::string_view expected_name)
Definition: routing_simulator.cc:224
stdx::expected< void, std::string > parse_sql(const rapidjson::Document &d, std::string_view expected_name)
Definition: routing_simulator.cc:289
Server_info server_
Definition: routing_simulator.h:71
int64_t last_source_
Definition: routing_simulator.h:77
Routing_simulator(rpn::Context *external_context=nullptr, Routing_guidelines_engine::ResolveCache *external_cache=nullptr)
Definition: routing_simulator.cc:37
std::unique_ptr< Routing_guidelines_engine > rpd_
Definition: routing_simulator.h:63
stdx::expected< void, std::string > parse_destination(const rapidjson::Document &d, std::string_view expected_name)
Definition: routing_simulator.cc:135
rpn::Context * external_context_
Definition: routing_simulator.h:66
stdx::expected< void, std::string > parse_router(const rapidjson::Document &d)
Definition: routing_simulator.cc:103
Sql_info sql_
Definition: routing_simulator.h:70
Router_info router_
Definition: routing_simulator.h:68
stdx::expected< void, std::string > process_document(const std::string &s)
Definition: routing_simulator.cc:42
Definition: expected.h:286
Define rapidjson::SizeType to be std::uint64_t.
Definition: routing_guidelines_datatypes.h:31
Information about this Router instance.
Definition: routing_guidelines.h:59
Information about one server destination.
Definition: routing_guidelines.h:80
Information about incoming session.
Definition: routing_guidelines.h:103
Information about query details.
Definition: routing_guidelines.h:117