MySQL 9.5.0
Source Code Documentation
router_conf.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2015, 2025, 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 ROUTER_MYSQL_ROUTER_CONF_INCLUDED
27#define ROUTER_MYSQL_ROUTER_CONF_INCLUDED
28
30
31/** @file
32 * @brief Defining the main class MySQLRouter
33 *
34 * This file defines the main class `MySQLRouter`.
35 *
36 */
37
38#include "config_generator.h"
39#include "dim.h"
47
48#include <cstdint>
49#include <iostream>
50#include <memory>
51#include <stdexcept>
52#include <vector>
53
55 public:
57 std::ostream &out_stream = std::cout,
58 std::ostream &err_stream = std::cerr)
59 : keyring_info_(keyring_info),
60 out_stream_(out_stream),
61 err_stream_(err_stream),
62 accounts_cleaner_(err_stream) {}
63
64 virtual ~MySQLRouterConf() = default;
65
66 virtual void prepare_command_options(
67 CmdArgHandler &arg_handler,
68 const std::string &bootstrap_uri = "") noexcept;
69
70 bool is_bootstrap() const { return !bootstrap_uri_.empty(); }
71 virtual bool is_legacy() const { return true; }
72
73 bool skipped() const { return skipped_; }
74
75 void add_option(const std::string &key, const std::string &value) {
77 }
78
79 const std::map<std::string, std::string> &bootstrap_options() const {
80 return bootstrap_options_;
81 }
82
83 public:
84 void connect();
85
86 mysqlrouter::MySQLSession *session() const { return mysql_.get(); }
87
88 std::string bootstrap(
89 const std::string &program_name, const mysql_harness::Path &origin,
90 bool allow_standalone, const std::string &plugin_folder
91#ifndef _WIN32
92 ,
93 mysqlrouter::SysUserOperationsBase *sys_user_operations = nullptr
94#endif
95 );
96
97 std::map<std::string, std::string> get_config_cmdln_options() const;
98
99 void commit() {
102 }
103
105 return accounts_cleaner_;
106 }
107
108 protected:
109 friend class MySQLRouter;
110
111#ifdef FRIEND_TEST
112 FRIEND_TEST(ConfigGeneratorTest, ssl_stage1_cmdline_arg_parse);
113 FRIEND_TEST(ConfigGeneratorTest, ssl_stage2_bootstrap_connection);
114 FRIEND_TEST(ConfigGeneratorTest, ssl_stage3_create_config);
115#endif
116
117 /**
118 * @brief Value of the argument passed to the -B or --bootstrap
119 * command line option for bootstrapping.
120 */
121 std::string bootstrap_uri_;
122 /**
123 * @brief Valueof the argument passed to the --directory command line option
124 */
126 /**
127 * @brief key/value map of additional configuration options for bootstrap
128 */
129 std::map<std::string, std::string> bootstrap_options_;
130
131 /**
132 * @brief key/list-of-values map of additional configuration options for
133 * bootstrap
134 */
135 std::map<std::string, std::vector<std::string>> bootstrap_multivalue_options_;
136
138 std::unique_ptr<mysqlrouter::MySQLSession> mysql_;
139
141
142 bool skipped_ = false;
143
144 std::ostream &out_stream_;
145 std::ostream &err_stream_;
146
147 std::string plugin_folder_;
148
149 /** @brief Saves the selected command line option in the internal options
150 * array after verifying it's value not empty and the router is doing
151 * bootstrap.
152 *
153 * Throws: std::runtime_error
154 */
155 void save_bootstrap_option_not_empty(const std::string &option_name,
156 const std::string &save_name,
157 const std::string &option_value);
158
159 /**
160 * @brief verify that bootstrap option (--bootstrap or -B) was given by user.
161 *
162 * @throw std::runtime_error if called in non-bootstrap mode.
163 */
164 void assert_bootstrap_mode(const std::string &option_name) const;
165
166 int get_connect_timeout() const;
167 int get_read_timeout() const;
168 std::string get_bootstrap_socket() const;
169
172};
173
174class silent_exception : public std::exception {
175 public:
176 silent_exception() : std::exception() {}
177};
178
179#endif // ROUTER_MYSQL_ROUTER_CONF_INCLUDED
Defining the commandline argument handler class CmdArgHandler.
Handles command line arguments.
Definition: arg_handler.h:141
KeyringInfo class encapsulates loading and storing master key using master-key-reader and master-key-...
Definition: keyring_info.h:76
Definition: router_conf.h:54
virtual void prepare_command_options(CmdArgHandler &arg_handler, const std::string &bootstrap_uri="") noexcept
Definition: router_conf.cc:212
bool skipped() const
Definition: router_conf.h:73
bool is_bootstrap() const
Definition: router_conf.h:70
MySQLRouterConf(KeyringInfo &keyring_info, std::ostream &out_stream=std::cout, std::ostream &err_stream=std::cerr)
Definition: router_conf.h:56
bool skipped_
Definition: router_conf.h:142
std::string get_bootstrap_socket() const
Definition: router_conf.cc:1101
int get_read_timeout() const
Definition: router_conf.cc:1091
virtual bool is_legacy() const
Definition: router_conf.h:71
KeyringInfo & keyring_info_
Definition: router_conf.h:140
std::ostream & err_stream_
Definition: router_conf.h:145
std::string bootstrap_directory_
Valueof the argument passed to the –directory command line option.
Definition: router_conf.h:125
void assert_bootstrap_mode(const std::string &option_name) const
verify that bootstrap option (–bootstrap or -B) was given by user.
Definition: router_conf.cc:1074
mysqlrouter::MySQLSession * session() const
Definition: router_conf.h:86
mysql_harness::AutoCleaner auto_cleaner_
Definition: router_conf.h:170
std::map< std::string, std::vector< std::string > > bootstrap_multivalue_options_
key/list-of-values map of additional configuration options for bootstrap
Definition: router_conf.h:135
void commit()
Definition: router_conf.h:99
mysqlrouter::URI target_uri_
Definition: router_conf.h:137
void connect()
Definition: router_conf.cc:1106
std::map< std::string, std::string > get_config_cmdln_options() const
Definition: router_conf.cc:1163
std::map< std::string, std::string > bootstrap_options_
key/value map of additional configuration options for bootstrap
Definition: router_conf.h:129
std::string bootstrap_uri_
Value of the argument passed to the -B or –bootstrap command line option for bootstrapping.
Definition: router_conf.h:121
void save_bootstrap_option_not_empty(const std::string &option_name, const std::string &save_name, const std::string &option_value)
Saves the selected command line option in the internal options array after verifying it's value not e...
Definition: router_conf.cc:1064
int get_connect_timeout() const
Definition: router_conf.cc:1081
mysqlrouter::MySQLAccountsCleaner & get_accounts_cleaner()
Definition: router_conf.h:104
std::unique_ptr< mysqlrouter::MySQLSession > mysql_
Definition: router_conf.h:138
mysqlrouter::MySQLAccountsCleaner accounts_cleaner_
Definition: router_conf.h:171
std::ostream & out_stream_
Definition: router_conf.h:144
const std::map< std::string, std::string > & bootstrap_options() const
Definition: router_conf.h:79
void add_option(const std::string &key, const std::string &value)
Definition: router_conf.h:75
virtual ~MySQLRouterConf()=default
std::string bootstrap(const std::string &program_name, const mysql_harness::Path &origin, bool allow_standalone, const std::string &plugin_folder, mysqlrouter::SysUserOperationsBase *sys_user_operations=nullptr)
Definition: router_conf.cc:1240
std::string plugin_folder_
Definition: router_conf.h:147
Manage the MySQL Router application.
Definition: router_app.h:81
Automatic cleanup on scope exit utility class.
Definition: auto_cleaner.h:62
void clear()
Definition: auto_cleaner.cc:87
Class representing a path in a file system.
Definition: filesystem.h:63
Definition: accounts_cleaner.h:35
void clear()
Definition: accounts_cleaner.h:66
Definition: mysql_session.h:157
Base class to allow multiple SysUserOperations implementations.
Definition: sys_user_operations.h:45
Parse and create URIs according to RFC3986.
Definition: uri.h:66
Definition: router_conf.h:174
silent_exception()
Definition: router_conf.h:176
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
Definition: gcs_xcom_synode.h:64
required string key
Definition: replication_asynchronous_connection_failover.proto:60