MySQL 8.0.39
Source Code Documentation
shared_quarantine_handler.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2021, 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 ROUTING_SHARED_QUARANTINE_HANDLER_INCLUDED
27#define ROUTING_SHARED_QUARANTINE_HANDLER_INCLUDED
28
29#include <functional>
30#include <string>
31#include <utility> // move
32
33#include "destination.h" // AllowedNodes
34#include "tcp_address.h"
35
37 public:
39 std::function<bool(mysql_harness::TCPAddress, bool)>;
41 std::function<bool(mysql_harness::TCPAddress)>;
42 using stop_callback_type = std::function<void()>;
43
44 using refresh_callback_type = std::function<void(
45 const std::string &, const bool, const AllowedNodes &)>;
46
47 /**
48 * Register a callback that can to be used to add a destination candidate
49 * to the quarantine.
50 *
51 * @param[in] clb Callback called to quarantine a destination.
52 */
53 void on_update(update_callback_type clb) { on_update_ = std::move(clb); }
54
55 bool update(const mysql_harness::TCPAddress &addr, bool success) {
56 if (on_update_) return on_update_(addr, success);
57 return false;
58 }
59
60 /**
61 * Register a callback that can be used to check if the given destination
62 * candidate is currently quarantined.
63 *
64 * @param[in] clb Callback called to check if the destination is quarantined.
65 */
67 on_is_quarantined_ = std::move(clb);
68 }
69
70 bool is_quarantined(const mysql_harness::TCPAddress &addr) const {
71 return on_is_quarantined_ ? on_is_quarantined_(addr) : false;
72 }
73
74 /**
75 * Register a callback that can be used to stop the unreachable destination
76 * candidates quarantine.
77 *
78 * @param[in] clb Callback called to remove all destinations from quarantine.
79 */
80 void on_stop(stop_callback_type clb) { on_stop_ = std::move(clb); }
81
82 void stop() {
83 if (on_stop_) on_stop_();
84 }
85
86 /**
87 * Register a callback used for refreshing the quarantined destinations when
88 * there are possible changes in the destination candidates set.
89 *
90 * @param[in] clb Callback called on metadata refresh.
91 */
92 void on_refresh(refresh_callback_type clb) { on_refresh_ = std::move(clb); }
93
94 void refresh(const std::string &instance_name, bool some_bool,
95 const AllowedNodes &allowed_nodes) {
96 if (on_refresh_) on_refresh_(instance_name, some_bool, allowed_nodes);
97 }
98
99 /**
100 * Unregister all of the destination candidates quarantine callbacks.
101 */
102 void reset() {
103 on_update_ = nullptr;
104 on_is_quarantined_ = nullptr;
105 on_refresh_ = nullptr;
106 on_stop_ = nullptr;
107 }
108
109 private:
111
115};
116
117#endif
Definition: shared_quarantine_handler.h:36
void on_refresh(refresh_callback_type clb)
Register a callback used for refreshing the quarantined destinations when there are possible changes ...
Definition: shared_quarantine_handler.h:92
std::function< void()> stop_callback_type
Definition: shared_quarantine_handler.h:42
void on_update(update_callback_type clb)
Register a callback that can to be used to add a destination candidate to the quarantine.
Definition: shared_quarantine_handler.h:53
bool update(const mysql_harness::TCPAddress &addr, bool success)
Definition: shared_quarantine_handler.h:55
void stop()
Definition: shared_quarantine_handler.h:82
void on_stop(stop_callback_type clb)
Register a callback that can be used to stop the unreachable destination candidates quarantine.
Definition: shared_quarantine_handler.h:80
stop_callback_type on_stop_
Definition: shared_quarantine_handler.h:113
refresh_callback_type on_refresh_
Definition: shared_quarantine_handler.h:114
std::function< bool(mysql_harness::TCPAddress)> is_quarantined_callback_type
Definition: shared_quarantine_handler.h:41
update_callback_type on_update_
Definition: shared_quarantine_handler.h:110
std::function< void(const std::string &, const bool, const AllowedNodes &)> refresh_callback_type
Definition: shared_quarantine_handler.h:45
void reset()
Unregister all of the destination candidates quarantine callbacks.
Definition: shared_quarantine_handler.h:102
void refresh(const std::string &instance_name, bool some_bool, const AllowedNodes &allowed_nodes)
Definition: shared_quarantine_handler.h:94
std::function< bool(mysql_harness::TCPAddress, bool)> update_callback_type
Definition: shared_quarantine_handler.h:39
bool is_quarantined(const mysql_harness::TCPAddress &addr) const
Definition: shared_quarantine_handler.h:70
void on_is_quarantined(is_quarantined_callback_type clb)
Register a callback that can be used to check if the given destination candidate is currently quarant...
Definition: shared_quarantine_handler.h:66
is_quarantined_callback_type on_is_quarantined_
Definition: shared_quarantine_handler.h:112
Defines an IP address with port number
Definition: tcp_address.h:40
std::vector< AvailableDestination > AllowedNodes
Definition: destination_status_types.h:59