MySQL 9.1.0
Source Code Documentation
resource_group.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2024, 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#ifndef RESOURCEGROUPS_RESOURCE_GROUP_H_
24#define RESOURCEGROUPS_RESOURCE_GROUP_H_
25
27
28#include <functional>
29#include <memory>
30#include <mutex>
31#include <set>
32
33#include "sql/log.h" // sql_print_warning
35
36namespace resourcegroups {
37
38/**
39 Class that represents an abstraction of the Resource Group.
40 It has generic attributes of Resource group name, type,
41 active or inactive, a pointer to a Resource control object.
42*/
43
45 public:
46 /**
47 Construct a Resource_group object.
48
49 @param name name of the Resource_group.
50 @param type type of the Resource_group.
51 @param enabled Check if Resource_group is enabled or not.
52 */
53
54 Resource_group(const std::string &name, const Type type, bool enabled)
56
57 const std::string &name() const { return m_name; }
58
59 Type type() const { return m_type; }
60
61 bool enabled() const { return m_enabled; }
62
64
66
68
71 }
72
73 /**
74 Check if resource group is associated with threads.
75
76 @return true if some threads are mapped with this resource group
77 else false.
78 */
79
81 std::unique_lock<std::mutex> lock(m_set_mutex);
82 return !m_pfs_thread_id_set.empty();
83 }
84
85 /**
86 Is pfs thread id already exists in the set.
87
88 @param pfs_thread_id PFS thread id.
89
90 @return true if thread id exists in the set else false.
91 */
92
93 bool is_pfs_thread_id_exists(const ulonglong pfs_thread_id) {
94 std::unique_lock<std::mutex> lock(m_set_mutex);
95 return m_pfs_thread_id_set.find(pfs_thread_id) != m_pfs_thread_id_set.end();
96 }
97
98 /**
99 Add thread_id to the thread id set associated with this resource group.
100
101 @param pfs_thread_id PFS thread id.
102 */
103
104 void add_pfs_thread_id(const ulonglong pfs_thread_id) {
105 std::unique_lock<std::mutex> lock(m_set_mutex);
106 (void)m_pfs_thread_id_set.insert(pfs_thread_id);
107 }
108
109 /**
110 Remove the PFS thread id.
111
112 @param pfs_thread_id Remove pfs thread id.
113 */
114
115 void remove_pfs_thread_id(const ulonglong pfs_thread_id) {
116 std::unique_lock<std::mutex> lock(m_set_mutex);
117 (void)m_pfs_thread_id_set.erase(pfs_thread_id);
118 }
119
120 /**
121 Clear the thread id set associated with this resource group.
122 */
123
124 void clear() {
125 std::unique_lock<std::mutex> lock(m_set_mutex);
126 (void)m_pfs_thread_id_set.clear();
127 }
128
129 /**
130 Apply a control function on threads associated with this resource group.
131
132 @param control_func pointer to Control function.
133 */
134
135 void apply_control_func(std::function<void(ulonglong)> control_func) {
136 std::unique_lock<std::mutex> lock(m_set_mutex);
137 for (auto pfs_thread_id : m_pfs_thread_id_set) control_func(pfs_thread_id);
138 }
139
140 ~Resource_group() = default;
141
142 private:
143 /**
144 Name of the resource group.
145 */
146 std::string m_name;
147
148 /**
149 Type whether it is user or system resource group.
150 */
152
153 /**
154 bool flag whether resource is enabled or disabled.
155 */
157
158 /**
159 Thread resource controller object.
160 */
162
163 /**
164 Threads associated with this resource group.
165 */
166 std::set<ulonglong> m_pfs_thread_id_set;
167
168 /**
169 Mutex protecting the resource group set.
170 */
171 std::mutex m_set_mutex;
172
173 /**
174 Disable copy construction and assignment.
175 */
177 void operator=(const Resource_group &) = delete;
178};
179} // namespace resourcegroups
180#endif // RESOURCEGROUPS_RESOURCE_GROUP_H_
Class that represents an abstraction of the Resource Group.
Definition: resource_group.h:44
void clear()
Clear the thread id set associated with this resource group.
Definition: resource_group.h:124
Resource_group(const std::string &name, const Type type, bool enabled)
Construct a Resource_group object.
Definition: resource_group.h:54
std::set< ulonglong > m_pfs_thread_id_set
Threads associated with this resource group.
Definition: resource_group.h:166
const std::string & name() const
Definition: resource_group.h:57
std::mutex m_set_mutex
Mutex protecting the resource group set.
Definition: resource_group.h:171
void apply_control_func(std::function< void(ulonglong)> control_func)
Apply a control function on threads associated with this resource group.
Definition: resource_group.h:135
Thread_resource_control * controller()
Definition: resource_group.h:67
void add_pfs_thread_id(const ulonglong pfs_thread_id)
Add thread_id to the thread id set associated with this resource group.
Definition: resource_group.h:104
void remove_pfs_thread_id(const ulonglong pfs_thread_id)
Remove the PFS thread id.
Definition: resource_group.h:115
bool m_enabled
bool flag whether resource is enabled or disabled.
Definition: resource_group.h:156
Resource_group(const Resource_group &)=delete
Disable copy construction and assignment.
Type type() const
Definition: resource_group.h:59
Type m_type
Type whether it is user or system resource group.
Definition: resource_group.h:151
std::string m_name
Name of the resource group.
Definition: resource_group.h:146
void operator=(const Resource_group &)=delete
bool is_bound_to_threads()
Check if resource group is associated with threads.
Definition: resource_group.h:80
void set_enabled(bool enabled)
Definition: resource_group.h:65
void set_type(Type type)
Definition: resource_group.h:63
bool is_pfs_thread_id_exists(const ulonglong pfs_thread_id)
Is pfs thread id already exists in the set.
Definition: resource_group.h:93
bool enabled() const
Definition: resource_group.h:61
const Thread_resource_control * controller() const
Definition: resource_group.h:69
Thread_resource_control m_thread_resource_control
Thread resource controller object.
Definition: resource_group.h:161
Class that abstracts the resource control that can be applied to threads.
Definition: thread_resource_control.h:40
Error logging, slow query logging, general query logging: If it's server-internal,...
unsigned long long int ulonglong
Definition: my_inttypes.h:56
Definition: dd_resource_group.h:29
Type
Definition: resource_group_basic_types.h:33
static std::mutex lock
Definition: net_ns.cc:56