MySQL 8.4.2
Source Code Documentation
mysql_harness Namespace Reference

Namespaces

namespace  anonymous_namespace{random_generator.cc}
 
namespace  anonymous_namespace{string_utils.cc}
 
namespace  detail
 
namespace  impl
 
namespace  loader
 
namespace  logging
 
namespace  posix
 
namespace  utility
 

Classes

class  bad_option
 Exception thrown for option problems. More...
 
class  bad_option_value
 Exception thrown for option value problems. More...
 
class  bad_section
 Exception thrown for section problems. More...
 
class  BasePluginConfig
 Retrieve and manage plugin configuration. More...
 
class  BoolOption
 
class  BuiltinPlugins
 Singleton class implementing registry of the built-in MySQLRouter plugins. More...
 
class  Config
 Configuration. More...
 
class  ConfigBuilder
 builder for MySQL Router config files. More...
 
class  ConfigSection
 Configuration section. More...
 
class  decryption_error
 
class  DIM
 
class  Directory
 Class representing a directory in a file system. More...
 
class  DurationOption
 
class  DynamicConfig
 Respresents the current Router configuration. More...
 
class  DynamicLibrary
 A DynamicLibrary. More...
 
class  DynamicLoader
 Loader for DynamicLibrary. More...
 
class  DynamicState
 DynamicState represents a MySQLRouter dynamic state object. More...
 
class  EventStateTracker
 EventStateTracker singleton object keeps track of the current known state of selected event. More...
 
class  FakeRandomGenerator
 
class  FloatingPointOption
 
class  IntOption
 
class  invalid_master_keyfile
 
class  Keyring
 Keyring interface. More...
 
class  KeyringFile
 KeyringFile class. More...
 
class  KeyringMemory
 KeyringMemory class. More...
 
class  Loader
 
class  LoaderConfig
 Configuration file handler for the loader. More...
 
class  LogReopen
 
class  LogReopenComponent
 component that manages the reopening of logfiles. More...
 
class  MasterKeyFile
 
class  MPMCQueueMS2Lock
 a unbounded multi-producer multi-consumer queue. More...
 
class  MPSCQueueDV
 a unbounded multi-producer single-consumer queue. More...
 
struct  mysql_router_thread_handle
 
class  MySQLRouterThread
 MySQLRouterThread provides higher level interface to managing threads. More...
 
class  option_empty
 Exception that gets thrown when the configuration option is present but it is empty value. More...
 
class  option_not_present
 Exception that gets thrown when the configuration option is missing. More...
 
class  Path
 Class representing a path in a file system. More...
 
class  PluginFuncEnv
 PluginFuncEnv object. More...
 
class  PluginThreads
 
class  ProcessLauncher
 
class  ProcessStateComponent
 manages the state of the process. More...
 
class  RandomGenerator
 
class  RandomGeneratorInterface
 
class  Range
 Convenience class for handling iterator range. More...
 
class  SectionConfigExposer
 Base class for a plugin specific specializations. More...
 
class  ShutdownPending
 
class  SignalHandler
 
class  SocketOperations
 This class provides a "real" (not mock) implementation. More...
 
class  SocketOperationsBase
 Base class to allow multiple SocketOperations implementations (at least one "real" and one mock for testing purposes) More...
 
class  SpawnedProcess
 an alive, spawned process More...
 
class  StringOption
 
class  syntax_error
 Exception thrown for syntax errors. More...
 
class  TCPAddress
 Defines an IP address with port number
More...
 
class  UniquePtr
 
class  WaitingQueueAdaptor
 provide waiting pop and push operator to thread-safe queues. More...
 

Typedefs

using security_descriptor_type = posix::access_rights::security_descriptor_type
 
using DenyOtherReadWritableVerifier = posix::access_rights::DenyPermissionVerifier<(S_IRWXO)>
 fail access_rights_verify() if others can read or write or execute. More...
 
using AllowUserReadWritableVerifier = posix::access_rights::AllowPermissionVerifier<(S_IRUSR|S_IWUSR)>
 fail access_rights_verify() if someone else then the owner of the file can read or write. More...
 
using DoubleOption = FloatingPointOption< double >
 
using MilliSecondsOption = DurationOption< std::chrono::milliseconds >
 a double option with milli-second precision. More...
 
using JsonAllocator = rapidjson::CrtAllocator
 
using JsonValue = rapidjson::GenericValue< rapidjson::UTF8<>, JsonAllocator >
 
using perm_mode = mode_t
 
template<typename T >
using MPMCQueue = MPMCQueueMS2Lock< T >
 
template<typename T >
using WaitingMPMCQueue = WaitingQueueAdaptor< MPMCQueue< T > >
 
template<typename T >
using MPSCQueue = MPSCQueueDV< T >
 
template<typename T >
using WaitingMPSCQueue = WaitingQueueAdaptor< MPSCQueue< T > >
 
using Ssl = std::unique_ptr< SSL, mysql_harness::impl::Deleter_SSL >
 
typedef pthread_t mysql_router_thread_t
 
typedef pthread_attr_t mysql_router_thread_attr_t
 
typedef void *(* my_start_routine) (void *)
 
using socket_t = net::impl::socket::native_handle_type
 

