MySQL 9.1.0
Source Code Documentation
log_reopen_component.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 2024, 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 designed to work 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 either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQL_HARNESS_LOG_REOPEN_COMPONENT_INCLUDED
27#define MYSQL_HARNESS_LOG_REOPEN_COMPONENT_INCLUDED
28
29#include <memory> // unique_ptr
30
31#include "harness_export.h"
33
34namespace mysql_harness {
35
36/**
37 * component that manages the reopening of logfiles.
38 *
39 * depends on the logging-registry to have initialized all loggers.
40 *
41 * As the loggers are plugins, init() must be called after the Loader
42 * started all the plugins which can be done by:
43 *
44 * @code
45 * loader->after_all_started([](){
46 * LogReopenComponent::get_instance().init();
47 * });
48 * @endcode
49 *
50 * The component should be shut down again after the plugins
51 * start to shutdown again.
52 *
53 * @code
54 * loader->after_first_exit([](){
55 * LogReopenComponent::get_instance().reset();
56 * });
57 * @endcode
58 */
59class HARNESS_EXPORT LogReopenComponent {
60 public:
61 static LogReopenComponent &get_instance();
62
63 // disable copy, as we are a single-instance
65 void operator=(LogReopenComponent const &) = delete;
66
67 // no move either
69 void operator=(LogReopenComponent &&) = delete;
70
71 /**
72 * initialize the log-component.
73 *
74 * starts LogReopen thread.
75 */
76 void init() { log_reopen_ = std::make_unique<LogReopen>(); }
77
78 /**
79 * forwards pointer deref's to the log_reopen instance.
80 */
81 LogReopen *operator->() { return log_reopen_.operator->(); }
82
83 /**
84 * forwards pointer deref's to the log_reopen instance.
85 */
86 const LogReopen *operator->() const { return log_reopen_.operator->(); }
87
88 /**
89 * checks if the component is initialized.
90 */
91 operator bool() const { return (bool)log_reopen_; }
92
93 /**
94 * shutdown the log-component.
95 */
96 void reset() { log_reopen_.reset(); }
97
98 private:
99 LogReopenComponent() = default;
100
101 std::unique_ptr<LogReopen> log_reopen_;
102};
103
104} // namespace mysql_harness
105
106#endif
component that manages the reopening of logfiles.
Definition: log_reopen_component.h:59
void reset()
shutdown the log-component.
Definition: log_reopen_component.h:96
void init()
initialize the log-component.
Definition: log_reopen_component.h:76
const LogReopen * operator->() const
forwards pointer deref's to the log_reopen instance.
Definition: log_reopen_component.h:86
LogReopenComponent(LogReopenComponent &&)=delete
void operator=(LogReopenComponent const &)=delete
std::unique_ptr< LogReopen > log_reopen_
Definition: log_reopen_component.h:101
void operator=(LogReopenComponent &&)=delete
LogReopen * operator->()
forwards pointer deref's to the log_reopen instance.
Definition: log_reopen_component.h:81
LogReopenComponent(LogReopenComponent const &)=delete
Definition: log_reopen.h:38
Definition: common.h:42