MySQL 8.3.0
Source Code Documentation
config_generator.cc File Reference
#include "config_generator.h"
#include <sys/stat.h>
#include <algorithm>
#include <array>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stdexcept>
#include <system_error>
#include <rapidjson/rapidjson.h>
#include "certificate_handler.h"
#include "common.h"
#include "config_builder.h"
#include "dim.h"
#include "harness_assert.h"
#include "hostname_validator.h"
#include "keyring/keyring_manager.h"
#include "mysql/harness/config_option.h"
#include "mysql/harness/config_parser.h"
#include "mysql/harness/dynamic_state.h"
#include "mysql/harness/logging/logging.h"
#include "mysql/harness/logging/supported_logger_options.h"
#include "mysql/harness/stdx/expected.h"
#include "mysql/harness/supported_config_options.h"
#include "mysql/harness/utility/string.h"
#include "mysql/harness/vt100.h"
#include "mysqld_error.h"
#include "mysqlrouter/default_paths.h"
#include "mysqlrouter/supported_connection_pool_options.h"
#include "mysqlrouter/supported_http_options.h"
#include "mysqlrouter/supported_metadata_cache_options.h"
#include "mysqlrouter/supported_rest_options.h"
#include "mysqlrouter/supported_router_options.h"
#include "mysqlrouter/supported_routing_options.h"
#include "mysqlrouter/uri.h"
#include "mysqlrouter/utils.h"
#include "mysqlrouter/utils_sqlstring.h"
#include "random_generator.h"
#include "router_app.h"
#include "router_config.h"
#include "scope_guard.h"
#include "sha1.h"
#include "cluster_metadata.h"
#include "mysqlrouter/cluster_metadata_dynamic_state.h"

Classes

struct  anonymous_namespace{config_generator.cc}::password_too_weak
 
struct  anonymous_namespace{config_generator.cc}::account_exists
 
class  ClusterAwareDecorator
 Cluster (GR or AR)-aware decorator for MySQL Sessions. More...
 
class  anonymous_namespace{config_generator.cc}::ChangeRouterAccountPlugin
 
class  anonymous_namespace{config_generator.cc}::ConfigSectionPrinter
 

Namespaces

namespace  anonymous_namespace{config_generator.cc}
 

Macros

#define MYSQL_ROUTER_LOG_DOMAIN    ::mysql_harness::logging::kMainLogger
 
#define ADD_CONFIG_LINE_CHECKED(section, option, value, supported_options)
 
#define ADD_CONFIG_LINE_CHECKED_WITH_EMPTY(section, option, value, supported_options)
 

Enumerations

enum class  MySQLErrorc { kSyntaxError = ER_PARSE_ERROR , kSuperReadOnly = ER_OPTION_PREVENTS_STATEMENT , kLostConnection = CR_SERVER_LOST }
 Error codes for MySQL Errors that we handle specifically. More...
 
enum class  anonymous_namespace{config_generator.cc}::EndpointMode { anonymous_namespace{config_generator.cc}::kEndpointModeRW , anonymous_namespace{config_generator.cc}::kEndpointModeRO , anonymous_namespace{config_generator.cc}::kEndpointModeRWSplit }
 

Functions

static bool is_valid_name (const std::string &name)
 
std::string get_opt (const std::map< std::string, std::string > &map, const std::string &key, const std::string &default_value)
 
static stdx::expected< std::ofstream, std::error_code > open_ofstream (const std::string &file_name)
 
unsigned anonymous_namespace{config_generator.cc}::get_password_retries (const std::map< std::string, std::string > &user_options)
 
