MySQL 8.4.0
Source Code Documentation
section_config_exposer.h
Go to the documentation of this file.
1/*
2 Copyright (c) 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_SESSION_CONFIG_EXPOSER_INCLUDED
27#define MYSQL_HARNESS_SESSION_CONFIG_EXPOSER_INCLUDED
28
29#include <map>
30#include <string>
31#include <variant>
32
33#include "harness_export.h"
36
37namespace mysql_harness {
38
39/** @class SectionConfigExposer
40 *
41 * @brief Base class for a plugin specific specializations. Lets the plugin
42 * expose their initial and default configuration to the DynamicConfig object.
43 */
44class HARNESS_EXPORT SectionConfigExposer {
45 public:
47
49
50 enum class Mode { ExposeInitialConfig, ExposeDefaultConfig };
51
52 /**
53 * Constructor.
54 *
55 * @param initial flag indicating if the initial or default configuration is
56 * being shared.
57 * @param default_section default section of the current configuration
58 * @param section_id identifier of the plugin configuration in the Dynamic
59 * config object.
60 */
62 const mysql_harness::ConfigSection &default_section,
63 const DC::SectionId &section_id)
64 : mode_(initial ? Mode::ExposeInitialConfig : Mode::ExposeDefaultConfig),
65 default_section_(default_section),
66 section_id_(section_id) {}
67
68 virtual ~SectionConfigExposer() = default;
69
71
72 protected:
73 /**
74 * Exposes plugin instance configuration.
75 */
76 virtual void expose() = 0;
77
78 const Mode mode_;
80
82 const DC::SectionId common_section_id_{"common", ""};
83
84 /**
85 * Exposes single option configuration.
86 *
87 * @param option option name
88 * @param value configured (initial) value of the option
89 * @param default_value default value for both Cluster and ClusterSet
90 * configuration
91 * @param is_common indicates whether the options is supposed to also be
92 * shared in the "common" section of the configuration
93 */
94 void expose_option(const std::string &option, const OptionValue &value,
95 const OptionValue &default_value, bool is_common = false);
96
97 /**
98 * Exposes single option configuration (overload for options that have
99 * different defaults for Cluster and for ClusterSet configuration).
100 *
101 * @param option option name
102 * @param value configured (initial) value of the option
103 * @param default_value_cluster default value for Cluster configuration
104 * @param default_value_clusterset default value for ClusterSet configuration
105 * @param is_common indicates whether the options is supposed to also be
106 * shared in the "common" section of the configuration
107 */
108 void expose_option(const std::string &option, const OptionValue &value,
109 const OptionValue &default_value_cluster,
110 const OptionValue &default_value_clusterset,
111 bool is_common);
112
113 private:
114 void expose_str_option(const std::string &option, const OptionValue &value,
115 const OptionValue &default_value_cluster,
116 const OptionValue &default_value_clusterset,
117 bool is_common = false);
118
119 void expose_int_option(const std::string &option, const OptionValue &value,
120 const OptionValue &default_value_cluster,
121 const OptionValue &default_value_clusterset,
122 bool is_common = false);
123
124 void expose_double_option(const std::string &option, const OptionValue &value,
125 const OptionValue &default_value_cluster,
126 const OptionValue &default_value_clusterset,
127 bool is_common = false);
128
129 void expose_bool_option(const std::string &option, const OptionValue &value,
130 const OptionValue &default_value_cluster,
131 const OptionValue &default_value_clusterset,
132 bool is_common = false);
133
134 void expose_default(const std::string &option,
135 const auto &default_value_cluster,
136 const auto &default_value_clusterset, bool is_common) {
137 DC::instance().set_option_default(
138 section_id_, option, default_value_cluster, default_value_clusterset);
139 if (is_common) {
140 DC::instance().set_option_default(common_section_id_, option,
141 default_value_cluster,
142 default_value_clusterset);
143 }
144 }
145};
146
147} // namespace mysql_harness
148
149#endif // MYSQL_HARNESS_SESSION_CONFIG_EXPOSER_INCLUDED
Configuration section.
Definition: config_parser.h:141
Respresents the current Router configuration.
Definition: dynamic_config.h:48
std::variant< std::monostate, int64_t, bool, double, std::string > OptionValue
Definition: dynamic_config.h:53
std::pair< std::string, std::string > SectionId
Definition: dynamic_config.h:62
Base class for a plugin specific specializations.
Definition: section_config_exposer.h:44
const mysql_harness::ConfigSection & default_section_
Definition: section_config_exposer.h:79
SectionConfigExposer(const SectionConfigExposer &)=delete
const DC::SectionId section_id_
Definition: section_config_exposer.h:81
const Mode mode_
Definition: section_config_exposer.h:78
void expose_default(const std::string &option, const auto &default_value_cluster, const auto &default_value_clusterset, bool is_common)
Definition: section_config_exposer.h:134
SectionConfigExposer(bool initial, const mysql_harness::ConfigSection &default_section, const DC::SectionId &section_id)
Constructor.
Definition: section_config_exposer.h:61
virtual void expose()=0
Exposes plugin instance configuration.
Mode
Definition: section_config_exposer.h:50
virtual ~SectionConfigExposer()=default
DC::OptionValue OptionValue
Definition: section_config_exposer.h:48
Definition: common.h:42