Enumerations

enum class  DynamicLoaderErrc { kDlError = 1 }
 error-codes of the DynamicLoader and DynamicLibrary. More...
 

Functions

HARNESS_EXPORT std::string truncate_string (const std::string &str, size_t max_len=80)
 Return a truncated version of input string. More...
 
template<class InputIt >
void serial_comma (std::ostream &out, InputIt start, InputIt finish, const std::string &delim="and")
 Emit a range of elements using the serial comma. More...
 
template<class InputIt >
std::string serial_comma (InputIt start, InputIt finish, const std::string &delim="and")
 Returns string containing list of the elements using the serial comma. More...
 
template<class Key , class Value >
Value get_from_map (const std::map< Key, Value > &map, const Key &key, const Value &default_value)
 Gets a Value from std::map for given Key. More...
 
template<class T >
std::string hexify (const T &buf)
 hexdump into a string. More...
 
bool HARNESS_EXPORT is_valid_ip_address (const std::string &address)
 
bool HARNESS_EXPORT is_valid_hostname (const std::string &address)
 check if address is a hostname. More...
 
bool HARNESS_EXPORT is_valid_domainname (const std::string &address)
 check if address is a domainname. More...
 
HARNESS_EXPORT bool init_keyring (const std::string &keyring_file_path, const std::string &master_key_path, bool create_if_needed)
 Initialize an instance of a keyring to be used in the application from the contents of a file, using the given master key file. More...
 
HARNESS_EXPORT bool init_keyring_with_key (const std::string &keyring_file_path, const std::string &master_key, bool create_if_needed)
 Initialize an instance of a keyring to be used in the application from the contents of a file, using the given master key. More...
 
HARNESS_EXPORT void flush_keyring ()
 Saves the keyring contents to disk. More...
 
HARNESS_EXPORT Keyringget_keyring () noexcept
 Gets a previously initialized singleton instance of the keyring. More...
 
HARNESS_EXPORT void reset_keyring () noexcept
 Clears the keyring singleton. More...
 
HARNESS_EXPORT stdx::expected< security_descriptor_type, std::error_code > access_rights_get (const std::string &file_name) noexcept
 get a access rights of file. More...
 
template<class Func >
stdx::expected< void, std::error_code > access_rights_verify (const security_descriptor_type &rights, Func &&func)
 check if a security descriptor satisfies a verifier. More...
 
HARNESS_EXPORT stdx::expected< void, std::error_code > access_rights_set (const std::string &file_name, const security_descriptor_type &sec_desc)
 set access rights of a file. More...
 
double HARNESS_EXPORT option_as_double (const std::string &value, const std::string &option_desc, double min_value=0, double max_value=std::numeric_limits< double >::max())
 
template<typename T >
option_as_int (const std::string_view &value, const std::string &option_desc, T min_value=std::numeric_limits< T >::min(), T max_value=std::numeric_limits< T >::max())
 Gets an integer using the given option value. More...
 
template<typename T >
option_as_uint (const std::string_view &value, const std::string &option_desc, T min_value=std::numeric_limits< T >::min(), T max_value=std::numeric_limits< T >::max())
 Get a unsigned integer. More...
 
bool HARNESS_EXPORT is_valid_conf_ident_char (const char ch)
 Returns true if a character given as a parameter is valid for config identifier (section, section key or option name) More...
 
std::error_code make_error_code (DynamicLoaderErrc ec)
 make error_code from a DynamicLoaderErrc. More...
 
HARNESS_EXPORT stdx::expected< void, std::error_code > delete_dir (const std::string &dir) noexcept
 Removes a directory. More...
 
HARNESS_EXPORT stdx::expected< void, std::error_code > delete_file (const std::string &path) noexcept
 Removes a file. More...
 
HARNESS_EXPORT stdx::expected< void, std::error_code > delete_dir_recursive (const std::string &dir) noexcept
 Removes directory and all its contents. More...
 
HARNESS_EXPORT std::string get_tmp_dir (const std::string &name="router")
 Creates a temporary directory with partially-random name and returns its path. More...
 
HARNESS_EXPORT std::string get_plugin_dir (const std::string &runtime_dir)
 
HARNESS_EXPORT std::string get_tests_data_dir (const std::string &runtime_dir)
 
HARNESS_EXPORT int mkdir (const std::string &dir, perm_mode mode, bool recursive=false)
 Creates a directory *. More...
 
void HARNESS_EXPORT make_file_public (const std::string &file_name)
 Changes file access permissions to be fully accessible by all users. More...
 
void HARNESS_EXPORT make_file_private (const std::string &file_name, const bool read_only_for_local_service=true)
 Changes file access permissions to be accessible only by a limited set of users. More...
 
void HARNESS_EXPORT make_file_readonly (const std::string &file_name)
 Changes file access permissions to be read only. More...
 
void HARNESS_EXPORT check_file_access_rights (const std::string &file_name)
 Verifies access permissions of a file. More...
 
std::string HARNESS_EXPORT to_string (const ShutdownPending::Reason &reason)
 
bool HARNESS_EXPORT notify_status (const std::string &msg)
 
bool HARNESS_EXPORT notify_ready ()
 
bool HARNESS_EXPORT notify_stopping ()
 
