MySQL 26.10.0
Source Code Documentation
health_monitor_disk_forecast_reset.h
Go to the documentation of this file.
1/* Copyright (c) 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 <functional>
28#include <mutex>
29#include <vector>
30
33
34namespace hm {
35
36/**
37 The context reset atomically discards all forecasting state, and is used when
38 the monitored filesystem changes.
39
40 Metrics and model state from different filesystems must not share the same
41 time series. If the filesystem changes, then we clear the metric, model,
42 forecast, summary and reporting state before accepting samples for the
43 new filesystem.
44
45 Preserve the metric count and advance the model so old logical indexes are
46 not reused.
47
48 A capacity change (resize) for the same filesystem does not reset the series.
49*/
50
52 std::mutex *series_mutex;
61 std::vector<Disk_Forecast> *last_forecasts;
63 uint64_t *total_mb;
64 uint64_t *last_total_mb;
65 uint64_t *used_mb;
66 double *used_pct;
68};
69
70using Disk_writeable_getter = std::function<bool()>;
71using Disk_writeable_setter = std::function<void(bool)>;
72using Disk_series_reset_action = std::function<void()>;
73
74/**
75 Pause disk metric writes, reset the series and restore the prior write state.
76
77 @param[in] get_writeable Write state reader
78 @param[in] set_writeable Write state setter
79 @param[in] reset_series Locked series reset action
80*/
81void reset_disk_series(const Disk_writeable_getter &get_writeable,
82 const Disk_writeable_setter &set_writeable,
83 const Disk_series_reset_action &reset_series);
84
85/**
86 Return the next logical metric position after clearing retained rows.
87
88 @param[in] total_written Monotonic count of metrics written
89 @return Logical position for the first metric after reset
90*/
91unsigned int disk_metric_position_after_reset(uint64_t total_written);
92
94 size_t &total_metric_count, time_t &last_forecast_time,
95 std::vector<Disk_Forecast> &last_forecasts,
96 Disk_Forecast_Summary &last_forecast_summary, uint64_t &total_mb,
97 uint64_t &last_total_mb, uint64_t &used_mb, double &used_pct,
98 bool &volume_size_changed);
99
100/**
101 Clear metric, model, forecast and reporting state.
102
103 The caller must hold the buffer write lock and forecast model write lock.
104*/
106 const Disk_Metric_Buffer &metric_buffer,
107 const Disk_Metric_Aggregate_Buffer &aggregate_buffer,
108 const Disk_Forecast_Buffer &forecast_buffer,
109 const Disk_Forecast_Summary_Buffer &summary_buffer,
110 Holt_Winters_Forecaster &forecaster, size_t &total_metric_count,
111 time_t &last_forecast_time, std::vector<Disk_Forecast> &last_forecasts,
112 Disk_Forecast_Summary &last_forecast_summary, uint64_t &total_mb,
113 uint64_t &last_total_mb, uint64_t &used_mb, double &used_pct,
114 bool &volume_size_changed);
115
116} // namespace hm
Implements the Holt-Winters forecasting algorithm for time series data.
Definition: fx_holt_winters_forecaster.h:44
Definition: component_command.h:29
unsigned int disk_metric_position_after_reset(const uint64_t total_written)
Return the next logical metric position after clearing retained rows.
Definition: health_monitor_disk_forecast_reset.cc:42
std::shared_ptr< Stat_Buffer< Disk_Metric_Aggregate > > Disk_Metric_Aggregate_Buffer
Definition: health_monitor_disk_bits.h:88
void clear_disk_forecast_series_no_lock(const Disk_Metric_Buffer &metric_buffer, const Disk_Metric_Aggregate_Buffer &aggregate_buffer, const Disk_Forecast_Buffer &forecast_buffer, const Disk_Forecast_Summary_Buffer &summary_buffer, Holt_Winters_Forecaster &forecaster, size_t &total_metric_count, time_t &last_forecast_time, std::vector< Disk_Forecast > &last_forecasts, Disk_Forecast_Summary &last_forecast_summary, uint64_t &total_mb, uint64_t &last_total_mb, uint64_t &used_mb, double &used_pct, bool &volume_size_changed)
Clear metric, model, forecast and reporting state.
Definition: health_monitor_disk_forecast_reset.cc:64
std::shared_ptr< Stat_Buffer< Disk_Forecast_Summary > > Disk_Forecast_Summary_Buffer
Definition: health_monitor_disk_bits.h:135
std::function< void()> Disk_series_reset_action
Definition: health_monitor_disk_forecast_reset.h:72
std::function< void(bool)> Disk_writeable_setter
Definition: health_monitor_disk_forecast_reset.h:71
std::shared_ptr< Stat_Buffer< Disk_Forecast > > Disk_Forecast_Buffer
Definition: health_monitor_disk_bits.h:116
std::function< bool()> Disk_writeable_getter
Definition: health_monitor_disk_forecast_reset.h:70
std::shared_ptr< Metric_Buffer< Disk_Metric > > Disk_Metric_Buffer
Definition: health_monitor_disk_bits.h:72
void reset_disk_series(const Disk_writeable_getter &get_writeable, const Disk_writeable_setter &set_writeable, const Disk_series_reset_action &reset_series)
Pause disk metric writes, reset the series and restore the prior write state.
Definition: health_monitor_disk_forecast_reset.cc:33
void clear_disk_forecast_retained_state(size_t &total_metric_count, time_t &last_forecast_time, std::vector< Disk_Forecast > &last_forecasts, Disk_Forecast_Summary &last_forecast_summary, uint64_t &total_mb, uint64_t &last_total_mb, uint64_t &used_mb, double &used_pct, bool &volume_size_changed)
Definition: health_monitor_disk_forecast_reset.cc:47
Definition: health_monitor_disk_bits.h:118
The context reset atomically discards all forecasting state, and is used when the monitored filesyste...
Definition: health_monitor_disk_forecast_reset.h:51
std::mutex * series_mutex
Definition: health_monitor_disk_forecast_reset.h:52
Disk_Forecast_Summary_Buffer summary_buffer
Definition: health_monitor_disk_forecast_reset.h:56
Holt_Winters_Forecaster * forecaster
Definition: health_monitor_disk_forecast_reset.h:57
Disk_Metric_Buffer metric_buffer
Definition: health_monitor_disk_forecast_reset.h:53
uint64_t * total_mb
Definition: health_monitor_disk_forecast_reset.h:63
Disk_Forecast_Buffer forecast_buffer
Definition: health_monitor_disk_forecast_reset.h:55
uint64_t * used_mb
Definition: health_monitor_disk_forecast_reset.h:65
mysql_rwlock_t * model_lock
Definition: health_monitor_disk_forecast_reset.h:58
bool * volume_size_changed
Definition: health_monitor_disk_forecast_reset.h:67
double * used_pct
Definition: health_monitor_disk_forecast_reset.h:66
std::vector< Disk_Forecast > * last_forecasts
Definition: health_monitor_disk_forecast_reset.h:61
size_t * total_metric_count
Definition: health_monitor_disk_forecast_reset.h:59
time_t * last_forecast_time
Definition: health_monitor_disk_forecast_reset.h:60
Disk_Forecast_Summary * last_forecast_summary
Definition: health_monitor_disk_forecast_reset.h:62
uint64_t * last_total_mb
Definition: health_monitor_disk_forecast_reset.h:64
Disk_Metric_Aggregate_Buffer aggregate_buffer
Definition: health_monitor_disk_forecast_reset.h:54
An instrumented rwlock structure.
Definition: mysql_rwlock_bits.h:51