MySQL 26.10.0
Source Code Documentation
health_monitor_monitored_path.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 <mutex>
28#include <optional>
29#include <string>
30
31namespace hm {
32
33/**
34 Store and synchronize the effective automatic monitored path.
35*/
37 public:
38 void store(const std::optional<std::string> &path) {
39 std::scoped_lock guard{m_mutex};
42 m_path = path;
43 }
44
46 std::scoped_lock guard{m_mutex};
49 }
50
51 [[nodiscard]] uint64_t generation() const {
52 std::scoped_lock guard{m_mutex};
53 return m_generation;
54 }
55
57 std::scoped_lock guard{m_mutex};
58 if ((!m_refresh_requested && m_path.has_value()) || m_refresh_in_progress) {
59 return false;
60 }
61 m_refresh_requested = false;
63 return true;
64 }
65
66 bool select(const std::string &configured_path, std::string &effective_path,
67 uint64_t &generation) const {
68 std::scoped_lock guard{m_mutex};
70 if (!configured_path.empty()) {
71 effective_path = configured_path;
72 return true;
73 }
74 if (!m_path.has_value()) {
75 effective_path.clear();
76 return false;
77 }
78 effective_path = *m_path;
79 return true;
80 }
81
82 private:
83 mutable std::mutex m_mutex;
84 std::optional<std::string> m_path;
87 uint64_t m_generation{0};
88};
89
90} // namespace hm
Store and synchronize the effective automatic monitored path.
Definition: health_monitor_monitored_path.h:36
bool m_refresh_requested
Definition: health_monitor_monitored_path.h:85
void store(const std::optional< std::string > &path)
Definition: health_monitor_monitored_path.h:38
bool begin_refresh()
Definition: health_monitor_monitored_path.h:56
bool m_refresh_in_progress
Definition: health_monitor_monitored_path.h:86
bool select(const std::string &configured_path, std::string &effective_path, uint64_t &generation) const
Definition: health_monitor_monitored_path.h:66
uint64_t m_generation
Definition: health_monitor_monitored_path.h:87
void request_refresh()
Definition: health_monitor_monitored_path.h:45
std::mutex m_mutex
Definition: health_monitor_monitored_path.h:83
std::optional< std::string > m_path
Definition: health_monitor_monitored_path.h:84
uint64_t generation() const
Definition: health_monitor_monitored_path.h:51
static char * path
Definition: mysqldump.cc:153
Definition: component_command.h:29