HARNESS_EXPORT std::vector< std::string > split_string (const std::string_view &data, const char delimiter, bool allow_empty=true)
 Splits a string using a delimiter. More...
 
HARNESS_EXPORT void left_trim (std::string &str)
 Removes leading whitespaces from the string. More...
 
HARNESS_EXPORT void right_trim (std::string &str)
 Removes trailing whitespaces from the string. More...
 
HARNESS_EXPORT void trim (std::string &str)
 Removes both leading and trailing whitespaces from the string. More...
 
HARNESS_EXPORT std::string limit_lines (const std::string &str, const size_t limit, const std::string &replace_with="")
 Returns the input string with number of lines reduced to selected value. More...
 
template<class Container >
std::string join (Container cont, const std::string &delim)
 join elements of an container into a string separated by a delimiter. More...
 
template<class T >
constexpr bool str_in_collection (const T &t, const std::string_view &k)
 
HARNESS_EXPORT stdx::expected< TCPAddress, std::error_code > make_tcp_address (const std::string &endpoint)
 create TCPAddress from endpoint string. More...
 
static void inplace_lower (std::string *str)
 
static std::string lower (std::string_view str)
 
static void check_option (std::string_view str)
 
const std::error_category & dynamic_loader_category () noexcept
 
int mkdir_wrapper (const std::string &dir, perm_mode mode)
 
static stdx::expected< void, std::error_code > make_file_private_win32 (const std::string &filename, const bool read_only_for_local_service)
 Makes a file fully accessible by the current process user and (read only or read/write depending on the second argument) for LocalService account (which is the account under which the MySQL router runs as service). More...
 
static stdx::expected< void, std::error_code > set_everyone_group_access_rights (const std::string &file_name, DWORD mask)
 Sets file permissions for Everyone group. More...
 
void make_file_readable_for_everyone (const std::string &file_name)
 
static const char * file_type_name (Path::FileType type)
 
std::ostream & operator<< (std::ostream &out, Path::FileType type)
 
int mkdir_recursive (const Path &path, perm_mode mode)
 
static void verify_file_permissions (const std::string &file_name)
 
static std::pair< std::string, std::string > get_master_key (MasterKeyFile &mkf, const std::string &keyring_file_path, bool create_if_needed)
 Gets the master_key for the specified keyring_file from the master key store. More...
 
static std::pair< std::string, std::string > create_initial_keyring_pair (MasterKeyFile &mkf, const std::string &keyring_file_path, std::string master_scramble)
 
const AppInfo * get_app_info (const PluginFuncEnv *env) noexcept
 
const ConfigSectionget_config_section (const PluginFuncEnv *env) noexcept
 
bool is_running (const PluginFuncEnv *env) noexcept
 
bool wait_for_stop (const PluginFuncEnv *env, uint32_t milliseconds) noexcept
 
void clear_running (PluginFuncEnv *env) noexcept
 
void set_error (PluginFuncEnv *env, ErrorType error_type, const char *fmt,...) noexcept
 
template<class T >
value_or (T a, T b)
 If a isn't set, return b. More...
 
static void call_plugin_function (PluginFuncEnv *env, std::exception_ptr &eptr, void(*fptr)(PluginFuncEnv *), const char *fnc_name, const char *plugin_name, const char *plugin_key=nullptr) noexcept
 
static std::string section_to_string (const ConfigSection *section)
 
static void report_unsupported_option (const std::string &section, const std::string &option, const bool error_out)
 
void on_service_ready (const std::string &name)
 
void on_service_ready (PluginFuncEnv *plugin_env)
 
static int mysql_router_thread_attr_init (mysql_router_thread_attr_t *attr)
 
static int mysql_router_thread_attr_setstacksize (mysql_router_thread_attr_t *attr, size_t stacksize)
 
static int mysql_router_thread_attr_setdetachstate (mysql_router_thread_attr_t *attr, int detachstate)
 
static bool mysql_router_thread_started (const mysql_router_thread_handle *thread)
 checks if thread pointed by thread was started More...
 
static bool mysql_router_thread_joinable (const mysql_router_thread_attr_t *attr)
 checks if thread pointed by attr is joinable More...
 
int mysql_router_thread_create (mysql_router_thread_handle *thread, const mysql_router_thread_attr_t *attr, my_start_routine func, void *arg)
 
int mysql_router_thread_join (mysql_router_thread_handle *thread, void **value_ptr)
 
static std::string option_description (std::string_view section_name, std::string_view option)
 
static std::error_code last_error_code () noexcept
 
static std::vector< const char * > get_params (const std::string &command, const std::vector< std::string > &params_vec)
 
static auto get_env_vars_vector (const std::vector< std::pair< std::string, std::string > > &env_vars)
 
static auto get_env_vars (const std::vector< std::string > &env_vars)
 
static std::string get_notify_socket_name ()
 
static stdx::expected< local::datagram_protocol::socket, std::error_code > connect_to_notify_socket (net::io_context &io_ctx, const std::string &socket_name)
 
static stdx::expected< void, std::error_code > notify (const std::string &msg, const std::string &socket_name)
 
static bool notify (const std::string &msg)
 
static void shrink (std::string &s)
 
