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