MySQL 9.3.0
Source Code Documentation
endpoint_manager.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2021, 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,
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 ROUTER_SRC_REST_MRS_SRC_MRS_OBJECT_MANAGER_H_
27#define ROUTER_SRC_REST_MRS_SRC_MRS_OBJECT_MANAGER_H_
28
29#include <compare>
30#include <map>
31#include <memory>
32#include <vector>
33
35#include "mrs/configuration.h"
46#include "mrs/gtid_manager.h"
51#include "my_compiler.h"
52
53namespace mrs {
54
56 public:
57 using EntryKey = database::entry::EntryKey;
61 using EndpointBasePtr = std::shared_ptr<EndpointBase>;
63 using EndpointFactoryPtr = std::shared_ptr<EndpointFactory>;
67
68 class EndpointId {
69 public:
70 enum IdType {
78 };
79
80 public:
82
83 template <IdType p_type>
84 EndpointId(const UniversalId &p_id) : type{p_type}, id{p_id} {}
85
86 EndpointId(const IdType p_type, const UniversalId &p_id)
87 : type{p_type}, id{p_id} {}
88
90 MY_COMPILER_GCC_DIAGNOSTIC_IGNORE("-Wzero-as-null-pointer-constant")
91 MY_COMPILER_CLANG_DIAGNOSTIC_IGNORE("-Wzero-as-null-pointer-constant")
92 std::strong_ordering operator<=>(const EndpointId &rhs) const {
93 const auto cmp_res = type <=> rhs.type;
94 if (cmp_res != 0) return cmp_res;
95
96 return id <=> rhs.id;
97 }
99
100 public:
103 };
104
105 public:
106 EndpointManager(const std::shared_ptr<mrs::interface::EndpointConfiguration>
109 mrs::interface::AuthorizeManager *auth_manager,
110 mrs::GtidManager *gtid_manager,
111 EndpointFactoryPtr endpoint_factory = {},
112 ResponseCache *response_cache = {},
113 ResponseCache *file_cache = {},
114 SlowQueryMonitor *slow_query_monitor = {},
115 MysqlTaskMonitor *task_monitor = {});
116
117 void configure(const std::optional<std::string> &options) override;
118
119 void update(const std::vector<DbService> &services) override;
120 void update(const std::vector<DbSchema> &schemas) override;
121 void update(const std::vector<DbObject> &objs) override;
122 void update(const std::vector<UrlHost> &hosts) override;
123 void update(const std::vector<ContentSet> &set) override;
124 void update(const std::vector<ContentFile> &files) override;
125
126 void clear() override;
127
128 private:
129 // Keep shared ownership of Hosts.
130 std::map<UniversalId, EndpointBasePtr> hold_host_endpoints_;
131
132 // Lets keep all objects in weak ptrs:
133 std::map<EndpointId, std::weak_ptr<EndpointBase>> endpoints_;
134
135 // Essential objects
139 std::vector<std::shared_ptr<interface::RestHandler>> custom_paths_;
140 std::shared_ptr<EndpointFactory> endpoint_factory_;
141};
142
143} // namespace mrs
144
145#endif // ROUTER_SRC_REST_MRS_SRC_MRS_OBJECT_MANAGER_H_
Definition: mysql_cache_manager.h:87
Definition: endpoint_configuration.h:35
Definition: endpoint_manager.h:68
IdType type
Definition: endpoint_manager.h:101
EndpointId(const UniversalId &p_id)
Definition: endpoint_manager.h:84
UniversalId id
Definition: endpoint_manager.h:102
IdType
Definition: endpoint_manager.h:70
@ IdContentFile
Definition: endpoint_manager.h:76
@ IdService
Definition: endpoint_manager.h:73
@ IdUrlHost
Definition: endpoint_manager.h:72
@ IdObject
Definition: endpoint_manager.h:77
@ IdSchema
Definition: endpoint_manager.h:74
@ IdNone
Definition: endpoint_manager.h:71
@ IdContentSet
Definition: endpoint_manager.h:75
EndpointId()
Definition: endpoint_manager.h:81
EndpointId(const IdType p_type, const UniversalId &p_id)
Definition: endpoint_manager.h:86
Definition: endpoint_manager.h:55
mrs::database::MysqlTaskMonitor MysqlTaskMonitor
Definition: endpoint_manager.h:66
std::map< UniversalId, EndpointBasePtr > hold_host_endpoints_
Definition: endpoint_manager.h:130
void update(const std::vector< DbService > &services) override
Definition: endpoint_manager.cc:276
database::entry::EntryType EntryType
Definition: endpoint_manager.h:58
mrs::GtidManager * gtid_manager_
Definition: endpoint_manager.h:138
void clear() override
Definition: endpoint_manager.cc:321
void configure(const std::optional< std::string > &options) override
Definition: endpoint_manager.cc:97
std::map< EndpointId, std::weak_ptr< EndpointBase > > endpoints_
Definition: endpoint_manager.h:133
mrs::database::SlowQueryMonitor SlowQueryMonitor
Definition: endpoint_manager.h:65
std::shared_ptr< EndpointFactory > endpoint_factory_
Definition: endpoint_manager.h:140
std::shared_ptr< EndpointFactory > EndpointFactoryPtr
Definition: endpoint_manager.h:63
std::shared_ptr< EndpointBase > EndpointBasePtr
Definition: endpoint_manager.h:61
std::vector< std::shared_ptr< interface::RestHandler > > custom_paths_
Definition: endpoint_manager.h:139
database::entry::UniversalId UniversalId
Definition: endpoint_manager.h:59
collector::MysqlCacheManager * cache_
Definition: endpoint_manager.h:136
database::entry::EntryKey EntryKey
Definition: endpoint_manager.h:57
mrs::interface::AuthorizeManager * auth_manager_
Definition: endpoint_manager.h:137
Definition: gtid_manager.h:50
Definition: response_cache.h:64
Definition: mysql_task_monitor.h:41
Definition: slow_query_monitor.h:47
Definition: endpoint_factory.h:42
Definition: authorize_manager.h:58
Definition: endpoint_base.h:57
Definition: endpoint_manager.h:42
Header for compiler-dependent features.
#define MY_COMPILER_GCC_DIAGNOSTIC_IGNORE(X)
Definition: my_compiler.h:242
#define MY_COMPILER_DIAGNOSTIC_PUSH()
save the compiler's diagnostic (enabled warnings, errors, ...) state
Definition: my_compiler.h:277
#define MY_COMPILER_DIAGNOSTIC_POP()
restore the compiler's diagnostic (enabled warnings, errors, ...) state
Definition: my_compiler.h:278
Definition: cache_manager.h:33
EntryType
Definition: entry.h:36
collector::MysqlCacheManager MysqlCacheManager
Definition: handler_db_object_table.cc:266
mrs::interface::EndpointBase EndpointBase
Definition: handler_factory.cc:61
Definition: authorize_manager.h:48
mrs::ResponseCache ResponseCache
Definition: endpoint_manager.cc:73
EndpointManager::EndpointFactory EndpointFactory
Definition: endpoint_manager.cc:72
mrs::database::entry::UniversalId UniversalId
Definition: universal_id.h:33
Definition: options.cc:57
Definition: services.cc:40
Definition: gcs_xcom_synode.h:64
std::set< Key, Compare, ut::allocator< Key > > set
Specialization of set which uses ut_allocator.
Definition: ut0new.h:2884
MY_COMPILER_CLANG_DIAGNOSTIC_IGNORE("-Winconsistent-missing-destructor-override") static Scope_guard static_guard([]()
Definition: protobuf_plugin.cc:33
required string configuration
Definition: replication_asynchronous_connection_failover.proto:49