static stdx::expected< std::string, std::error_code > endpoint_to_name (const net::ip::tcp::endpoint &ep)
 
static SocketOperationsBase::LocalHostnameResolutionError make_local_hostname_resolution_error (const std::error_code &ec)
 
static stdx::expected< TCPAddress, std::error_code > make_tcp_address_ipv6 (const std::string &endpoint)
 

Variables

static const int kMaxKeyringKeyLength = 255
 
HARNESS_EXPORT const perm_mode kStrictDirectoryPerm = S_IRWXU
 
static constexpr std::array loader_supported_options
 
static const size_t kDefaultStackSizeInKiloBytes = 1024
 
static constexpr mysql_router_thread_t null_thread_initializer
 
constexpr socket_t kInvalidSocket = net::impl::socket::kInvalidSocket
 
static std::unique_ptr< KeyringFileg_keyring
 
static std::string g_keyring_file_path
 
static std::string g_keyring_key
 
static const unsigned kKeyLength = 32
 
static const std::array< char, 5 > kMasterKeyFileSignature
 
static constexpr unsigned char kAesIv []
 
constexpr auto kTerminateWaitInterval = std::chrono::seconds(10)
 
constexpr auto kWaitPidCheckInterval = std::chrono::milliseconds(10)
 maximum number of parameters that can be passed to the launched process More...
 

Typedef Documentation

◆ AllowUserReadWritableVerifier

fail access_rights_verify() if someone else then the owner of the file can read or write.

◆ DenyOtherReadWritableVerifier

fail access_rights_verify() if others can read or write or execute.

◆ DoubleOption

◆ JsonAllocator

using mysql_harness::JsonAllocator = typedef rapidjson::CrtAllocator

◆ JsonValue

using mysql_harness::JsonValue = typedef rapidjson::GenericValue<rapidjson::UTF8<>, JsonAllocator>

◆ MilliSecondsOption

using mysql_harness::MilliSecondsOption = typedef DurationOption<std::chrono::milliseconds>

a double option with milli-second precision.

input is seconds as double. output is a std::chrono::millisecond

◆ MPMCQueue

template<typename T >
using mysql_harness::MPMCQueue = typedef MPMCQueueMS2Lock<T>

◆ MPSCQueue

template<typename T >
using mysql_harness::MPSCQueue = typedef MPSCQueueDV<T>

◆ my_start_routine

typedef void *(* mysql_harness::my_start_routine) (void *)

◆ mysql_router_thread_attr_t

◆ mysql_router_thread_t

◆ perm_mode

using mysql_harness::perm_mode = typedef mode_t

◆ security_descriptor_type

◆ socket_t

◆ Ssl

using mysql_harness::Ssl = typedef std::unique_ptr<SSL, mysql_harness::impl::Deleter_SSL>

◆ WaitingMPMCQueue

template<typename T >
using mysql_harness::WaitingMPMCQueue = typedef WaitingQueueAdaptor<MPMCQueue<T> >

◆ WaitingMPSCQueue

template<typename T >
using mysql_harness::WaitingMPSCQueue = typedef WaitingQueueAdaptor<MPSCQueue<T> >

Enumeration Type Documentation

◆ DynamicLoaderErrc

error-codes of the DynamicLoader and DynamicLibrary.

when set, the error-msg needs be retrieved from DynamicLoader().error_msg() or DynamicLibrary().error_msg()

Enumerator
kDlError 

Function Documentation

◆ access_rights_get()

stdx::expected< security_descriptor_type, std::error_code > mysql_harness::access_rights_get ( const std::string &  file_name)
noexcept

get a access rights of file.

Parameters
file_nameof a file.

◆ access_rights_set()

stdx::expected< void, std::error_code > mysql_harness::access_rights_set ( const std::string &  file_name,
const security_descriptor_type sec_desc 
)

set access rights of a file.

◆ access_rights_verify()

template<class Func >
stdx::expected< void, std::error_code > mysql_harness::access_rights_verify ( const security_descriptor_type rights,
Func &&  func 
)

check if a security descriptor satisfies a verifier.

◆ call_plugin_function()

static void mysql_harness::call_plugin_function ( PluginFuncEnv env,
std::exception_ptr &  eptr,
void(*)(PluginFuncEnv *)  fptr,
const char *  fnc_name,
const char *  plugin_name,
const char *  plugin_key = nullptr 
)
staticnoexcept

◆ check_file_access_rights()

void mysql_harness::check_file_access_rights ( const std::string &  file_name)

Verifies access permissions of a file.

On Unix systems it throws if file's permissions differ from 600. On Windows it throws if file can be accessed by Everyone group.

Parameters
[in]file_nameFile to be verified.
Exceptions
std::exceptionFile access rights are too permissive or an error occurred.
std::system_errorOS and/or filesystem doesn't support file permissions.

◆ check_option()

static void mysql_harness::check_option ( std::string_view  str)
static

◆ clear_running()

void mysql_harness::clear_running ( PluginFuncEnv env)
noexcept

◆ connect_to_notify_socket()

static stdx::expected< local::datagram_protocol::socket, std::error_code > mysql_harness::connect_to_notify_socket ( net::io_context io_ctx,
const std::string &  socket_name 
)
static