std::string anonymous_namespace{config_generator.cc}::str (const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
 
bool anonymous_namespace{config_generator.cc}::is_valid_conf_ident (const std::string &name)
 
std::map< std::string, std::string > anonymous_namespace{config_generator.cc}::get_config_cmdln_options (const std::map< std::string, std::vector< std::string > > &multivalue_options)
 
static std::string generate_username (uint32_t router_id, mysql_harness::RandomGeneratorInterface &rg)
 
static std::string get_target_cluster_value (const std::string &target_cluster_option, const std::string &target_cluster_by_name_option, const ClusterInfo &cluster_info)
 
void anonymous_namespace{config_generator.cc}::add_endpoint_option (ConfigSectionPrinter &routing_section, const ConfigGenerator::Options &options, const ConfigGenerator::Options::Endpoint &ep)
 
void anonymous_namespace{config_generator.cc}::add_metadata_cache_routing_section (std::ostream &config_file, bool is_classic, const EndpointMode endpoint_mode, const ConfigGenerator::Options::Endpoint endpoint, const ConfigGenerator::Options &options, const std::string &metadata_key, const std::string &cluster_name, const std::map< std::string, std::string > &config_cmdln_options)
 
static void anonymous_namespace{config_generator.cc}::add_http_auth_backend_section (std::ostream &config_file, const mysql_harness::Path &datadir, const std::string_view auth_backend_name, const mysqlrouter::MetadataSchemaVersion schema_version, const std::map< std::string, std::string > &config_cmdln_options)
 Add proper authentication backend section to the config based on the metadata version. More...
 
void anonymous_namespace{config_generator.cc}::add_rest_section (std::ostream &config_file, const ConfigGenerator::Options &options, const std::map< std::string, std::string > &default_paths, const std::map< std::string, std::string > &config_cmdln_options, const std::string &ssl_cert, const std::string &ssl_key, const mysqlrouter::MetadataSchemaVersion &schema_version)
 
static void save_initial_dynamic_state (std::ostream &state_stream, ClusterMetadata &cluster_metadata, const std::string &cluster_type_specific_id, const std::vector< std::string > &metadata_server_addresses)
 
uint16_t get_x_protocol_port (const mysql_harness::Config &conf, const std::string &role)
 
std::string anonymous_namespace{config_generator.cc}::get_cluster_type_specific_uuid (const mysql_harness::Config &conf, mysqlrouter::ClusterType cluster_type)
 
static bool files_equal (const std::string &f1, const std::string &f2)
 

Variables

static const int kDefaultRWPort = 6446
 
static const int kDefaultROPort = 6447
 
static const int kDefaultRWSplitPort = 6450
 
static const char * kRWSocketName = "mysql.sock"
 
static const char * kROSocketName = "mysqlro.sock"
 
static const char * kRWSplitSocketName = "mysqlsplit.sock"
 
static const int kLegacyDefaultRWXPort = 64460
 
static const int kLegacyDefaultROXPort = 64470
 
static const int kBasePortDefault = -1
 
static const int kBasePortLegacyDefault = 0
 
static const char * kRWXSocketName = "mysqlx.sock"
 
static const char * kROXSocketName = "mysqlxro.sock"
 
static const int kMaxTCPPortNumber = 65535
 
static const int kAllocatedTCPPortCount = 4
 
static const std::string kSystemRouterName = "system"
 
static const int kMetadataServerPasswordLength = 16
 
static const int kMaxRouterNameLength
 
static const char * kKeyringAttributePassword = "password"
 
static const std::chrono::milliseconds kDefaultMetadataTTL
 
static const std::chrono::milliseconds kDefaultMetadataTTLGRNotificationsON
 
static const std::chrono::milliseconds kDefaultMetadataTTLClusterSet
 
static const std::chrono::milliseconds kDefaultAuthCacheTTL
 
static const std::chrono::milliseconds kDefaultAuthCacheRefreshInterval
 
static constexpr uint32_t kMaxRouterId
 
static constexpr unsigned kNumRandomChars = 12
 
static constexpr unsigned kDefaultPasswordRetries
 
static constexpr unsigned kMaxPasswordRetries = 10000
 
static const std::string kDefaultMetadataCacheSectionKey = "bootstrap"
 
const char kAppArmorMsg []
 

Macro Definition Documentation

◆ ADD_CONFIG_LINE_CHECKED

#define ADD_CONFIG_LINE_CHECKED (   section,
  option,
  value,
  supported_options 
)
Value:
(section).add_line(option, value);
static constexpr std::array supported_options
Definition: connection_pool_plugin.cc:61
static bool add_line(String &buffer, char *line, size_t line_length, char *in_string, bool *ml_comment, bool truncated)
Definition: mysql.cc:2740
constexpr bool str_in_collection(const T &t, const std::string_view &k)
Definition: string.h:156

◆ ADD_CONFIG_LINE_CHECKED_WITH_EMPTY

#define ADD_CONFIG_LINE_CHECKED_WITH_EMPTY (   section,
  option,
  value,
  supported_options 
)
Value:
(section).add_line(option, value, true);

◆ MYSQL_ROUTER_LOG_DOMAIN

#define MYSQL_ROUTER_LOG_DOMAIN    ::mysql_harness::logging::kMainLogger

Enumeration Type Documentation

◆ MySQLErrorc

enum class MySQLErrorc
strong

Error codes for MySQL Errors that we handle specifically.

Enumerator
kSyntaxError 
kSuperReadOnly 
kLostConnection 

Function Documentation

◆ files_equal()

static bool files_equal ( const std::string &  f1,
const std::string &  f2 
)
static

◆ generate_username()

static std::string generate_username ( uint32_t  router_id,
mysql_harness::RandomGeneratorInterface rg 
)
static

