MySQL 8.0.37
Source Code Documentation
event_state_tracker.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 MYSQL_HARNESS_EVENT_STATE_TRACKER_INCLUDED
27#define MYSQL_HARNESS_EVENT_STATE_TRACKER_INCLUDED
28
29#include "harness_export.h"
30
31#include <map>
32#include <mutex>
33#include <string>
34
35namespace mysql_harness {
36
37/**
38 * @brief EventStateTracker singleton object keeps track of the current known
39 * state of selected event. Can be used to track the changes of the state of
40 * selected event (for conditional logging etc.)
41 *
42 */
43class HARNESS_EXPORT EventStateTracker {
44 public:
45 /**
46 * @brief List of the events that can currently be tracked
47 *
48 */
49 enum class EventId : size_t {
50 MetadataServerConnectedOk,
51 MetadataRefreshOk,
52 GRMemberConnectedOk,
53 MetadataNodeInGR,
54 GRNodeInMetadata,
55 TargetClusterPresentInOptions,
56 ClusterInvalidatedInMetadata,
57 ClusterWasBootstrappedAgainstClusterset,
58 NoRightsToUpdateRouterAttributes
59 };
60
61 /**
62 * @brief Returns information about the selected event state change (and sets
63 * the new state of event if changed).
64 *
65 * @param state current state of the event
66 * @param event_id id of the event
67 * @param additional_tag optional tag
68 *
69 * @return information about the event state change
70 * @retval true the event state has changed since the last call
71 * @retval false the event state has NOT changed since the last call
72 */
73 bool state_changed(const int state, const EventId event_id,
74 const std::string &additional_tag = "");
75
76 /**
77 * @brief Get the singleton object of EventStateTracker
78 *
79 */
80 static EventStateTracker &instance();
81
82 /**
83 * @brief Remove the state for a given tag for all event_id that it has
84 * registered
85 *
86 * @param tag tag of the events being removed
87 *
88 */
89 void remove_tag(const std::string &tag);
90
91 /**
92 * @brief Remove stored state for all events
93 *
94 */
95 void clear();
96
97 private:
98 EventStateTracker() = default;
101 using Key = std::pair<size_t, size_t>;
102 std::map<Key, int> events_;
103 std::mutex events_mtx_;
104};
105
106} // namespace mysql_harness
107
108#endif /* MYSQL_HARNESS_EVENT_STATE_TRACKER_INCLUDED */
EventStateTracker singleton object keeps track of the current known state of selected event.
Definition: event_state_tracker.h:43
EventStateTracker(const EventStateTracker &)=delete
std::mutex events_mtx_
Definition: event_state_tracker.h:103
EventStateTracker operator=(const EventStateTracker &)=delete
std::pair< size_t, size_t > Key
Definition: event_state_tracker.h:101
std::map< Key, int > events_
Definition: event_state_tracker.h:102
EventId
List of the events that can currently be tracked.
Definition: event_state_tracker.h:49
Definition: common.h:42
static mysql_service_status_t clear(reference_caching_channel channel) noexcept
Definition: component.cc:154