◆ create_initial_keyring_pair()

static std::pair< std::string, std::string > mysql_harness::create_initial_keyring_pair ( MasterKeyFile mkf,
const std::string &  keyring_file_path,
std::string  master_scramble 
)
static

◆ dynamic_loader_category()

const std::error_category & mysql_harness::dynamic_loader_category ( )
noexcept

◆ endpoint_to_name()

static stdx::expected< std::string, std::error_code > mysql_harness::endpoint_to_name ( const net::ip::tcp::endpoint ep)
static

◆ file_type_name()

static const char * mysql_harness::file_type_name ( Path::FileType  type)
static

◆ flush_keyring()

void mysql_harness::flush_keyring ( )

Saves the keyring contents to disk.

◆ get_app_info()

const AppInfo * mysql_harness::get_app_info ( const PluginFuncEnv env)
noexcept

◆ get_config_section()

const ConfigSection * mysql_harness::get_config_section ( const PluginFuncEnv env)
noexcept

◆ get_env_vars()

static auto mysql_harness::get_env_vars ( const std::vector< std::string > &  env_vars)
static

◆ get_env_vars_vector()

static auto mysql_harness::get_env_vars_vector ( const std::vector< std::pair< std::string, std::string > > &  env_vars)
static

◆ get_from_map()

template<class Key , class Value >
Value mysql_harness::get_from_map ( const std::map< Key, Value > &  map,
const Key &  key,
const Value &  default_value 
)

Gets a Value from std::map for given Key.

Returns provided default if the Key is not in the map.

◆ get_keyring()

Keyring * mysql_harness::get_keyring ( )
noexcept

Gets a previously initialized singleton instance of the keyring.

◆ get_master_key()

static std::pair< std::string, std::string > mysql_harness::get_master_key ( MasterKeyFile mkf,
const std::string &  keyring_file_path,
bool  create_if_needed 
)
static

Gets the master_key for the specified keyring_file from the master key store.

If the master key store file does not exist, it will be created along with a new master_key, which will be stored and also returned. If the master key store already exists, but does not have an entry for the master key, it will be generated and then stored.

Returns the master_key and the scramble for the master_key

◆ get_notify_socket_name()

static std::string mysql_harness::get_notify_socket_name ( )
static

◆ get_params()

static std::vector< const char * > mysql_harness::get_params ( const std::string &  command,
const std::vector< std::string > &  params_vec 
)
static

◆ get_plugin_dir()

std::string mysql_harness::get_plugin_dir ( const std::string &  runtime_dir)

◆ get_tests_data_dir()

std::string mysql_harness::get_tests_data_dir ( const std::string &  runtime_dir)

◆ hexify()

template<class T >
std::string mysql_harness::hexify ( const T &  buf)
inline

hexdump into a string.

converts the contents of continous container (has .data() and .size()) as hex values in rows of 16 bytes.

Parameters
bufa container
Returns
string containing the hexdump

◆ init_keyring()

bool mysql_harness::init_keyring ( const std::string &  keyring_file_path,
const std::string &  master_key_path,
bool  create_if_needed 
)

Initialize an instance of a keyring to be used in the application from the contents of a file, using the given master key file.

Parameters
keyring_file_pathpath to the file where keyring is stored
master_key_pathpath to the file keyring master keys are stored
create_if_neededcreates the keyring if it doesn't exist yet
Returns
false if the keyring had to be created

◆ init_keyring_with_key()

bool mysql_harness::init_keyring_with_key ( const std::string &  keyring_file_path,
const std::string &  master_key,
bool  create_if_needed 
)

Initialize an instance of a keyring to be used in the application from the contents of a file, using the given master key.

Parameters
keyring_file_pathpath to the file where keyring is stored
master_keymaster key for the keyring
create_if_neededcreates the keyring if it doesn't exist yet
Returns
false if the keyring had to be created

◆ inplace_lower()

static void mysql_harness::inplace_lower ( std::string *  str)
static

◆ is_running()

bool mysql_harness::is_running ( const PluginFuncEnv env)
noexcept

◆ is_valid_conf_ident_char()

bool mysql_harness::is_valid_conf_ident_char ( const char  ch)

Returns true if a character given as a parameter is valid for config identifier (section, section key or option name)

◆ is_valid_domainname()

bool mysql_harness::is_valid_domainname ( const std::string &  address)

check if address is a domainname.

domainnames according to RFC 2181:

  • max size 255 chars
  • labels are separated by dots
  • each label is min 1, max 63 chars.

That means

  • IPv4 addresses
  • IPv6 addresses
  • hostnames

are domainnames.

Parameters
addressaddress to check
Return values
trueaddress is a domainname
falseaddress is not a domainname

◆ is_valid_hostname()

bool mysql_harness::is_valid_hostname ( const std::string &  address)

check if address is a hostname.

hostname is verified according to RFC 1123.

  • fully qualified domain names like "mysql.com." are not valid hostnames (trailing dot)
  • service names like "_mysql.example.com" are not valid hostnames (leading underscore)
Parameters
addressname of a host
Return values
falsehostname is invalid
truehostname is valid

◆ is_valid_ip_address()

bool mysql_harness::is_valid_ip_address ( const std::string &  address)

◆ join()

