MySQL 9.3.0
Source Code Documentation
destination_nodes_state_notifier.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2023, 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_ROUTING_INCLUDE_MYSQLROUTER_DESTINATION_NODES_STATE_NOTIFIER_H_
27#define ROUTER_SRC_ROUTING_INCLUDE_MYSQLROUTER_DESTINATION_NODES_STATE_NOTIFIER_H_
28
30
31#include <list>
32#include <mutex>
33#include <string>
34
36
37// first argument is the new set of the allowed nodes
38// second argument is a set of nodes that can be used for new connections
39// third argument is an indication whether we should disconnect existing
40// connections (based on disconnect_on_metadata_unavailable setting)
41// fourth argument is the description of the condition that triggered the change
42// (like 'metadata change' etc.) can be used for logging purposes by the caller
44 std::function<void(const AllowedNodes &, const AllowedNodes &, const bool,
45 const std::string &)>;
46// NOTE: this has to be container like std::list that does not invalidate
47// iterators when it is modified as we return the iterator to the inserted
48// callback to the caller to allow unregistering
49using AllowedNodesChangeCallbacksList = std::list<AllowedNodesChangedCallback>;
51 AllowedNodesChangeCallbacksList::iterator;
52// Starting a socket acceptor returns a value indicating if the start succeeded.
54 std::function<stdx::expected<void, std::string>()>;
55using StopSocketAcceptorCallback = std::function<void()>;
56// First callback argument informs if the instances returned from the metadata
57// has changed. Second argument is a list of new instances available after
58// md refresh.
60 std::function<void(const bool, const AllowedNodes &)>;
61// Callback argument is a destination we want to check, value returned is
62// true if the destination is quarantined, false otherwise.
64 std::function<bool(const mysql_harness::Destination &)>;
65
66/** @class DestinationNodesStateNotifier
67 *
68 * Allows the obervers to register for notifications on the change in the state
69 * of the destination nodes.
70 */
72 public:
73 virtual ~DestinationNodesStateNotifier() = default;
74
75 /** @brief Registers the callback for notification on the change in the
76 * state if the destination nodes.
77 *
78 * @param clb callback that should be called
79 * @return identifier of the inserted callback, can be used to unregister
80 * the callback
81 */
83 register_allowed_nodes_change_callback(
85
86 /** @brief Unregisters the callback registered with
87 * register_allowed_nodes_change_callback().
88 *
89 * @param it iterator returned by the call to
90 * register_allowed_nodes_change_callback()
91 */
92 void unregister_allowed_nodes_change_callback(
94
95 /**
96 * Registers the callback for notification that the routing socket acceptor
97 * should accept new connections.
98 *
99 * @param clb callback that should be called
100 */
101 void register_start_router_socket_acceptor(
102 const StartSocketAcceptorCallback &clb);
103
104 /**
105 * Unregisters the callback registered with
106 * register_start_router_socket_acceptor().
107 */
108 void unregister_start_router_socket_acceptor();
109
110 /**
111 * Registers the callback for notification that the routing socket acceptor
112 * should stop accepting new connections.
113 *
114 * @param clb callback that should be called
115 */
116 void register_stop_router_socket_acceptor(
117 const StopSocketAcceptorCallback &clb);
118
119 /**
120 * Unregisters the callback registered with
121 * register_stop_router_socket_acceptor().
122 */
123 void unregister_stop_router_socket_acceptor();
124
125 /**
126 * Registers a callback that is going to be used on metadata refresh
127 *
128 * @param callback Callback that will be called on each metadata refresh.
129 */
130 void register_md_refresh_callback(const MetadataRefreshCallback &callback);
131
132 /**
133 * Unregisters the callback registered with
134 * register_md_refresh_callback().
135 */
136 void unregister_md_refresh_callback();
137
138 /**
139 * Registers a callback that could be used for checking if the provided
140 * destination candidate is currently quarantined.
141 *
142 * @param clb Callback to query unreachable destinations.
143 */
144 void register_query_quarantined_destinations(
146
147 /**
148 * Unregisters the callback registered with
149 * register_query_quarantined_destinations().
150 */
151 void unregister_query_quarantined_destinations();
152
153 /**
154 * Specifies if the destination addresses can be added/removed from the set.
155 *
156 * NOTE: the sequence of nodes may change.
157 */
158 virtual bool is_dynamic();
159 virtual std::string get_dynamic_plugin_name();
160
161 protected:
168 mutable std::mutex md_refresh_callback_mtx_;
171};
172
173#endif // ROUTER_SRC_ROUTING_INCLUDE_MYSQLROUTER_DESTINATION_NODES_STATE_NOTIFIER_H_
Allows the obervers to register for notifications on the change in the state of the destination nodes...
Definition: destination_nodes_state_notifier.h:71
StartSocketAcceptorCallback start_router_socket_acceptor_callback_
Definition: destination_nodes_state_notifier.h:164
MetadataRefreshCallback md_refresh_callback_
Definition: destination_nodes_state_notifier.h:163
StopSocketAcceptorCallback stop_router_socket_acceptor_callback_
Definition: destination_nodes_state_notifier.h:165
std::mutex socket_acceptor_handle_callbacks_mtx
Definition: destination_nodes_state_notifier.h:169
QueryQuarantinedDestinationsCallback query_quarantined_destinations_callback_
Definition: destination_nodes_state_notifier.h:166
AllowedNodesChangeCallbacksList allowed_nodes_change_callbacks_
Definition: destination_nodes_state_notifier.h:162
std::mutex md_refresh_callback_mtx_
Definition: destination_nodes_state_notifier.h:168
std::mutex allowed_nodes_change_callbacks_mtx_
Definition: destination_nodes_state_notifier.h:167
std::mutex query_quarantined_destinations_callback_mtx_
Definition: destination_nodes_state_notifier.h:170
virtual ~DestinationNodesStateNotifier()=default
Definition: destination.h:95
std::function< void()> StopSocketAcceptorCallback
Definition: destination_nodes_state_notifier.h:55
std::function< stdx::expected< void, std::string >()> StartSocketAcceptorCallback
Definition: destination_nodes_state_notifier.h:54
std::function< void(const AllowedNodes &, const AllowedNodes &, const bool, const std::string &)> AllowedNodesChangedCallback
Definition: destination_nodes_state_notifier.h:45
AllowedNodesChangeCallbacksList::iterator AllowedNodesChangeCallbacksListIterator
Definition: destination_nodes_state_notifier.h:51
std::function< bool(const mysql_harness::Destination &)> QueryQuarantinedDestinationsCallback
Definition: destination_nodes_state_notifier.h:64
std::list< AllowedNodesChangedCallback > AllowedNodesChangeCallbacksList
Definition: destination_nodes_state_notifier.h:49
std::function< void(const bool, const AllowedNodes &)> MetadataRefreshCallback
Definition: destination_nodes_state_notifier.h:60
std::vector< AvailableDestination > AllowedNodes
Definition: destination_status_types.h:62
#define ROUTING_EXPORT
Definition: routing_export.h:15