MySQL 9.2.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
destination_status_component.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 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 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 MYSQLROUTER_DESTINATION_STATUS_COMPONENT_INCLUDED
27#define MYSQLROUTER_DESTINATION_STATUS_COMPONENT_INCLUDED
28
29#include <chrono>
30#include <memory>
31
35
37
38/**
39 * @class DestinationStatusComponent
40 * @brief Shared component representing status of the routing destinations.
41 *
42 */
44 public:
45 /**
46 * @brief Get the singleton instance object of our class.
47 */
48 static DestinationStatusComponent &get_instance();
49
50 // disable copy, as we are a single-instance
52 void operator=(DestinationStatusComponent const &) = delete;
53
54 // no move either
57
59
60 /**
61 * @brief Initialize the component with the configured options.
62 *
63 * @param quarantine_interval interval after which the quarantined
64 * destinations are checked for availability
65 * @param qurantine_threshold number of invalid connect attempts after which
66 * the destination is added to the quarantine
67 */
68 void init(std::chrono::seconds quarantine_interval,
69 uint32_t qurantine_threshold);
70
71 /**
72 * @brief Register callbacks requied by the quarantine mechanism (start/stop
73 * acceptor etc.).
74 *
75 * @param routing_callbacks object defining the callbacks
76 */
77 void register_quarantine_callbacks(
78 QuarantineRoutingCallbacks &&routing_callbacks);
79 /**
80 * @brief Unregister callbacks requied by the quarantine mechanism.
81 */
82 void unregister_quarantine_callbacks();
83
84 /**
85 * @brief Register routing instance in the quarantine mechanism.
86 *
87 * @param name name of the route
88 */
89 void register_route(const std::string &name);
90
91 /**
92 * Register the connection error or success to a given destination.
93 *
94 * If registering a success it will set the number of reported errors to a
95 * given connection to 0.
96 *
97 * If registering a failure it will increment the number of reported failed
98 * connections to the destination. If the number reached the
99 * quarantine_threshold the destination will be added to the quarantine. If
100 * the destination candidate is not quarantine yet it will starting the async
101 * handler for it, otherwise it will just update the referencing plugins list.
102 *
103 * @param[in] dest Reported destination address.
104 * @param[in] success Indicates if the reported connection result is success
105 * of failure.
106 *
107 * @returns true if the destination got added to the quarantine, false
108 * otherwise
109 */
110 bool report_connection_result(const mysql_harness::Destination &dest,
111 bool success);
112
113 /**
114 * Query the quarantined destination candidates set and check if the given
115 * destination candidate is quarantined.
116 *
117 * @param[in] dest Destination candidate address.
118 * @returns true if the destination candidate is quarantined, false otherwise.
119 */
120 bool is_destination_quarantined(const mysql_harness::Destination &dest);
121
122 /**
123 * Stop all async operations and clear the quarantine list.
124 */
125 void stop_unreachable_destinations_quarantine();
126
127 /**
128 * Refresh the quarantined destination candidates list on metadata refresh.
129 *
130 * 1) if the destination candidates list got updated we have to go through the
131 * quarantined destinations and check if there are still routing plugins that
132 * references them.
133 * 2) for each destination returned in the metadata (which is available from
134 * the md perspective) check if it is still unreachable and should be
135 * quarantined.
136 *
137 * @param[in] instance_name Routing plugin instance name.
138 * @param[in] nodes_changed_on_md_refresh Information if the destination
139 * candidates have been updated for the given routing plugin.
140 * @param[in] new_destinations List of destination candidates that are
141 * available for the given routing plugin after metadata refresh.
142 */
143 void refresh_destinations_quarantine(const std::string &instance_name,
144 const bool nodes_changed_on_md_refresh,
145 const AllowedNodes &new_destinations);
146
147 private:
149
150 std::unique_ptr<UnreachableDestinationsQuarantine>
152};
153
154#endif // MYSQLROUTER_DESTINATION_STATUS_COMPONENT_INCLUDED
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:571
Shared component representing status of the routing destinations.
Definition: destination_status_component.h:43
std::unique_ptr< UnreachableDestinationsQuarantine > unreachable_destinations_quarantine_
Definition: destination_status_component.h:151
void operator=(DestinationStatusComponent const &)=delete
DestinationStatusComponent(DestinationStatusComponent const &)=delete
DestinationStatusComponent(DestinationStatusComponent &&)=delete
void operator=(DestinationStatusComponent &&)=delete
Information about unreachable destination candidates that is shared between plugin instances.
Definition: unreachable_destinations_quarantine.h:51
Definition: destination.h:95
#define DESTINATION_STATUS_EXPORT
Definition: destination_status_export.h:15
std::vector< AvailableDestination > AllowedNodes
Definition: destination_status_types.h:62
case opt name
Definition: sslopt-case.h:29
Definition: destination_status_types.h:35
double seconds()
Definition: task.cc:314