template<class Container >
std::string mysql_harness::join ( Container  cont,
const std::string &  delim 
)

join elements of an container into a string separated by a delimiter.

Container MUST:

  • have .begin() and end()
  • iterator must be ForwardIterator + InputIterator
  • value_type must be appendable to std::string

should work with:

  • std::vector<const char *|stdstring>
  • std::array<const char *|stdstring, N>
  • std::list<const char *|stdstring>
Parameters
conta container
delimdelimiter
Returns
string of elements of container separated by delim

◆ last_error_code()

static std::error_code mysql_harness::last_error_code ( )
staticnoexcept

◆ left_trim()

void mysql_harness::left_trim ( std::string &  str)

Removes leading whitespaces from the string.

Parameters
strthe string to be trimmed

◆ limit_lines()

std::string mysql_harness::limit_lines ( const std::string &  str,
const size_t  limit,
const std::string &  replace_with = "" 
)

Returns the input string with number of lines reduced to selected value.

Parameters
strinput string
limitmaximum number of lines of the returned string
replace_withstring that should be used in place of the removed lines
Returns
If the input string contains more than 'limit' number of lines, it removes the lines from the middle leaving only 'limit' number of lines (limit/2 of the first lines and limit/2 of the last lines). Otherwise it returns the whole input string.

◆ lower()

static std::string mysql_harness::lower ( std::string_view  str)
static

◆ make_error_code()

std::error_code mysql_harness::make_error_code ( DynamicLoaderErrc  ec)

make error_code from a DynamicLoaderErrc.

std::error_code make_error_code(DynamicLoaderErrc ec)
make error_code from a DynamicLoaderErrc.
Definition: dynamic_loader.cc:79

◆ make_file_private()

void mysql_harness::make_file_private ( const std::string &  file_name,
const bool  read_only_for_local_service = true 
)

Changes file access permissions to be accessible only by a limited set of users.

On Unix, the function sets file permission mask to 600. On Windows, all permissions to this file are removed for Everyone group, LocalService account gets read (and optionally write) access.

Parameters
[in]file_nameFile name.
[in]read_only_for_local_serviceWeather the LocalService user on Windows should get only the read access (if false will grant write access too). Not used on non-Windows.
Exceptions
std::exceptionFailed to change file permissions.

◆ make_file_private_win32()

static stdx::expected< void, std::error_code > mysql_harness::make_file_private_win32 ( const std::string &  filename,
const bool  read_only_for_local_service 
)
static

Makes a file fully accessible by the current process user and (read only or read/write depending on the second argument) for LocalService account (which is the account under which the MySQL router runs as service).

And not accessible for everyone else.

◆ make_file_public()

void mysql_harness::make_file_public ( const std::string &  file_name)

Changes file access permissions to be fully accessible by all users.

On Unix, the function sets file permission mask to 777. On Windows, Everyone group is granted full access to the file.

Parameters
[in]file_nameFile name.
Exceptions
std::exceptionFailed to change file permissions.

◆ make_file_readable_for_everyone()

void mysql_harness::make_file_readable_for_everyone ( const std::string &  file_name)

◆ make_file_readonly()

void mysql_harness::make_file_readonly ( const std::string &  file_name)

Changes file access permissions to be read only.

On Unix, the function sets file permission mask to 555. On Windows, all permissions to this file are read access only for Everyone group, LocalService account gets read access.

Parameters
[in]file_nameFile name.
Exceptions
std::exceptionFailed to change file permissions.

◆ make_local_hostname_resolution_error()

static SocketOperationsBase::LocalHostnameResolutionError mysql_harness::make_local_hostname_resolution_error ( const std::error_code &  ec)
static

◆ make_tcp_address()

stdx::expected< TCPAddress, std::error_code > mysql_harness::make_tcp_address ( const std::string &  endpoint)

create TCPAddress from endpoint string.

  • [::1]:1234
  • ::1
  • 10.0.1.1
  • 10.0.1.1:1234
  • example.org:1234

◆ make_tcp_address_ipv6()

static stdx::expected< TCPAddress, std::error_code > mysql_harness::make_tcp_address_ipv6 ( const std::string &  endpoint)
static

◆ mkdir()

int mysql_harness::mkdir ( const std::string &  dir,
perm_mode  mode,
bool  recursive = false 
)

Creates a directory *.

Parameters
dirname (or path) of the directory to create
modepermission mode for the created directory
recursiveif true then imitate unix mkdir -p recursively creating parent directories if needed
Return values
0operation succeeded
-1operation failed because of wrong parameters
>0 errno for failure to mkdir() system call

◆ mkdir_recursive()

int mysql_harness::mkdir_recursive ( const Path path,
perm_mode  mode 
)

◆ mkdir_wrapper()

int mysql_harness::mkdir_wrapper ( const std::string &  dir,
perm_mode  mode 
)

◆ mysql_router_thread_attr_init()

static int mysql_harness::mysql_router_thread_attr_init ( mysql_router_thread_attr_t attr)
inlinestatic

◆ mysql_router_thread_attr_setdetachstate()

static int mysql_harness::mysql_router_thread_attr_setdetachstate ( mysql_router_thread_attr_t attr,
int  detachstate 
)
inlinestatic

