MySQL 26.10.0
Source Code Documentation
health_monitor_memory_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 <cstdint>
27#include <string>
28
29namespace hm {
30
31class Memory_Collector;
32
33namespace ms {
34
36 public:
38
39 Memory_State() = default;
40 Memory_State(const char *state_name, State state)
41 : m_name(state_name), m_state(state) {}
42
43 virtual ~Memory_State() = default;
44 virtual void enter() {}
45 virtual void check_levels() {}
46 virtual void exit() {}
48 static void get_params();
49 static void get_levels();
50 enum State state() const { return m_state; }
51
53 static uint64_t available_mb;
54 /* Memory thresholds, set for each settings change */
55 static uint64_t low_space_limit_mb;
56 static uint64_t critical_level_mb;
57 static uint64_t warn_level_1_mb;
58 static uint64_t warn_level_2_mb;
59 static uint64_t warn_level_3_mb;
60 static uint64_t max_warn_level_mb;
61
62 private:
63 const std::string m_name;
65};
66
67/**
68 Start State
69
70 The Memory Collector process thread is starting but has not yet checked the
71 memory levels.
72*/
73class Start_State : public Memory_State {
74 public:
76 Start_State(const Start_State &) = delete;
77 Start_State &operator=(const Start_State &) = delete;
78
79 void check_levels() override;
80};
81
82/**
83 Stop State
84
85 The Memory Collector process thread is stopping. Clean up any remaining tasks.
86*/
87class Stop_State : public Memory_State {
88 public:
90 Stop_State(const Stop_State &) = delete;
91 Stop_State &operator=(const Stop_State &) = delete;
92
93 void check_levels() override;
94};
95
96/**
97 Normal State
98
99 Available memory is above warning levels.
100*/
102 public:
104 void check_levels() override;
105};
106
107/**
108 Warning State
109
110 Available memory is below one or more warning levels.
111*/
113 public:
115 void enter() override;
116 static bool check_warning_level();
117 void check_levels() override;
118};
119
120/**
121 Error State
122
123 The Memory Collector is running but there is an error that prevents it from
124 collecting memory data.
125*/
126class Error_State : public Memory_State {
127 public:
129 void enter() override;
130 void check_levels() override;
131};
132
133} // namespace ms
134} // namespace hm
Memory Collector.
Definition: health_monitor_memory.h:110
Error State.
Definition: health_monitor_memory_state.h:126
void check_levels() override
Error_State()
Definition: health_monitor_memory_state.h:128
void enter() override
Definition: health_monitor_memory_state.h:35
virtual void enter()
Definition: health_monitor_memory_state.h:44
virtual ~Memory_State()=default
static uint64_t low_space_limit_mb
Definition: health_monitor_memory_state.h:55
static void set_collector(Memory_Collector *collector)
Definition: health_monitor_memory_state.h:47
static uint64_t warn_level_2_mb
Definition: health_monitor_memory_state.h:58
virtual void check_levels()
Definition: health_monitor_memory_state.h:45
static void get_params()
Memory State - Get params Get the memory threshold params from the memory collector.
Definition: health_monitor_memory_state.cc:42
static uint64_t warn_level_3_mb
Definition: health_monitor_memory_state.h:59
static void get_levels()
Memory State - Get levels Get the memory levels from the memory collector.
Definition: health_monitor_memory_state.cc:54
State
Definition: health_monitor_memory_state.h:37
@ UNDEF
Definition: health_monitor_memory_state.h:37
@ WARNING
Definition: health_monitor_memory_state.h:37
@ START
Definition: health_monitor_memory_state.h:37
@ ERROR
Definition: health_monitor_memory_state.h:37
@ STOP
Definition: health_monitor_memory_state.h:37
@ NORMAL
Definition: health_monitor_memory_state.h:37
static Memory_Collector * mc
Definition: health_monitor_memory_state.h:52
static uint64_t warn_level_1_mb
Definition: health_monitor_memory_state.h:57
Memory_State(const char *state_name, State state)
Definition: health_monitor_memory_state.h:40
static uint64_t critical_level_mb
Definition: health_monitor_memory_state.h:56
static uint64_t available_mb
Definition: health_monitor_memory_state.h:53
virtual void exit()
Definition: health_monitor_memory_state.h:46
const std::string m_name
Definition: health_monitor_memory_state.h:63
enum State state() const
Definition: health_monitor_memory_state.h:50
static uint64_t max_warn_level_mb
Definition: health_monitor_memory_state.h:60
State m_state
Definition: health_monitor_memory_state.h:64
Normal State.
Definition: health_monitor_memory_state.h:101
void check_levels() override
Normal_State()
Definition: health_monitor_memory_state.h:103
Start State.
Definition: health_monitor_memory_state.h:73
Start_State()
Definition: health_monitor_memory_state.h:75
Start_State(const Start_State &)=delete
void check_levels() override
Start_State & operator=(const Start_State &)=delete
Stop State.
Definition: health_monitor_memory_state.h:87
Stop_State(const Stop_State &)=delete
void check_levels() override
Stop_State()
Definition: health_monitor_memory_state.h:89
Stop_State & operator=(const Stop_State &)=delete
Warning State.
Definition: health_monitor_memory_state.h:112
void check_levels() override
void enter() override
static bool check_warning_level()
Warning_State()
Definition: health_monitor_memory_state.h:114
Definition: mrs_component_embedded_mysql_cache.h:33
Definition: component_command.h:29