MySQL 9.3.0
Source Code Documentation
mysql_option_tracker.h
Go to the documentation of this file.
1/* Copyright (c) 2024, 2025, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MYSQL_OPTION_TRACKER_H
25#define MYSQL_OPTION_TRACKER_H
26
28#include <cstddef>
29
30/**
31 @ingroup group_components_services_inventory
32
33 Option tracker registration and deregistration services
34
35 This is a service that will allow registering an option.
36 Each option has a name. The name is UTF8mb4 and is unique in
37 the list.
38 Manipulating the option list is an "expesive" operation since there
39 is a global lock involved.
40
41 Each code container (a component or a plugin) should register its
42 options during its initialization and should unregister them during
43 its deinitialization.
44*/
45BEGIN_SERVICE_DEFINITION(mysql_option_tracker_option)
46
47/**
48 Define an option. Adds an option definition.
49
50 If another option of the same name exists, the definition fails
51
52 @param option The name of the option, UTF8mb4. Must be unique.
53 @param container The container name. UTF8mb4
54 Please prefix with "plugin_" for plugins.
55 @param is_enabled non-0 if the option is marked as enabled, 0 otherwise
56 @retval false success
57 @retval true failure
58*/
59DECLARE_BOOL_METHOD(define, (const char *option, const char *container,
61/**
62 Undefine an option.
63
64 Fails if no option is defined with the same name
65
66 @param option The name of the option, US ASCII
67 @retval false success
68 @retval true failure
69*/
70DECLARE_BOOL_METHOD(undefine, (const char *option));
71
72/**
73 Set enabled for an existing element
74
75 if the option is not defined it fails
76
77 @param option The name of the option, US ASCII
78 @param is_enabled non-0 if the option is marked as enabled, 0 otherwise
79 @retval false success
80 @retval true failure
81*/
82DECLARE_BOOL_METHOD(set_enabled, (const char *option, int is_enabled));
83
84END_SERVICE_DEFINITION(mysql_option_tracker_option)
85
86/**
87 @ingroup group_components_services_inventory
88
89 Option tracker usage marker
90
91 Sets usage data for a given option.
92 Internally stores into the system table.
93
94 Cluster ID is set to empty.
95
96 It gets the value for server_id from the system variable
97 server_uuid.
98*/
99BEGIN_SERVICE_DEFINITION(mysql_option_tracker_usage)
100/**
101 Set usage data. Sets the persisted state
102
103 @param option The name of the option, US ASCII
104 @param usage_data_json Usage data, JSON, zero terminated UTF-8
105 @retval false success
106 @retval true failure
107*/
108DECLARE_BOOL_METHOD(set, (const char *option, const char *usage_data_json));
109/**
110 Get usage data. Reads the persisted state.
111 Stores a 0-terminated UTF-8 data into the supplied buffer. If the data to
112 be stored are too long for the buffer the function fails.
113
114 Reading is done in a separate auto-commit transaction.
115
116 @param option The name of the option, US ASCII
117 @param [out] usage_data A buffer to return the UTF-8 data in.
118 @param sizeof_usage_data The size of the usage_data_buffer in bytes.
119 otherwise.
120 @retval false success
121 @retval true failure
122*/
123DECLARE_BOOL_METHOD(get, (const char *option, char *usage_data,
124 size_t sizeof_usage_data));
125END_SERVICE_DEFINITION(mysql_option_tracker_usage)
126
128 unsigned long long new_value);
129/**
130 @ingroup group_components_services_inventory
131
132 Option tracker usage cache updater callbacks registry
133
134 Handles the reset of the intial cached values when the persisted data changes.
135
136 The idea is that each component needs to register a callback to be called when
137 there's update of the persited values coming via means different from the
138 mysql_option_tracker_usage::set method. The callback is supposed to update the
139 in-memory status variable cache for that option.
140 Call add() after reading the status value.
141 Call delete() when removing the component and the callback was added.
142 Expect offline calls to the callback when data are updated via the GR
143 signalling service.
144*/
145BEGIN_SERVICE_DEFINITION(mysql_option_tracker_usage_cache_callbacks)
146/**
147 Call this when the component is initalized. Pass a callback pointer
148 that will, when called, set the value of the cache to the value passed
149
150 @param option_name the name of the option to add callback to
151 @param callback a function pointer to a function to be called to set the new
152 value
153 @retval false success
154 @retval true failure
155*/
157 add, (const char *option_name,
159/**
160 Call this when the component is de-initalized and a callback has been added.
161 Pass the same callback pointer as the one passed to add(). It will be checked.
162
163 @param option_name the name of the option to add callback to
164 @param callback for verification; the same callback function as is passed to
165 add
166 @retval false success
167 @retval true failure
168*/
170 remove, (const char *option_name,
172END_SERVICE_DEFINITION(mysql_option_tracker_usage_cache_callbacks)
173
174#endif /* MYSQL_OPTION_TRACKER_H */
bool(* mysql_option_tracker_usage_cache_update_callback)(unsigned long long new_value)
Definition: mysql_option_tracker.h:127
Definition: atomics_array.h:39
bool is_enabled()
Check if doublewrite is enabled.
Definition: buf0dblwr.h:390
static mysql_service_status_t get(THD **thd) noexcept
Definition: mysql_current_thread_reader_all_empty.cc:31
static mysql_service_status_t remove(reference_caching_channel channel, const char *implementation_name) noexcept
Definition: component.cc:137
static mysql_service_status_t add(reference_caching_channel channel, const char *implementation_name) noexcept
Definition: component.cc:127
std::set< Key, Compare, ut::allocator< Key > > set
Specialization of set which uses ut_allocator.
Definition: ut0new.h:2884
#define END_SERVICE_DEFINITION(name)
A macro to end the last Service definition started with the BEGIN_SERVICE_DEFINITION macro.
Definition: service.h:91
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:86
#define DECLARE_BOOL_METHOD(name, args)
Declares a method that returns bool as a part of the Service definition.
Definition: service.h:112