◆ mysql_router_thread_attr_setstacksize()

static int mysql_harness::mysql_router_thread_attr_setstacksize ( mysql_router_thread_attr_t attr,
size_t  stacksize 
)
inlinestatic

◆ mysql_router_thread_create()

int mysql_harness::mysql_router_thread_create ( mysql_router_thread_handle thread,
const mysql_router_thread_attr_t attr,
my_start_routine  func,
void *  arg 
)

◆ mysql_router_thread_join()

int mysql_harness::mysql_router_thread_join ( mysql_router_thread_handle thread,
void **  value_ptr 
)

◆ mysql_router_thread_joinable()

static bool mysql_harness::mysql_router_thread_joinable ( const mysql_router_thread_attr_t attr)
inlinestatic

checks if thread pointed by attr is joinable

Exceptions
std::runtime_errorif cannot check if thread is joinable

◆ mysql_router_thread_started()

static bool mysql_harness::mysql_router_thread_started ( const mysql_router_thread_handle thread)
inlinestatic

checks if thread pointed by thread was started

◆ notify() [1/2]

static bool mysql_harness::notify ( const std::string &  msg)
static

◆ notify() [2/2]

static stdx::expected< void, std::error_code > mysql_harness::notify ( const std::string &  msg,
const std::string &  socket_name 
)
static

◆ notify_ready()

bool mysql_harness::notify_ready ( )

◆ notify_status()

bool mysql_harness::notify_status ( const std::string &  msg)

◆ notify_stopping()

bool mysql_harness::notify_stopping ( )

◆ on_service_ready() [1/2]

void mysql_harness::on_service_ready ( const std::string &  name)

◆ on_service_ready() [2/2]

void mysql_harness::on_service_ready ( PluginFuncEnv plugin_env)

◆ operator<<()

std::ostream & mysql_harness::operator<< ( std::ostream &  out,
Path::FileType  type 
)

◆ option_as_double()

double mysql_harness::option_as_double ( const std::string &  value,
const std::string &  option_desc,
double  min_value = 0,
double  max_value = std::numeric_limits<double>::max() 
)

◆ option_as_int()

template<typename T >
T mysql_harness::option_as_int ( const std::string_view &  value,
const std::string &  option_desc,
min_value = std::numeric_limits<T>::min(),
max_value = std::numeric_limits<T>::max() 
)

Gets an integer using the given option value.

Gets an integer using the given option value. The type can be any integer type such as uint16_t, int8_t and bool.

The min_value argument can be used to set a minimum value for the option. For example, when 0 (zero) is not allowed, min_value can be set to 1. The maximum value is whatever the maximum of the use type is.

Throws std::invalid_argument on errors.

Parameters
valueOption value
option_descOption name
min_valueMinimum value
max_valueMaximum value
Returns
value read from the configuration

◆ option_as_uint()

template<typename T >
T mysql_harness::option_as_uint ( const std::string_view &  value,
const std::string &  option_desc,
min_value = std::numeric_limits<T>::min(),
max_value = std::numeric_limits<T>::max() 
)

Get a unsigned integer.

use option_as_int<T> instead.

◆ option_description()

static std::string mysql_harness::option_description ( std::string_view  section_name,
std::string_view  option 
)
static

◆ report_unsupported_option()

static void mysql_harness::report_unsupported_option ( const std::string &  section,
const std::string &  option,
const bool  error_out 
)
static

◆ reset_keyring()

void mysql_harness::reset_keyring ( )
noexcept

Clears the keyring singleton.

◆ right_trim()

void mysql_harness::right_trim ( std::string &  str)

Removes trailing whitespaces from the string.

Parameters
strthe string to be trimmed

◆ section_to_string()

static std::string mysql_harness::section_to_string ( const ConfigSection section)
static

◆ serial_comma() [1/2]

template<class InputIt >
std::string mysql_harness::serial_comma ( InputIt  start,
InputIt  finish,
const std::string &  delim = "and" 
)

Returns string containing list of the elements using the serial comma.

This function can be used to output a range of elements using a serial comma (also known as the Oxford comma). To return a list of the first five prime numbers as "The first five prime numbers are 2, 3, 5, 7, and 11":

std::vector<int> primes{2, 3, 5, 7, 11};
std::cout << "The first five prime numbers are "
<< serial_comma(primes.begin(), primes.end()) << std::endl;
void serial_comma(std::ostream &out, InputIt start, InputIt finish, const std::string &delim="and")
Emit a range of elements using the serial comma.
Definition: common.h:75
Parameters
startInput iterator to start of range.
finishInput iterator to one-after-end of range.
delimDelimiter to use. Defaults to "and".
Returns
string containing list of the elements

◆ serial_comma() [2/2]

template<class InputIt >
void mysql_harness::serial_comma ( std::ostream &  out,
InputIt  start,
InputIt  finish,
const std::string &  delim = "and" 
)

Emit a range of elements using the serial comma.

This function can be used to output a range of elements using a serial comma (also known as the Oxford comma). To emit a list of the first five prime numbers as "The first five prime numbers are 2, 3, 5, 7, and 11":

