MySQL 9.2.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
routing_simulator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 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 also distributed with certain software (including
9 * but not limited to OpenSSL) that is licensed under separate terms, as
10 * 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 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License, version 2.0, for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef ROUTER_SRC_ROUTING_GUIDELINES_SRC_ROUTING_SIMULATOR_H_
25#define ROUTER_SRC_ROUTING_GUIDELINES_SRC_ROUTING_SIMULATOR_H_
26
27#include <memory>
28#include <string>
29#include <string_view>
30#include <unordered_map>
31
32#ifdef RAPIDJSON_NO_SIZETYPEDEFINE
33#include "my_rapidjson_size_t.h"
34#endif
35
36#include <rapidjson/document.h>
37#include <rapidjson/error/en.h>
38
40#include "rpn.h"
41
42namespace routing_guidelines {
43
45 public:
46 explicit Routing_simulator(
47 rpn::Context *external_context = nullptr,
48 Routing_guidelines_engine::ResolveCache *external_cache = nullptr);
49
51
52 private:
53 stdx::expected<void, std::string> parse_router(const rapidjson::Document &d);
55 const rapidjson::Document &d, std::string_view expected_name);
57 const rapidjson::Document &d, std::string_view expected_name);
58 stdx::expected<void, std::string> parse_sql(const rapidjson::Document &d,
59 std::string_view expected_name);
60
61 std::unique_ptr<Routing_guidelines_engine> rpd_;
62
63 // External context + variables to keep it valid
70
71 // Tracking many destinations and sources
72 std::unordered_map<std::string, Server_info> destinations_;
73 std::string last_destination_;
74 std::unordered_map<int, Session_info> sources_;
75 int64_t last_source_{-1};
76};
77
78} // namespace routing_guidelines
79
80#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:186
Definition: routing_simulator.h:44
std::unordered_map< std::string, Server_info > destinations_
Definition: routing_simulator.h:72
std::string last_destination_
Definition: routing_simulator.h:73
std::unordered_map< int, Session_info > sources_
Definition: routing_simulator.h:74
Session_info session_
Definition: routing_simulator.h:67
Routing_guidelines_engine::ResolveCache * external_cache_
Definition: routing_simulator.h:65
stdx::expected< void, std::string > parse_source(const rapidjson::Document &d, std::string_view expected_name)
Definition: routing_simulator.cc:222
stdx::expected< void, std::string > parse_sql(const rapidjson::Document &d, std::string_view expected_name)
Definition: routing_simulator.cc:287
Server_info server_
Definition: routing_simulator.h:69
int64_t last_source_
Definition: routing_simulator.h:75
Routing_simulator(rpn::Context *external_context=nullptr, Routing_guidelines_engine::ResolveCache *external_cache=nullptr)
Definition: routing_simulator.cc:35
std::unique_ptr< Routing_guidelines_engine > rpd_
Definition: routing_simulator.h:61
stdx::expected< void, std::string > parse_destination(const rapidjson::Document &d, std::string_view expected_name)
Definition: routing_simulator.cc:133
rpn::Context * external_context_
Definition: routing_simulator.h:64
stdx::expected< void, std::string > parse_router(const rapidjson::Document &d)
Definition: routing_simulator.cc:101
Sql_info sql_
Definition: routing_simulator.h:68
Router_info router_
Definition: routing_simulator.h:66
stdx::expected< void, std::string > process_document(const std::string &s)
Definition: routing_simulator.cc:40
Definition: expected.h:286
Define rapidjson::SizeType to be std::uint64_t.
Definition: routing_guidelines_datatypes.h:30
Information about this Router instance.
Definition: routing_guidelines.h:57
Information about one server destination.
Definition: routing_guidelines.h:78
Information about incoming session.
Definition: routing_guidelines.h:101
Information about query details.
Definition: routing_guidelines.h:115