MySQL 9.4.0
Source Code Documentation
rpl_opt_tracker.h
Go to the documentation of this file.
1/* Copyright (c) 2024, 2025, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
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, version 2.0, 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#ifndef RPL_OPT_TRACKER_H_
25#define RPL_OPT_TRACKER_H_
26
27#include <my_systime.h>
32#include <string>
33
34/**
35 Class to track the state and usage data of Replication features.
36*/
38 public:
40 virtual ~Rpl_opt_tracker();
41 /* Prevent user from invoking default assignment function. */
43 /* Prevent user from invoking default constructor function. */
45
46 /**
47 The thread worker that periodically tracks the replication
48 features.
49 */
50 void worker();
51
52 /**
53 Start the thread that periodically tracks the replication
54 features.
55 */
56 void start_worker();
57
58 /**
59 Stop the thread that periodically tracks the replication
60 features.
61 */
62 void stop_worker();
63
64 /**
65 Tracks the Replication Replica feature, including the usage data.
66 It only updates usage data if the feature is enabled.
67
68 @param enabled true: tracks as enabled
69 false: tracks as disabled
70 */
71 void track_replication_replica(bool enabled) const;
72
73 private:
74 using Service_type = SERVICE_TYPE(mysql_option_tracker_option);
76 static constexpr auto m_service_name = "mysql_option_tracker_option";
77
78 /**
79 Helper method to get Replication Replica feature status.
80
81 @return Replication Replica feature status
82 @retval true enabled
83 @retval false disabled
84 */
86
87 /**
88 Tracks a feature, including the usage data.
89 It only updates usage data if the feature is enabled.
90 Internal method to be used after the mysql_option_tracker_option
91 service is acquired.
92
93 @param service_guard acquired service guard
94 @param enabled true: tracks as enabled
95 false: tracks as disabled
96 @param fname feature name
97 @param usage_counter feature usage counter
98 */
99 static void track(const Tracker_service_guard &service_guard, bool enabled,
100 const std::string &fname,
101 unsigned long long &usage_counter);
102
103 /**
104 Tracks the Binary Log feature, including the usage data.
105 It only updates usage data if the feature is enabled.
106 Internal method to be used after the mysql_option_tracker_option
107 service is acquired.
108
109 @param service_guard acquired service guard
110 @param enabled true: tracks as enabled
111 false: tracks as disabled
112 */
113 void track_binary_log(const Tracker_service_guard &service_guard,
114 bool enabled) const;
115
116 /**
117 Tracks the Replication Replica feature, including the usage data.
118 It only updates usage data if the feature is enabled.
119
120 @param service_guard acquired service guard
121 @param enabled true: tracks as enabled
122 false: tracks as disabled
123 */
124 void track_replication_replica(const Tracker_service_guard &service_guard,
125 bool enabled) const;
126
128 bool m_stop_worker{false};
129 static constexpr const Timeout_type s_tracking_period{600}; // 10 minutes
130
131 static const std::string s_c_name_mysql_server;
132 static const std::string s_f_name_binary_log;
133 static const std::string s_f_name_replication_replica;
134
135 public:
136 static unsigned long long m_opt_option_tracker_usage_binary_log;
138
139 protected:
140 static bool cb_binlog(unsigned long long new_value) {
142 return false;
143 }
145 static bool cb_replica(unsigned long long new_value) {
147 return false;
148 }
150};
151
152/**
153 The rpl_opt_tracker singleton.
154*/
156
157#endif /* RPL_OPT_TRACKER_H_ */
Class to track the state and usage data of Replication features.
Definition: rpl_opt_tracker.h:37
static unsigned long long m_opt_option_tracker_usage_replication_replica
Definition: rpl_opt_tracker.h:137
my_thread_handle m_thread_id
Definition: rpl_opt_tracker.h:127
static bool cb_binlog_define_failed
Definition: rpl_opt_tracker.h:144
static unsigned long long m_opt_option_tracker_usage_binary_log
Definition: rpl_opt_tracker.h:136
static const std::string s_f_name_binary_log
Definition: rpl_opt_tracker.h:132
void stop_worker()
Stop the thread that periodically tracks the replication features.
Definition: rpl_opt_tracker.cc:227
static constexpr auto m_service_name
Definition: rpl_opt_tracker.h:76
void worker()
The thread worker that periodically tracks the replication features.
Definition: rpl_opt_tracker.cc:137
Rpl_opt_tracker & operator=(const Rpl_opt_tracker &info)
static const std::string s_c_name_mysql_server
Definition: rpl_opt_tracker.h:131
Rpl_opt_tracker()
Definition: rpl_opt_tracker.cc:52
static const std::string s_f_name_replication_replica
Definition: rpl_opt_tracker.h:133
Rpl_opt_tracker(const Rpl_opt_tracker &info)
static bool is_replication_replica_enabled()
Helper method to get Replication Replica feature status.
Definition: rpl_opt_tracker.cc:94
void start_worker()
Start the thread that periodically tracks the replication features.
Definition: rpl_opt_tracker.cc:208
static bool cb_binlog(unsigned long long new_value)
Definition: rpl_opt_tracker.h:140
static constexpr const Timeout_type s_tracking_period
Definition: rpl_opt_tracker.h:129
static void track(const Tracker_service_guard &service_guard, bool enabled, const std::string &fname, unsigned long long &usage_counter)
Tracks a feature, including the usage data.
Definition: rpl_opt_tracker.cc:109
virtual ~Rpl_opt_tracker()
Definition: rpl_opt_tracker.cc:76
bool m_stop_worker
Definition: rpl_opt_tracker.h:128
static bool cb_replica(unsigned long long new_value)
Definition: rpl_opt_tracker.h:145
void track_binary_log(const Tracker_service_guard &service_guard, bool enabled) const
Tracks the Binary Log feature, including the usage data.
Definition: rpl_opt_tracker.cc:120
static bool cb_replica_define_failed
Definition: rpl_opt_tracker.h:149
void track_replication_replica(bool enabled) const
Tracks the Replication Replica feature, including the usage data.
Definition: rpl_opt_tracker.cc:132
Wraps my_h_service struct conforming ABI into RAII C++ object with ability to cast to desired service...
Definition: my_service.h:35
Defines for getting and processing the current system type programmatically.
std::uint64_t Timeout_type
Type alias to reduce chance of conversion errors on timeout values.
Definition: my_systime.h:127
Performance schema instrumentation interface.
required bool enabled
Definition: replication_group_member_actions.proto:33
Rpl_opt_tracker * rpl_opt_tracker
The rpl_opt_tracker singleton.
Definition: mysqld.cc:1855
#define SERVICE_TYPE(name)
Generates the standard Service type name.
Definition: service.h:76
Definition: my_thread_bits.h:58
Option tracker registration and deregistration services.
Definition: mysql_option_tracker.h:45