std::vector<int> primes{2, 3, 5, 7, 11};
std::cout << "The first five prime numbers are ";
serial_comma(std::cout, primes.begin(), primes.end());
std::cout << std::endl;
Parameters
outOutput stream
startInput iterator to start of range.
finishInput iterator to one-after-end of range.
delimDelimiter to use. Defaults to "and".

◆ set_error()

void mysql_harness::set_error ( PluginFuncEnv env,
ErrorType  error_type,
const char *  fmt,
  ... 
)
noexcept

◆ set_everyone_group_access_rights()

static stdx::expected< void, std::error_code > mysql_harness::set_everyone_group_access_rights ( const std::string &  file_name,
DWORD  mask 
)
static

Sets file permissions for Everyone group.

Parameters
[in]file_nameFile name.
[in]maskAccess rights mask for Everyone group.
Exceptions
std::exceptionFailed to change file permissions.

◆ shrink()

static void mysql_harness::shrink ( std::string &  s)
static

◆ split_string()

std::vector< std::string > mysql_harness::split_string ( const std::string_view &  data,
const char  delimiter,
bool  allow_empty = true 
)

Splits a string using a delimiter.

Splits a string using the given delimiter. When allow_empty is true (default), tokens can be empty, and will be included as empty in the result.

Parameters
dataa string to split
delimitera char used as delimiter
allow_emptywhether to allow empty tokens or not (default true)
Returns
std::vector<string> containing tokens

◆ str_in_collection()

template<class T >
constexpr bool mysql_harness::str_in_collection ( const T &  t,
const std::string_view &  k 
)
constexpr

◆ to_string()

std::string mysql_harness::to_string ( const ShutdownPending::Reason reason)

◆ trim()

void mysql_harness::trim ( std::string &  str)

Removes both leading and trailing whitespaces from the string.

Parameters
strthe string to be trimmed

◆ truncate_string()

std::string mysql_harness::truncate_string ( const std::string &  str,
size_t  max_len = 80 
)

Return a truncated version of input string.

Parameters
strinput text
max_lenmaximum length after truncation
Returns
truncated string

◆ value_or()

template<class T >
T mysql_harness::value_or ( a,
b 
)

If a isn't set, return b.

like ?:, but ensures that b is always evaluated first.

◆ verify_file_permissions()

static void mysql_harness::verify_file_permissions ( const std::string &  file_name)
static

◆ wait_for_stop()

bool mysql_harness::wait_for_stop ( const PluginFuncEnv env,
uint32_t  milliseconds 
)
noexcept

Variable Documentation

◆ g_keyring

std::unique_ptr<KeyringFile> mysql_harness::g_keyring
static

◆ g_keyring_file_path

std::string mysql_harness::g_keyring_file_path
static

◆ g_keyring_key

std::string mysql_harness::g_keyring_key
static

◆ kAesIv

constexpr unsigned char mysql_harness::kAesIv[]
staticconstexpr
Initial value:
= {0x39, 0x62, 0x9f, 0x52, 0x7f, 0x76,
0x9a, 0xae, 0xcd, 0xca, 0xf7, 0x04,
0x65, 0x8e, 0x5d, 0x88}

◆ kDefaultStackSizeInKiloBytes

const size_t mysql_harness::kDefaultStackSizeInKiloBytes = 1024
static

◆ kInvalidSocket

constexpr socket_t mysql_harness::kInvalidSocket = net::impl::socket::kInvalidSocket
constexpr

◆ kKeyLength

const unsigned mysql_harness::kKeyLength = 32
static

◆ kMasterKeyFileSignature

const std::array<char, 5> mysql_harness::kMasterKeyFileSignature
static
Initial value:
= {'M', 'R', 'K', 'F',
'\0'}

◆ kMaxKeyringKeyLength

const int mysql_harness::kMaxKeyringKeyLength = 255
static

◆ kStrictDirectoryPerm

const perm_mode mysql_harness::kStrictDirectoryPerm = S_IRWXU

◆ kTerminateWaitInterval

constexpr auto mysql_harness::kTerminateWaitInterval = std::chrono::seconds(10)
constexpr

◆ kWaitPidCheckInterval

constexpr auto mysql_harness::kWaitPidCheckInterval = std::chrono::milliseconds(10)
constexpr

maximum number of parameters that can be passed to the launched process

◆ loader_supported_options

constexpr std::array mysql_harness::loader_supported_options
staticconstexpr
Initial value:
{
}
constexpr std::string_view kConfigFolder
Definition: supported_config_options.h:41
constexpr std::string_view kProgram
Definition: supported_config_options.h:36
constexpr std::string_view kUnknownConfigOption
Definition: supported_config_options.h:42
constexpr std::string_view kRuntimeFolder
Definition: supported_config_options.h:38
constexpr std::string_view kPluginFolder
Definition: supported_config_options.h:40
constexpr std::string_view kOrigin
Definition: supported_config_options.h:35
constexpr std::string_view kDataFolder
Definition: supported_config_options.h:39
constexpr std::string_view kLoggingFolder
Definition: supported_config_options.h:37

◆ null_thread_initializer

constexpr mysql_router_thread_t mysql_harness::null_thread_initializer
staticconstexpr
Initial value:
=
pthread_t mysql_router_thread_t
Definition: mysql_router_thread.h:53