MySQL 26.7.0
Source Code Documentation
applier_channel_monitor.h
Go to the documentation of this file.
1// Copyright (c) 2026, 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
24#ifndef MYSQL_CSA_APPLIER_MONITOR_H
25#define MYSQL_CSA_APPLIER_MONITOR_H
26
27#include <chrono>
28#include <cstddef>
29
31
32namespace mysql::csa {
33
35 public:
37
38 /// @brief Initializes monitoring with custom refresh interval (default 10s).
39 /// Resets refresh time to now() and sets interval.
40 /// @param refresh_time Custom interval in milliseconds.
43
44 /// @brief Detects if the applier is stalled by monitoring progress metrics
45 /// (applied events, scheduler/commit clocks, active transactions) over a
46 /// periodic interval (default 10s). If no progress detected and unblock
47 /// attempts remain, calls scheduler unblock function to mitigate stalls.
48 /// Void return; unblock counter limited per stall.
49 /// Call periodically from applier oversight.
51
52 std::size_t get_allowed_unblocks() const;
53 std::size_t get_current_unblock_counter() const;
54 std::size_t get_total_unblock_counter() const;
55
56 private:
57 /// Helper refreshing internal statistics
58 void refresh_values();
59
60 /// Monitored CSA channel reference
62 /// Previous recorded value of applied events
64 /// Current recorded value of applied events
66 /// Previous recorded clock value
67 std::size_t m_previous_clock_value{0};
68 /// Current recorded clock value
69 std::size_t m_current_clock_value{0};
70 /// Active transactions
71 std::size_t m_active_trx{0};
72 /// Previous recorded commit order clock value
74 /// Current recorded commit order clock value
76 /// Last time we refreshed values
77 std::chrono::time_point<std::chrono::system_clock> m_time_refresh;
78 /// Refresh current values (and previous) each 'm_refresh_interval' seconds
80 /// Current attempts to unblocking the applier
82 /// Total attempts to unblocking the applier
84 /// Allowed clock unblocks for the current stall
85 std::size_t m_allowed_unblocks{0};
86};
87
88} // namespace mysql::csa
89
90#endif // MYSQL_CSA_APPLIER_MONITOR_H
Definition: applier_channel_monitor.h:34
std::size_t m_previous_commit_clock_value
Previous recorded commit order clock value.
Definition: applier_channel_monitor.h:73
std::chrono::milliseconds m_refresh_interval
Refresh current values (and previous) each 'm_refresh_interval' seconds.
Definition: applier_channel_monitor.h:79
std::chrono::time_point< std::chrono::system_clock > m_time_refresh
Last time we refreshed values.
Definition: applier_channel_monitor.h:77
std::size_t get_allowed_unblocks() const
Definition: applier_channel_monitor.cpp:95
void check_applier_progress()
Detects if the applier is stalled by monitoring progress metrics (applied events, scheduler/commit cl...
Definition: applier_channel_monitor.cpp:56
std::size_t m_previous_applied_events
Previous recorded value of applied events.
Definition: applier_channel_monitor.h:63
std::size_t m_active_trx
Active transactions.
Definition: applier_channel_monitor.h:71
void init_monitoring(std::chrono::milliseconds refresh_time=std::chrono::milliseconds{10000})
Initializes monitoring with custom refresh interval (default 10s).
Definition: applier_channel_monitor.cpp:35
Csa_channel & m_channel
Monitored CSA channel reference.
Definition: applier_channel_monitor.h:61
std::size_t get_current_unblock_counter() const
Definition: applier_channel_monitor.cpp:99
std::size_t m_total_unblock_counter
Total attempts to unblocking the applier.
Definition: applier_channel_monitor.h:83
std::size_t m_current_commit_clock_value
Current recorded commit order clock value.
Definition: applier_channel_monitor.h:75
std::size_t m_current_unblock_counter
Current attempts to unblocking the applier.
Definition: applier_channel_monitor.h:81
std::size_t m_current_clock_value
Current recorded clock value.
Definition: applier_channel_monitor.h:69
std::size_t m_current_applied_events
Current recorded value of applied events.
Definition: applier_channel_monitor.h:65
std::size_t m_previous_clock_value
Previous recorded clock value.
Definition: applier_channel_monitor.h:67
std::size_t m_allowed_unblocks
Allowed clock unblocks for the current stall.
Definition: applier_channel_monitor.h:85
std::size_t get_total_unblock_counter() const
Definition: applier_channel_monitor.cpp:103
Applier_channel_monitor(Csa_channel &channel)
Definition: applier_channel_monitor.cpp:32
void refresh_values()
Helper refreshing internal statistics.
Definition: applier_channel_monitor.cpp:42
std::chrono::milliseconds milliseconds
Definition: authorize_manager.cc:69
Definition: channel.cpp:28
Definition: task.h:427
Aggregates applier structures for a single channel.
Definition: csa_channel.h:40