MySQL 8.3.0
Source Code Documentation
log_reopen_component.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 2023, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
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 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
25#ifndef MYSQL_HARNESS_LOG_REOPEN_COMPONENT_INCLUDED
26#define MYSQL_HARNESS_LOG_REOPEN_COMPONENT_INCLUDED
27
28#include <memory> // unique_ptr
29
30#include "harness_export.h"
32
33namespace mysql_harness {
34
35/**
36 * component that manages the reopening of logfiles.
37 *
38 * depends on the logging-registry to have initialized all loggers.
39 *
40 * As the loggers are plugins, init() must be called after the Loader
41 * started all the plugins which can be done by:
42 *
43 * @code
44 * loader->after_all_started([](){
45 * LogReopenComponent::get_instance().init();
46 * });
47 * @endcode
48 *
49 * The component should be shut down again after the plugins
50 * start to shutdown again.
51 *
52 * @code
53 * loader->after_first_exit([](){
54 * LogReopenComponent::get_instance().reset();
55 * });
56 * @endcode
57 */
58class HARNESS_EXPORT LogReopenComponent {
59 public:
60 static LogReopenComponent &get_instance();
61
62 // disable copy, as we are a single-instance
64 void operator=(LogReopenComponent const &) = delete;
65
66 // no move either
68 void operator=(LogReopenComponent &&) = delete;
69
70 /**
71 * initialize the log-component.
72 *
73 * starts LogReopen thread.
74 */
75 void init() { log_reopen_ = std::make_unique<LogReopen>(); }
76
77 /**
78 * forwards pointer deref's to the log_reopen instance.
79 */
80 LogReopen *operator->() { return log_reopen_.operator->(); }
81
82 /**
83 * forwards pointer deref's to the log_reopen instance.
84 */
85 const LogReopen *operator->() const { return log_reopen_.operator->(); }
86
87 /**
88 * checks if the component is initialized.
89 */
90 operator bool() const { return (bool)log_reopen_; }
91
92 /**
93 * shutdown the log-component.
94 */
95 void reset() { log_reopen_.reset(); }
96
97 private:
98 LogReopenComponent() = default;
99
100 std::unique_ptr<LogReopen> log_reopen_;
101};
102
103} // namespace mysql_harness
104
105#endif
component that manages the reopening of logfiles.
Definition: log_reopen_component.h:58
void reset()
shutdown the log-component.
Definition: log_reopen_component.h:95
void init()
initialize the log-component.
Definition: log_reopen_component.h:75
const LogReopen * operator->() const
forwards pointer deref's to the log_reopen instance.
Definition: log_reopen_component.h:85
LogReopenComponent(LogReopenComponent &&)=delete
void operator=(LogReopenComponent const &)=delete
std::unique_ptr< LogReopen > log_reopen_
Definition: log_reopen_component.h:100
void operator=(LogReopenComponent &&)=delete
LogReopen * operator->()
forwards pointer deref's to the log_reopen instance.
Definition: log_reopen_component.h:80
LogReopenComponent(LogReopenComponent const &)=delete
Definition: log_reopen.h:37
Definition: common.h:41