MySQL 8.3.0
Source Code Documentation
event_state_tracker.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2021, 2023, 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 also distributed 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 included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#ifndef MYSQL_HARNESS_EVENT_STATE_TRACKER_INCLUDED
26#define MYSQL_HARNESS_EVENT_STATE_TRACKER_INCLUDED
27
28#include "harness_export.h"
29
30#include <map>
31#include <mutex>
32#include <string>
33
34namespace mysql_harness {
35
36/**
37 * @brief EventStateTracker singleton object keeps track of the current known
38 * state of selected event. Can be used to track the changes of the state of
39 * selected event (for conditional logging etc.)
40 *
41 */
42class HARNESS_EXPORT EventStateTracker {
43 public:
44 /**
45 * @brief List of the events that can currently be tracked
46 *
47 */
48 enum class EventId : size_t {
49 MetadataServerConnectedOk,
50 MetadataRefreshOk,
51 GRMemberConnectedOk,
52 MetadataNodeInGR,
53 GRNodeInMetadata,
54 TargetClusterPresentInOptions,
55 ClusterInvalidatedInMetadata,
56 ClusterWasBootstrappedAgainstClusterset,
57 NoRightsToUpdateRouterAttributes,
58 NoGRQuorum,
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:42
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:48
Definition: common.h:41
static mysql_service_status_t clear(reference_caching_channel channel) noexcept
Definition: component.cc:145