MySQL 8.4.0
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 NoGRQuorum,
60 };
61
62 /**
63 * @brief Returns information about the selected event state change (and sets
64 * the new state of event if changed).
65 *
66 * @param state current state of the event
67 * @param event_id id of the event
68 * @param additional_tag optional tag
69 *
70 * @return information about the event state change
71 * @retval true the event state has changed since the last call
72 * @retval false the event state has NOT changed since the last call
73 */
74 bool state_changed(const int state, const EventId event_id,
75 const std::string &additional_tag = "");
76
77 /**
78 * @brief Get the singleton object of EventStateTracker
79 *
80 */
81 static EventStateTracker &instance();
82
83 /**
84 * @brief Remove the state for a given tag for all event_id that it has
85 * registered
86 *
87 * @param tag tag of the events being removed
88 *
89 */
90 void remove_tag(const std::string &tag);
91
92 /**
93 * @brief Remove stored state for all events
94 *
95 */
96 void clear();
97
98 private:
99 EventStateTracker() = default;
102 using Key = std::pair<size_t, size_t>;
103 std::map<Key, int> events_;
104 std::mutex events_mtx_;
105};
106
107} // namespace mysql_harness
108
109#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:104
EventStateTracker operator=(const EventStateTracker &)=delete
std::pair< size_t, size_t > Key
Definition: event_state_tracker.h:102
std::map< Key, int > events_
Definition: event_state_tracker.h:103
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:146