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