MySQL 9.3.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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:
39 Rpl_opt_tracker(SERVICE_TYPE_NO_CONST(registry_registration) *
41 SERVICE_TYPE_NO_CONST(registry_registration) *
43 virtual ~Rpl_opt_tracker();
44 /* Prevent user from invoking default assignment function. */
46 /* Prevent user from invoking default constructor function. */
48
49 /**
50 The thread worker that periodically tracks the replication
51 features.
52 */
53 void worker();
54
55 /**
56 Start the thread that periodically tracks the replication
57 features.
58 */
59 void start_worker();
60
61 /**
62 Stop the thread that periodically tracks the replication
63 features.
64 */
65 void stop_worker();
66
67 /**
68 Tracks the Replication Replica feature, including the usage data.
69 It only updates usage data if the feature is enabled.
70
71 @param enabled true: tracks as enabled
72 false: tracks as disabled
73 */
74 void track_replication_replica(bool enabled) const;
75
76 private:
77 using Service_type = SERVICE_TYPE(mysql_option_tracker_option);
79 static constexpr auto m_service_name = "mysql_option_tracker_option";
80
81 /**
82 Helper method to get Replication Replica feature status.
83
84 @return Replication Replica feature status
85 @retval true enabled
86 @retval false disabled
87 */
89
90 /**
91 Tracks a feature, including the usage data.
92 It only updates usage data if the feature is enabled.
93 Internal method to be used after the mysql_option_tracker_option
94 service is acquired.
95
96 @param service_guard acquired service guard
97 @param enabled true: tracks as enabled
98 false: tracks as disabled
99 @param fname feature name
100 @param usage_counter feature usage counter
101 */
102 static void track(const Tracker_service_guard &service_guard, bool enabled,
103 const std::string &fname,
104 unsigned long long &usage_counter);
105
106 /**
107 Tracks the Binary Log feature, including the usage data.
108 It only updates usage data if the feature is enabled.
109 Internal method to be used after the mysql_option_tracker_option
110 service is acquired.
111
112 @param service_guard acquired service guard
113 @param enabled true: tracks as enabled
114 false: tracks as disabled
115 */
116 void track_binary_log(const Tracker_service_guard &service_guard,
117 bool enabled) const;
118
119 /**
120 Tracks the Replication Replica feature, including the usage data.
121 It only updates usage data if the feature is enabled.
122
123 @param service_guard acquired service guard
124 @param enabled true: tracks as enabled
125 false: tracks as disabled
126 */
127 void track_replication_replica(const Tracker_service_guard &service_guard,
128 bool enabled) const;
129
130 SERVICE_TYPE_NO_CONST(registry_registration) *
132
134 bool m_stop_worker{false};
135 static constexpr const Timeout_type s_tracking_period{600}; // 10 minutes
136
137 static const std::string s_c_name_mysql_server;
138 static const std::string s_f_name_binary_log;
139 static const std::string s_f_name_replication_replica;
140
141 public:
142 static unsigned long long m_opt_option_tracker_usage_binary_log;
144
145 protected:
146 static bool cb_binlog(unsigned long long new_value) {
148 return false;
149 }
151 static bool cb_replica(unsigned long long new_value) {
153 return false;
154 }
156};
157
158/**
159 The rpl_opt_tracker singleton.
160*/
162
163#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:143
my_thread_handle m_thread_id
Definition: rpl_opt_tracker.h:133
static bool cb_binlog_define_failed
Definition: rpl_opt_tracker.h:150
static unsigned long long m_opt_option_tracker_usage_binary_log
Definition: rpl_opt_tracker.h:142
static const std::string s_f_name_binary_log
Definition: rpl_opt_tracker.h:138
void stop_worker()
Stop the thread that periodically tracks the replication features.
Definition: rpl_opt_tracker.cc:231
static constexpr auto m_service_name
Definition: rpl_opt_tracker.h:79
void worker()
The thread worker that periodically tracks the replication features.
Definition: rpl_opt_tracker.cc:141
Rpl_opt_tracker & operator=(const Rpl_opt_tracker &info)
static const std::string s_c_name_mysql_server
Definition: rpl_opt_tracker.h:137
static const std::string s_f_name_replication_replica
Definition: rpl_opt_tracker.h:139
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:98
void start_worker()
Start the thread that periodically tracks the replication features.
Definition: rpl_opt_tracker.cc:212
static bool cb_binlog(unsigned long long new_value)
Definition: rpl_opt_tracker.h:146
static constexpr const Timeout_type s_tracking_period
Definition: rpl_opt_tracker.h:135
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:113
virtual ~Rpl_opt_tracker()
Definition: rpl_opt_tracker.cc:80
Rpl_opt_tracker(mysql_service_registry_registration_t *srv_registry_registration, mysql_service_registry_registration_t *srv_registry_registration_no_lock)
Definition: rpl_opt_tracker.cc:52
bool m_stop_worker
Definition: rpl_opt_tracker.h:134
mysql_service_registry_registration_t * m_srv_registry_registration_no_lock
Definition: rpl_opt_tracker.h:131
static bool cb_replica(unsigned long long new_value)
Definition: rpl_opt_tracker.h:151
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:124
static bool cb_replica_define_failed
Definition: rpl_opt_tracker.h:155
void track_replication_replica(bool enabled) const
Tracks the Replication Replica feature, including the usage data.
Definition: rpl_opt_tracker.cc:136
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
mysql_service_registry_registration_t * srv_registry_registration_no_lock
Definition: mysqld.cc:2026
mysql_service_registry_registration_t * srv_registry_registration
Definition: mysqld.cc:2023
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:1853
#define SERVICE_TYPE(name)
Generates the standard Service type name.
Definition: service.h:76
#define SERVICE_TYPE_NO_CONST(name)
Generates the standard Service type name.
Definition: service.h:71
Definition: my_thread_bits.h:58
Option tracker registration and deregistration services.
Definition: mysql_option_tracker.h:45