◆ get_opt()

std::string get_opt ( const std::map< std::string, std::string > &  map,
const std::string &  key,
const std::string &  default_value 
)
inline

◆ get_target_cluster_value()

static std::string get_target_cluster_value ( const std::string &  target_cluster_option,
const std::string &  target_cluster_by_name_option,
const ClusterInfo cluster_info 
)
static

◆ get_x_protocol_port()

uint16_t get_x_protocol_port ( const mysql_harness::Config conf,
const std::string &  role 
)

◆ is_valid_name()

static bool is_valid_name ( const std::string &  name)
static

◆ open_ofstream()

static stdx::expected< std::ofstream, std::error_code > open_ofstream ( const std::string &  file_name)
static

◆ save_initial_dynamic_state()

static void save_initial_dynamic_state ( std::ostream &  state_stream,
ClusterMetadata cluster_metadata,
const std::string &  cluster_type_specific_id,
const std::vector< std::string > &  metadata_server_addresses 
)
static

Variable Documentation

◆ kAllocatedTCPPortCount

const int kAllocatedTCPPortCount = 4
static

◆ kAppArmorMsg

const char kAppArmorMsg[]
Initial value:
=
"This may be caused by insufficient rights or AppArmor settings.\n"
"If you have AppArmor enabled try adding full path to the output directory "
"in the mysqlrouter profile file:\n"
"/etc/apparmor.d/usr.bin.mysqlrouter\n\n"
"Example:\n\n"
" /path/to/your/output/dir rw,\n"
" /path/to/your/output/dir/** rw,"

◆ kBasePortDefault

const int kBasePortDefault = -1
static

◆ kBasePortLegacyDefault

const int kBasePortLegacyDefault = 0
static

◆ kDefaultAuthCacheRefreshInterval

const std::chrono::milliseconds kDefaultAuthCacheRefreshInterval
static
Initial value:
=
std::chrono::milliseconds(2000)

◆ kDefaultAuthCacheTTL

const std::chrono::milliseconds kDefaultAuthCacheTTL
static
Initial value:
=
double seconds()
Definition: task.cc:309

◆ kDefaultMetadataCacheSectionKey

const std::string kDefaultMetadataCacheSectionKey = "bootstrap"
static

◆ kDefaultMetadataTTL

const std::chrono::milliseconds kDefaultMetadataTTL
static
Initial value:
=
std::chrono::milliseconds(500)

◆ kDefaultMetadataTTLClusterSet

const std::chrono::milliseconds kDefaultMetadataTTLClusterSet
static
Initial value:
=
std::chrono::milliseconds(
5 * 1000)

◆ kDefaultMetadataTTLGRNotificationsON

const std::chrono::milliseconds kDefaultMetadataTTLGRNotificationsON
static
Initial value:
=
std::chrono::milliseconds(60 * 1000)

◆ kDefaultPasswordRetries

constexpr unsigned kDefaultPasswordRetries
staticconstexpr
Initial value:
=
20

◆ kDefaultROPort

const int kDefaultROPort = 6447
static

◆ kDefaultRWPort

const int kDefaultRWPort = 6446
static

◆ kDefaultRWSplitPort

const int kDefaultRWSplitPort = 6450
static

◆ kKeyringAttributePassword

const char* kKeyringAttributePassword = "password"
static

◆ kLegacyDefaultROXPort

const int kLegacyDefaultROXPort = 64470
static

◆ kLegacyDefaultRWXPort

const int kLegacyDefaultRWXPort = 64460
static

◆ kMaxPasswordRetries

constexpr unsigned kMaxPasswordRetries = 10000
staticconstexpr

◆ kMaxRouterId

constexpr uint32_t kMaxRouterId
staticconstexpr
Initial value:
=
999999

◆ kMaxRouterNameLength

const int kMaxRouterNameLength
static
Initial value:
=
255

◆ kMaxTCPPortNumber

const int kMaxTCPPortNumber = 65535
static

◆ kMetadataServerPasswordLength

const int kMetadataServerPasswordLength = 16
static

◆ kNumRandomChars

constexpr unsigned kNumRandomChars = 12
staticconstexpr

◆ kROSocketName

const char* kROSocketName = "mysqlro.sock"
static

◆ kROXSocketName

const char* kROXSocketName = "mysqlxro.sock"
static

◆ kRWSocketName

const char* kRWSocketName = "mysql.sock"
static

◆ kRWSplitSocketName

const char* kRWSplitSocketName = "mysqlsplit.sock"
static

◆ kRWXSocketName

const char* kRWXSocketName = "mysqlx.sock"
static

◆ kSystemRouterName

const std::string kSystemRouterName = "system"
static