MySQL 26.10.0
Source Code Documentation
health_monitor_disk_state.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2026, 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#pragma once
25
26#include <string>
27
28namespace hm {
29
30class Disk_Collector;
31
32namespace ds {
33
35 public:
36 enum State {
46 ERROR
47 };
48
49 Storage_State() = default;
50 Storage_State(const char *state_name, State state)
51 : m_name(state_name), m_state(state) {}
52
53 virtual ~Storage_State() = default;
54 virtual void enter() {}
55 virtual void check_levels() {}
56 virtual void exit() {}
58 static void get_params();
59 static void get_levels();
60 enum State state() const { return m_state; }
61
62 static bool normal_level();
63 static bool warning_level();
64 static bool low_level();
65 static bool critical_level();
66 static bool disk_error();
67
68 static void set_normal_state();
69 static void set_warning_state();
70 static void set_low_limit_state();
71 static void set_critical_state();
72 static void set_error_state();
73
75 static size_t available_mb;
76 // Storage thresholds, updated when the monitored filesystem or settings
77 // change
78 static size_t reserve_mb;
79 static size_t critical_level_mb;
80 static size_t warn_level_1_mb;
81 static size_t warn_level_2_mb;
82 static size_t warn_level_3_mb;
83 static size_t max_warn_level_mb;
84 static size_t recovery_level_mb;
85
86 private:
87 const std::string m_name;
89};
90
91/**
92 Start State
93
94 The Disk Collector process thread is starting but has not yet checked the
95 storage status.
96*/
97class Start_State : public Storage_State {
98 public:
100 Start_State(const Start_State &) = delete;
102
103 void check_levels() override;
104};
105
106/**
107 Stop State
108
109 The Disk Collector process thread is stopping. Clean up any remaining tasks.
110*/
111class Stop_State : public Storage_State {
112 public:
114 void check_levels() override;
115};
116
117/**
118 Normal State
119
120 Available space is above low space limit.
121*/
123 public:
125 void check_levels() override;
126};
127
128/**
129 Warning State
130
131 Available space is below one or more warning levels, but above
132 the low space limit.
133*/
135 public:
137 void enter() override;
138 static bool check_warning_level();
139 void check_levels() override;
140};
141
142/**
143 Low Limit State
144
145 Available space is below the low space limit but still above
146 the critical space limit. Entering the low limit state starts
147 the fallback timer.
148*/
150 public:
152 void enter() override;
153 void check_levels() override;
154 void exit() override;
155};
156
157/**
158 Critical State
159
160 Available space is below the absolute lowest storage limit.
161 Fallback mode is triggered immediately.
162*/
164 public:
166 void enter() override;
167 void exit() override;
168 void check_levels() override;
169};
170
171/**
172 Error State
173
174 The Disk Collector is running but there is an error that prevents it from
175 collecting storage data.
176*/
178 public:
180 void enter() override;
181 void check_levels() override;
182};
183
184} // namespace ds
185} // namespace hm
Disk Collector.
Definition: health_monitor_disk.h:245
Critical State.
Definition: health_monitor_disk_state.h:163
void enter() override
Critical State - Enter If the server hasn't been fenced yet, then fence immediately.
Definition: health_monitor_disk_state.cc:384
void check_levels() override
Critical State - Check levels Server is (or should be) fenced, issue regular warnings.
Definition: health_monitor_disk_state.cc:406
void exit() override
Critical Limit State - Exit Clear Critical state variables.
Definition: health_monitor_disk_state.cc:398
Critical_State()
Definition: health_monitor_disk_state.h:165
Error State.
Definition: health_monitor_disk_state.h:177
void check_levels() override
Error State - Check levels.
Definition: health_monitor_disk_state.cc:452
void enter() override
Error State - Enter.
Definition: health_monitor_disk_state.cc:445
Error_State()
Definition: health_monitor_disk_state.h:179
Low Limit State.
Definition: health_monitor_disk_state.h:149
void check_levels() override
Low Limit State - Check levels Fallback timer was started in enter() and is counting down.
Definition: health_monitor_disk_state.cc:322
void enter() override
Low Limit State - Enter Start fallback timer countdown.
Definition: health_monitor_disk_state.cc:295
void exit() override
Low Limit State - Exit Cancel the fallback timer, clear Low Limit state variables.
Definition: health_monitor_disk_state.cc:308
Low_Limit_State()
Definition: health_monitor_disk_state.h:151
Normal State.
Definition: health_monitor_disk_state.h:122
void check_levels() override
Normal State - Check levels.
Definition: health_monitor_disk_state.cc:180
Normal_State()
Definition: health_monitor_disk_state.h:124
Start State.
Definition: health_monitor_disk_state.h:97
Start_State & operator=(const Start_State &)=delete
Start_State(const Start_State &)=delete
void check_levels() override
Start State - Check levels.
Definition: health_monitor_disk_state.cc:142
Start_State()
Definition: health_monitor_disk_state.h:99
Stop State.
Definition: health_monitor_disk_state.h:111
void check_levels() override
Stop State - Check levels.
Definition: health_monitor_disk_state.cc:161
Stop_State()
Definition: health_monitor_disk_state.h:113
Definition: health_monitor_disk_state.h:34
static bool low_level()
Definition: health_monitor_disk_state.cc:88
static void set_collector(Disk_Collector *collector)
Definition: health_monitor_disk_state.h:57
const std::string m_name
Definition: health_monitor_disk_state.h:87
static void set_low_limit_state()
Definition: health_monitor_disk_state.cc:106
static size_t warn_level_2_mb
Definition: health_monitor_disk_state.h:81
static size_t warn_level_1_mb
Definition: health_monitor_disk_state.h:80
static size_t recovery_level_mb
Definition: health_monitor_disk_state.h:84
static void set_normal_state()
Storage State - Transitions.
Definition: health_monitor_disk_state.cc:104
State
Definition: health_monitor_disk_state.h:36
@ CRITICAL
Definition: health_monitor_disk_state.h:43
@ ERROR
Definition: health_monitor_disk_state.h:46
@ START
Definition: health_monitor_disk_state.h:38
@ RECOVERY_2
Definition: health_monitor_disk_state.h:45
@ UNDEF
Definition: health_monitor_disk_state.h:37
@ STOP
Definition: health_monitor_disk_state.h:39
@ WARNING
Definition: health_monitor_disk_state.h:41
@ LOW_LIMIT
Definition: health_monitor_disk_state.h:42
@ RECOVERY_1
Definition: health_monitor_disk_state.h:44
@ NORMAL
Definition: health_monitor_disk_state.h:40
virtual void exit()
Definition: health_monitor_disk_state.h:56
static void set_error_state()
Definition: health_monitor_disk_state.cc:108
static size_t critical_level_mb
Definition: health_monitor_disk_state.h:79
static bool critical_level()
Definition: health_monitor_disk_state.cc:94
static size_t warn_level_3_mb
Definition: health_monitor_disk_state.h:82
enum State state() const
Definition: health_monitor_disk_state.h:60
static bool disk_error()
Definition: health_monitor_disk_state.cc:99
virtual void check_levels()
Definition: health_monitor_disk_state.h:55
static bool warning_level()
Definition: health_monitor_disk_state.cc:81
static void get_params()
Storage State - Get params Get the storage threshold params from the disk collector.
Definition: health_monitor_disk_state.cc:46
Storage_State(const char *state_name, State state)
Definition: health_monitor_disk_state.h:50
static bool normal_level()
Storage State - Storage levels.
Definition: health_monitor_disk_state.cc:75
static size_t available_mb
Definition: health_monitor_disk_state.h:75
static Disk_Collector * dc
Definition: health_monitor_disk_state.h:74
static size_t max_warn_level_mb
Definition: health_monitor_disk_state.h:83
virtual void enter()
Definition: health_monitor_disk_state.h:54
virtual ~Storage_State()=default
static void get_levels()
Storage State - Get levels Get the storage levels from the disk collector.
Definition: health_monitor_disk_state.cc:61
static void set_warning_state()
Definition: health_monitor_disk_state.cc:105
static size_t reserve_mb
Definition: health_monitor_disk_state.h:78
static void set_critical_state()
Definition: health_monitor_disk_state.cc:107
State m_state
Definition: health_monitor_disk_state.h:88
Warning State.
Definition: health_monitor_disk_state.h:134
void enter() override
Warning State - Enter Issue a warning immediately upon entering the warning state.
Definition: health_monitor_disk_state.cc:207
void check_levels() override
Warning State - Check levels Issue warnings when the warning level changes.
Definition: health_monitor_disk_state.cc:267
Warning_State()
Definition: health_monitor_disk_state.h:136
static bool check_warning_level()
Warning State - Check warning levels.
Definition: health_monitor_disk_state.cc:219
Definition: mrs_component_embedded_mysql_cache.h:33
Definition: component_command.h:29