MySQL 26.10.0
Source Code Documentation
destination_nodes_state_notifier.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2023, 2026, 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// Refreshing a socket acceptor returns whether the refresh succeeded.
54 std::function<stdx::expected<void, std::string>()>;
55// First callback argument informs if the instances returned from the metadata
56// has changed. Second argument is a list of new instances available after
57// md refresh.
59 std::function<void(const bool, const AllowedNodes &)>;
60// Callback argument is a destination we want to check, value returned is
61// true if the destination is quarantined, false otherwise.
63 std::function<bool(const mysql_harness::Destination &)>;
64
65/** @class DestinationNodesStateNotifier
66 *
67 * Allows the obervers to register for notifications on the change in the state
68 * of the destination nodes.
69 */
71 public:
72 virtual ~DestinationNodesStateNotifier() = default;
73
74 /** @brief Registers the callback for notification on the change in the
75 * state if the destination nodes.
76 *
77 * @param clb callback that should be called
78 * @return identifier of the inserted callback, can be used to unregister
79 * the callback
80 */
82 register_allowed_nodes_change_callback(
84
85 /** @brief Unregisters the callback registered with
86 * register_allowed_nodes_change_callback().
87 *
88 * @param it iterator returned by the call to
89 * register_allowed_nodes_change_callback()
90 */
91 void unregister_allowed_nodes_change_callback(
93
94 /**
95 * Registers the callback for notification that the routing socket acceptor
96 * state may need to be refreshed.
97 *
98 * @param clb callback that should be called
99 */
100 void register_refresh_router_socket_acceptor_state(
102
103 /**
104 * Unregisters the callback registered with
105 * register_refresh_router_socket_acceptor_state().
106 */
107 void unregister_refresh_router_socket_acceptor_state();
108
109 /**
110 * Registers a callback that is going to be used on metadata refresh
111 *
112 * @param callback Callback that will be called on each metadata refresh.
113 */
114 void register_md_refresh_callback(const MetadataRefreshCallback &callback);
115
116 /**
117 * Unregisters the callback registered with
118 * register_md_refresh_callback().
119 */
120 void unregister_md_refresh_callback();
121
122 /**
123 * Registers a callback that could be used for checking if the provided
124 * destination candidate is currently quarantined.
125 *
126 * @param clb Callback to query unreachable destinations.
127 */
128 void register_query_quarantined_destinations(
130
131 /**
132 * Unregisters the callback registered with
133 * register_query_quarantined_destinations().
134 */
135 void unregister_query_quarantined_destinations();
136
137 /**
138 * Specifies if the destination addresses can be added/removed from the set.
139 *
140 * NOTE: the sequence of nodes may change.
141 */
142 virtual bool is_dynamic();
143 virtual std::string get_dynamic_plugin_name();
144
145 protected:
152 mutable std::mutex md_refresh_callback_mtx_;
155};
156
157#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:70
MetadataRefreshCallback md_refresh_callback_
Definition: destination_nodes_state_notifier.h:147
RefreshSocketAcceptorStateCallback refresh_router_socket_acceptor_state_callback_
Definition: destination_nodes_state_notifier.h:149
std::mutex socket_acceptor_handle_callbacks_mtx
Definition: destination_nodes_state_notifier.h:153
QueryQuarantinedDestinationsCallback query_quarantined_destinations_callback_
Definition: destination_nodes_state_notifier.h:150
AllowedNodesChangeCallbacksList allowed_nodes_change_callbacks_
Definition: destination_nodes_state_notifier.h:146
std::mutex md_refresh_callback_mtx_
Definition: destination_nodes_state_notifier.h:152
std::mutex allowed_nodes_change_callbacks_mtx_
Definition: destination_nodes_state_notifier.h:151
std::mutex query_quarantined_destinations_callback_mtx_
Definition: destination_nodes_state_notifier.h:154
virtual ~DestinationNodesStateNotifier()=default
Definition: destination.h:95
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:63
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:59
std::function< stdx::expected< void, std::string >()> RefreshSocketAcceptorStateCallback
Definition: destination_nodes_state_notifier.h:54
std::vector< AvailableDestination > AllowedNodes
Definition: destination_status_types.h:60
#define ROUTING_EXPORT
Definition: routing_export.h:15