MySQL  8.0.20
Source Code Documentation
mysqlrouter Namespace Reference

Classes

class  BasePluginConfig
 Retrieve and manage plugin configuration. More...
 
struct  ClusterInfo
 
class  ClusterMetadata
 
class  ClusterMetadataAR
 
class  ClusterMetadataGR
 
class  ClusterMetadataGRV1
 
class  ClusterMetadataGRV2
 
class  ConfigGenerator
 
class  LogFilter
 
struct  MetadataSchemaVersion
 
class  MetadataUpgradeInProgressException
 
class  MockOfstream
 mock implementation of std::ofstream More...
 
class  MySQLClientThreadToken
 Thread Token for libmysqlclient API users. More...
 
class  MySQLSession
 
class  Ofstream
 interface to std::ofstream and alternative (mock) implementations More...
 
class  option_empty
 Exception that gets thrown when the configuarion option is present but it is empty value. More...
 
class  option_not_present
 Exception that gets thrown when the configuarion option is missing. More...
 
class  RealOfstream
 simple std::ofstream adapter, needed for DI purposes More...
 
class  SQLLogFilter
 A SQLLogFilter allows to replace substrings defined by a set of hardcoded regular expressions with '***'. More...
 
class  sqlstring
 
struct  SSLOptions
 SSL connection related options. More...
 
class  SysUserOperations
 This class provides implementations of SysUserOperationsBase methods. More...
 
class  SysUserOperationsBase
 Base class to allow multiple SysUserOperations implementations. More...
 
class  URI
 Parse and create URIs according to RFC3986. More...
 
class  URIError
 Exception when URI was not valid. More...
 
class  URIParser
 
struct  UserCredentials
 

Typedefs

using URIAuthority = std::tuple< std::string, uint16_t, std::string, std::string >
 
using URIPath = std::vector< std::string >
 
using URIQuery = std::map< std::string, std::string >
 
using perm_mode = mode_t
 

Enumerations

enum  ClusterType { ClusterType::GR_V1, ClusterType::GR_V2, ClusterType::RS_V2 }
 
enum  SqlStringFlags { QuoteOnlyIfNeeded = 1 << 0, UseAnsiQuotes = 1 << 1, EndOfInput = 1 << 7 }
 

Functions

std::string to_string (const MetadataSchemaVersion &version)
 
MetadataSchemaVersion get_metadata_schema_version (MySQLSession *mysql)
 
bool metadata_schema_version_is_compatible (const mysqlrouter::MetadataSchemaVersion &required, const mysqlrouter::MetadataSchemaVersion &available)
 
template<size_t N>
bool metadata_schema_version_is_compatible (const mysqlrouter::MetadataSchemaVersion(&required)[N], const mysqlrouter::MetadataSchemaVersion &available)
 
template<size_t N>
std::string to_string (const mysqlrouter::MetadataSchemaVersion(&version)[N])
 
ClusterType get_cluster_type (const MetadataSchemaVersion &schema_version, MySQLSession *mysql)
 
std::string to_string (const ClusterType cluster_type)
 
void setup_metadata_session (MySQLSession &session)
 
std::ostream & operator<< (std::ostream &strm, const URI &uri)
 
template<typename T >
std::string to_string (const T &data)
 
std::string ms_to_seconds_string (const std::chrono::milliseconds &msec)
 
std::string string_format (const char *format,...)
 Returns string formatted using given data. More...
 
std::pair< std::string, uint16_t > split_addr_port (const std::string data)
 Split host and port. More...
 
uint16_t get_tcp_port (const std::string &data)
 Validates a string containing a TCP port. More...
 
std::string hexdump (const unsigned char *buffer, size_t count, long start=0, bool literals=false)
 Dumps buffer as hex values. More...
 
std::string get_last_error (int myerrnum=0)
 Returns the platform specific error code of last operation Using errno in UNIX & Linux systems and GetLastError in Windows systems. More...
 
int get_socket_errno () noexcept
 Returns error number of the last failed socket operation. More...
 
std::string prompt_password (const std::string &prompt)
 Prompts for a password from the console. More...
 
void set_prompt_password (const std::function< std::string(const std::string &)> &f)
 Override default prompt password function. More...
 
bool substitute_envvar (std::string &line) noexcept
 Substitutes placeholders of environment variables in a string. More...
 
std::string substitute_variable (const std::string &s, const std::string &name, const std::string &value)
 
bool my_check_access (const std::string &path)
 
void copy_file (const std::string &from, const std::string &to)
 Copy contents of one file to another. More...
 
int rename_file (const std::string &from, const std::string &to)
 renames file, returns 0 if succeed, or positive error code if fails. More...
 
bool is_valid_socket_name (const std::string &socket, std::string &err_msg)
 Returns whether the socket name passed as parameter is valid. More...
 
int strtoi_checked (const char *value, signed int default_result=0) noexcept
 Converts char array to signed integer, intuitively. More...
 
unsigned strtoui_checked (const char *value, unsigned int default_result=0) noexcept
 Converts char array to unsigned integer, intuitively. More...
 
void set_owner_if_file_exists (const std::string &filepath, const std::string &username, struct passwd *user_info_arg, mysqlrouter::SysUserOperationsBase *sys_user_operations)
 Sets the owner of selected file/directory if it exists. More...
 
void set_user (const std::string &username, bool permanently=false, mysqlrouter::SysUserOperationsBase *sys_user_operations=SysUserOperations::instance())
 Sets effective user of the calling process. More...
 
struct passwd * check_user (const std::string &username, bool must_be_root, mysqlrouter::SysUserOperationsBase *sys_user_operations)
 Checks if the given user can be switched to or made an owner of a selected file. More...
 
std::string escape_sql_string (const std::string &s, bool wildcards)
 Escape a string to be used in a SQL query Same code as used by mysql. More...
 
std::string escape_backticks (const std::string &string)
 
std::string quote_identifier (const std::string &identifier, const char quote_char)
 
std::string quote_identifier_if_needed (const std::string &ident, const char quote_char)
 Quotes the given identifier, but only if it needs to be quoted. More...
 
static std::string get_string (const char *input_str)
 Return a string representation of the input character string. More...
 
static void verify_router_id_is_ours_v1 (const uint32_t router_id, const std::string &hostname_override, MySQLSession *mysql, mysql_harness::SocketOperationsBase *socket_operations)
 
static void verify_router_id_is_ours_v2 (const uint32_t router_id, const std::string &hostname_override, MySQLSession *mysql, mysql_harness::SocketOperationsBase *socket_operations)
 
static void update_router_info_v1 (const uint32_t router_id, const std::string &rw_endpoint, const std::string &ro_endpoint, const std::string &rw_x_endpoint, const std::string &ro_x_endpoint, const std::string &username, MySQLSession *mysql)
 
static void update_router_info_v2 (const uint32_t router_id, const std::string &cluster_id, const std::string &rw_endpoint, const std::string &ro_endpoint, const std::string &rw_x_endpoint, const std::string &ro_x_endpoint, const std::string &username, MySQLSession *mysql)
 
static uint32_t register_router_v1 (const std::string &router_name, const bool overwrite, const std::string &hostname_override, MySQLSession *mysql, mysql_harness::SocketOperationsBase *socket_operations)
 
static uint32_t register_router_v2 (const std::string &router_name, const bool overwrite, const std::string &hostname_override, MySQLSession *mysql, mysql_harness::SocketOperationsBase *socket_operations)
 
static bool check_group_replication_online (MySQLSession *mysql)
 
static bool check_group_has_quorum (MySQLSession *mysql)
 
static uint64_t query_gr_cluster_count (MySQLSession *mysql, const bool metadata_v2)
 
static ClusterInfo query_metadata_servers (MySQLSession *mysql, const bool metadata_v2)
 
static std::vector< std::string > do_get_routing_mode_queries (MySQLSession *mysql, const bool metadata_v2, const std::string &cluster_name)
 
static ClusterType get_cluster_type (MySQLSession *mysql)
 
std::unique_ptr< ClusterMetadatacreate_metadata (const MetadataSchemaVersion &schema_version, MySQLSession *mysql, mysql_harness::SocketOperationsBase *sockops)
 
static std::vector< std::string > get_grant_statements_v1 (const std::string &new_accounts)
 
static std::vector< std::string > get_grant_statements_v2 (const std::string &new_accounts)
 
bool is_reserved_word (const std::string &word)
 
static size_t match_zero_or_more (const string &s, const string &pat, size_t pos_start=0)
 
static size_t skip (size_t pos_start, size_t match_len)
 
static string capture (const string &s, size_t pos_start, size_t match_len, size_t &pos_end)
 
static bool is_eol (const string &s, size_t pos_start)
 
static bool match_pct_encoded (const string &s, size_t pos_start, size_t &pos_end, string &pct_enc)
 
static bool match_path_chars (const string &s, size_t pos_start, size_t &pos_end, string &path_chars)
 
static bool match_scheme (const string &s, size_t pos_start, size_t &pos_end, string &scheme)
 
static bool match_colon (const string &s, size_t pos_start, size_t &pos_end)
 
static bool match_double_colon (const string &s, size_t pos_start, size_t &pos_end)
 
static bool match_userinfo (const string &s, size_t pos_start, size_t &pos_end, string &user_info)
 
static void split_userinfo (const string &user_info, string &username, string &password)
 
static bool match_port (const string &s, size_t pos_start, size_t &pos_end, string &port)
 
static bool match_reg_name (const string &s, size_t pos_start, size_t &pos_end, string &reg_name, bool with_pct_encoded)
 
static bool match_dec_octet (const string &s, size_t pos_start, size_t &pos_end, string &dec_octet)
 
static bool match_ipv4 (const string &s, size_t pos_start, size_t &pos_end, string &ipv4_addr)
 
static bool match_ipv6_h16 (const string &s, size_t pos_start, size_t &pos_end, string &h16)
 
static bool match_ipv6_ls32 (const string &s, size_t pos_start, size_t &pos_end, string &ls32)
 
static bool match_ipv6_h16_colon (const string &s, size_t pos_start, size_t &pos_end, string &h16_colon)
 
static bool match_ipv6_1 (const string &s, size_t pos_start, size_t &pos_end, string &ipv6_addr)
 
static bool match_ipv6_2 (const string &s, size_t pos_start, size_t &pos_end, string &ipv6_addr)
 
static bool match_ipv6_h16_colon_prefix (const string &s, size_t pos_start, size_t max_pre_double_colon, size_t &pos_end, string &ipv6_addr)
 
static bool match_ipv6_3 (const string &s, size_t pos_start, size_t max_pre_double_colon, size_t &pos_end, string &ipv6_addr)
 
static bool match_ipv6_8 (const string &s, size_t pos_start, size_t max_pre_double_colon, size_t &pos_end, string &ipv6_addr)
 
static bool match_ipv6_zoneid (const string &s, size_t pos_start, size_t &pos_end, string &zoneid, bool with_pct_encoded)
 
static bool match_ipv6 (const string &s, size_t pos_start, size_t &pos_end, string &ipv6_addr)
 
static bool match_ip_literal (const string &s, size_t pos_start, size_t &pos_end, string &ip_literal, bool with_pct_encoded)
 
static bool match_host (const string &s, size_t pos_start, size_t &pos_end, string &host, bool with_pct_encoded)
 
static bool match_authority (const string &s, size_t pos_start, size_t &pos_end, string &tmp_host, string &tmp_port, string &tmp_username, string &tmp_password)
 
static bool match_path_segment (const string &s, size_t pos_start, size_t &pos_end, string &segment)
 
static bool match_path_empty (const string &s, size_t pos_start, size_t &pos_end, string &path)
 
static bool match_path_absolute (const string &s, size_t pos_start, size_t &pos_end, string &path)
 
static bool match_path_absolute_or_empty (const string &s, size_t pos_start, size_t &pos_end, string &path)
 
static bool match_path_rootless (const string &s, size_t pos_start, size_t &pos_end, string &path)
 
static bool match_fragment_query_chars (const string &s, size_t pos_start, size_t &pos_end, string &chars)
 
static bool match_fragment (const string &s, size_t pos_start, size_t &pos_end, string &fragment)
 
static bool match_query (const string &s, size_t pos_start, size_t &pos_end, string &query)
 
static string pct_decode (const string &s)
 
static URIQuery split_query (const string &s)
 
static bool is_ipv6 (const string &s)
 
static string pct_encode (const string &s, const string &allowed_chars)
 
std::pair< string, uint16_t > split_addr_port (string data)
 
uint16_t get_tcp_port (const string &data)
 
static string default_prompt_password (const string &prompt)
 
template<typename RET >
static RET strtoX_checked_common (const char *value, RET default_value) noexcept
 
static bool check_if_root (const std::string &username, SysUserOperationsBase *sys_user_operations)
 
static passwd * get_user_info (const std::string &username, SysUserOperationsBase *sys_user_operations)
 
static void set_user_priv (const std::string &username, struct passwd *user_info_arg, bool permanently, SysUserOperationsBase *sys_user_operations)
 

Variables

constexpr MetadataSchemaVersion kRequiredBootstrapSchemaVersion []
 
constexpr MetadataSchemaVersion kRequiredRoutingMetadataSchemaVersion []
 
constexpr MetadataSchemaVersion kNewMetadataVersion {2, 0, 0}
 
constexpr MetadataSchemaVersion kUpgradeInProgressMetadataVersion {0, 0, 0}
 
const perm_mode kStrictDirectoryPerm = S_IRWXU
 Constant for directory accessible only for the owner. More...
 
constexpr const char * kDefaultSqlMode
 
static std::function< string(const string &)> g_prompt_password
 

Typedef Documentation

◆ perm_mode

using mysqlrouter::perm_mode = typedef mode_t

◆ URIAuthority

using mysqlrouter::URIAuthority = typedef std::tuple<std::string, uint16_t, std::string, std::string>

◆ URIPath

using mysqlrouter::URIPath = typedef std::vector<std::string>

◆ URIQuery

using mysqlrouter::URIQuery = typedef std::map<std::string, std::string>

Enumeration Type Documentation

◆ ClusterType

Enumerator
GR_V1 
GR_V2 
RS_V2 

◆ SqlStringFlags

Enumerator
QuoteOnlyIfNeeded 
UseAnsiQuotes 
EndOfInput 

Function Documentation

◆ capture()

static string mysqlrouter::capture ( const string &  s,
size_t  pos_start,
size_t  match_len,
size_t &  pos_end 
)
static

◆ check_group_has_quorum()

static bool mysqlrouter::check_group_has_quorum ( MySQLSession mysql)
static

◆ check_group_replication_online()

static bool mysqlrouter::check_group_replication_online ( MySQLSession mysql)
static

◆ check_if_root()

static bool mysqlrouter::check_if_root ( const std::string &  username,
SysUserOperationsBase sys_user_operations 
)
static

◆ check_user()

struct passwd * mysqlrouter::check_user ( const std::string &  username,
bool  must_be_root,
mysqlrouter::SysUserOperationsBase sys_user_operations 
)

Checks if the given user can be switched to or made an owner of a selected file.

Exceptions
std::runtime_errorin case of an error
Parameters
usernamename of the system user to check
must_be_rootmake sure that the current user is root
sys_user_operationsobject for the system specific operation that should be used by the function
Returns
pointer to the user's passwd structure if the user can be switched to or nullptr otherwise

◆ copy_file()

void mysqlrouter::copy_file ( const std::string &  from,
const std::string &  to 
)

Copy contents of one file to another.

Exception thrown if open, create read or write operation fails.

◆ create_metadata()

std::unique_ptr< ClusterMetadata > mysqlrouter::create_metadata ( const MetadataSchemaVersion schema_version,
MySQLSession mysql,
mysql_harness::SocketOperationsBase sockops 
)

◆ default_prompt_password()

static string mysqlrouter::default_prompt_password ( const string &  prompt)
static

◆ do_get_routing_mode_queries()

static std::vector<std::string> mysqlrouter::do_get_routing_mode_queries ( MySQLSession mysql,
const bool  metadata_v2,
const std::string &  cluster_name 
)
static

◆ escape_backticks()

std::string mysqlrouter::escape_backticks ( const std::string &  string)

◆ escape_sql_string()

std::string mysqlrouter::escape_sql_string ( const std::string &  s,
bool  wildcards 
)

Escape a string to be used in a SQL query Same code as used by mysql.

Handles null bytes in the middle of the string. If wildcards is true then _ and % are masked as well.

◆ get_cluster_type() [1/2]

ClusterType mysqlrouter::get_cluster_type ( const MetadataSchemaVersion schema_version,
MySQLSession mysql 
)

◆ get_cluster_type() [2/2]

static ClusterType mysqlrouter::get_cluster_type ( MySQLSession mysql)
static

◆ get_grant_statements_v1()

static std::vector<std::string> mysqlrouter::get_grant_statements_v1 ( const std::string &  new_accounts)
static

◆ get_grant_statements_v2()

static std::vector<std::string> mysqlrouter::get_grant_statements_v2 ( const std::string &  new_accounts)
static

◆ get_last_error()

std::string mysqlrouter::get_last_error ( int  myerrnum = 0)

Returns the platform specific error code of last operation Using errno in UNIX & Linux systems and GetLastError in Windows systems.

If myerrnum arg is not zero will use GetLastError in Windows (if myerrnum is zero in Unix will read the current errno).

Returns
the error code description

◆ get_metadata_schema_version()

MetadataSchemaVersion mysqlrouter::get_metadata_schema_version ( MySQLSession mysql)

◆ get_socket_errno()

int mysqlrouter::get_socket_errno ( )
noexcept

Returns error number of the last failed socket operation.

◆ get_string()

static std::string mysqlrouter::get_string ( const char *  input_str)
static

Return a string representation of the input character string.

Parameters
input_strA character string.
Returns
A string object encapsulation of the input character string. An empty string if input string is nullptr.

◆ get_tcp_port() [1/2]

uint16_t mysqlrouter::get_tcp_port ( const std::string &  data)

Validates a string containing a TCP port.

Validates whether the data can be used as a TCP port. A TCP port is a valid number in the range of 0 and 65535. The returned integer is of type uint16_t.

An empty data string will result in TCP port 0 to be returned.

Throws runtime_error when the given string can not be converted to an integer or when the integer is to big.

Parameters
datastring containing the TCP port number
Returns
uint16_t the TCP port number

◆ get_tcp_port() [2/2]

uint16_t mysqlrouter::get_tcp_port ( const string &  data)

◆ get_user_info()

static passwd* mysqlrouter::get_user_info ( const std::string &  username,
SysUserOperationsBase sys_user_operations 
)
static

◆ hexdump()

string mysqlrouter::hexdump ( const unsigned char *  buffer,
size_t  count,
long  start = 0,
bool  literals = false 
)

Dumps buffer as hex values.

Debugging function which dumps the given buffer as hex values in rows of 16 bytes. When literals is true, characters in a-z or A-Z, are printed as-is.

Parameters
bufferchar array or front of vector<uint8_t>
countnumber of bytes to dump
startfrom where to start dumping
literalswhether to show a-zA-Z as-is
Returns
string containing the dump

◆ is_eol()

static bool mysqlrouter::is_eol ( const string &  s,
size_t  pos_start 
)
static

◆ is_ipv6()

static bool mysqlrouter::is_ipv6 ( const string &  s)
static

◆ is_reserved_word()

bool mysqlrouter::is_reserved_word ( const std::string &  word)

◆ is_valid_socket_name()

bool mysqlrouter::is_valid_socket_name ( const std::string &  socket,
std::string &  err_msg 
)

Returns whether the socket name passed as parameter is valid.

◆ match_authority()

static bool mysqlrouter::match_authority ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  tmp_host,
string &  tmp_port,
string &  tmp_username,
string &  tmp_password 
)
static

◆ match_colon()

static bool mysqlrouter::match_colon ( const string &  s,
size_t  pos_start,
size_t &  pos_end 
)
static

◆ match_dec_octet()

static bool mysqlrouter::match_dec_octet ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  dec_octet 
)
static

◆ match_double_colon()

static bool mysqlrouter::match_double_colon ( const string &  s,
size_t  pos_start,
size_t &  pos_end 
)
static

◆ match_fragment()

static bool mysqlrouter::match_fragment ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  fragment 
)
static

◆ match_fragment_query_chars()

static bool mysqlrouter::match_fragment_query_chars ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  chars 
)
static

◆ match_host()

static bool mysqlrouter::match_host ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  host,
bool  with_pct_encoded 
)
static

◆ match_ip_literal()

static bool mysqlrouter::match_ip_literal ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  ip_literal,
bool  with_pct_encoded 
)
static

◆ match_ipv4()

static bool mysqlrouter::match_ipv4 ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  ipv4_addr 
)
static

◆ match_ipv6()

static bool mysqlrouter::match_ipv6 ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  ipv6_addr 
)
static

◆ match_ipv6_1()

static bool mysqlrouter::match_ipv6_1 ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  ipv6_addr 
)
static

◆ match_ipv6_2()

static bool mysqlrouter::match_ipv6_2 ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  ipv6_addr 
)
static

◆ match_ipv6_3()

static bool mysqlrouter::match_ipv6_3 ( const string &  s,
size_t  pos_start,
size_t  max_pre_double_colon,
size_t &  pos_end,
string &  ipv6_addr 
)
static

◆ match_ipv6_8()

static bool mysqlrouter::match_ipv6_8 ( const string &  s,
size_t  pos_start,
size_t  max_pre_double_colon,
size_t &  pos_end,
string &  ipv6_addr 
)
static

◆ match_ipv6_h16()

static bool mysqlrouter::match_ipv6_h16 ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  h16 
)
static

◆ match_ipv6_h16_colon()

static bool mysqlrouter::match_ipv6_h16_colon ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  h16_colon 
)
static

◆ match_ipv6_h16_colon_prefix()

static bool mysqlrouter::match_ipv6_h16_colon_prefix ( const string &  s,
size_t  pos_start,
size_t  max_pre_double_colon,
size_t &  pos_end,
string &  ipv6_addr 
)
static

◆ match_ipv6_ls32()

static bool mysqlrouter::match_ipv6_ls32 ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  ls32 
)
static

◆ match_ipv6_zoneid()

static bool mysqlrouter::match_ipv6_zoneid ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  zoneid,
bool  with_pct_encoded 
)
static

◆ match_path_absolute()

static bool mysqlrouter::match_path_absolute ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  path 
)
static

◆ match_path_absolute_or_empty()

static bool mysqlrouter::match_path_absolute_or_empty ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  path 
)
static

◆ match_path_chars()

static bool mysqlrouter::match_path_chars ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  path_chars 
)
static

◆ match_path_empty()

static bool mysqlrouter::match_path_empty ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  path 
)
static

◆ match_path_rootless()

static bool mysqlrouter::match_path_rootless ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  path 
)
static

◆ match_path_segment()

static bool mysqlrouter::match_path_segment ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  segment 
)
static

◆ match_pct_encoded()

static bool mysqlrouter::match_pct_encoded ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  pct_enc 
)
static

◆ match_port()

static bool mysqlrouter::match_port ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  port 
)
static

◆ match_query()

static bool mysqlrouter::match_query ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  query 
)
static

◆ match_reg_name()

static bool mysqlrouter::match_reg_name ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  reg_name,
bool  with_pct_encoded 
)
static

◆ match_scheme()

static bool mysqlrouter::match_scheme ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  scheme 
)
static

◆ match_userinfo()

static bool mysqlrouter::match_userinfo ( const string &  s,
size_t  pos_start,
size_t &  pos_end,
string &  user_info 
)
static

◆ match_zero_or_more()

static size_t mysqlrouter::match_zero_or_more ( const string &  s,
const string &  pat,
size_t  pos_start = 0 
)
static

◆ metadata_schema_version_is_compatible() [1/2]

bool mysqlrouter::metadata_schema_version_is_compatible ( const mysqlrouter::MetadataSchemaVersion required,
const mysqlrouter::MetadataSchemaVersion available 
)

◆ metadata_schema_version_is_compatible() [2/2]

template<size_t N>
bool mysqlrouter::metadata_schema_version_is_compatible ( const mysqlrouter::MetadataSchemaVersion(&)  required[N],
const mysqlrouter::MetadataSchemaVersion available 
)

◆ ms_to_seconds_string()

std::string mysqlrouter::ms_to_seconds_string ( const std::chrono::milliseconds &  msec)

◆ my_check_access()

bool mysqlrouter::my_check_access ( const std::string &  path)

◆ operator<<()

std::ostream & mysqlrouter::operator<< ( std::ostream &  strm,
const URI uri 
)

◆ pct_decode()

static string mysqlrouter::pct_decode ( const string &  s)
static

◆ pct_encode()

static string mysqlrouter::pct_encode ( const string &  s,
const string &  allowed_chars 
)
static

◆ prompt_password()

string mysqlrouter::prompt_password ( const std::string &  prompt)

Prompts for a password from the console.

◆ query_gr_cluster_count()

static uint64_t mysqlrouter::query_gr_cluster_count ( MySQLSession mysql,
const bool  metadata_v2 
)
static

◆ query_metadata_servers()

static ClusterInfo mysqlrouter::query_metadata_servers ( MySQLSession mysql,
const bool  metadata_v2 
)
static

◆ quote_identifier()

std::string mysqlrouter::quote_identifier ( const std::string &  identifier,
const char  quote_char 
)

◆ quote_identifier_if_needed()

std::string mysqlrouter::quote_identifier_if_needed ( const std::string &  ident,
const char  quote_char 
)

Quotes the given identifier, but only if it needs to be quoted.

http://dev.mysql.com/doc/refman/5.1/en/identifiers.html specifies what is allowed in unquoted identifiers. Leading numbers are not strictly forbidden but discouraged as they may lead to ambiguous behavior.

◆ register_router_v1()

static uint32_t mysqlrouter::register_router_v1 ( const std::string &  router_name,
const bool  overwrite,
const std::string &  hostname_override,
MySQLSession mysql,
mysql_harness::SocketOperationsBase socket_operations 
)
static

◆ register_router_v2()

static uint32_t mysqlrouter::register_router_v2 ( const std::string &  router_name,
const bool  overwrite,
const std::string &  hostname_override,
MySQLSession mysql,
mysql_harness::SocketOperationsBase socket_operations 
)
static

◆ rename_file()

int mysqlrouter::rename_file ( const std::string &  from,
const std::string &  to 
)

renames file, returns 0 if succeed, or positive error code if fails.

The function will overwrite the 'to' file if already exists.

◆ set_owner_if_file_exists()

void mysqlrouter::set_owner_if_file_exists ( const std::string &  filepath,
const std::string &  username,
struct passwd *  user_info_arg,
mysqlrouter::SysUserOperationsBase sys_user_operations 
)

Sets the owner of selected file/directory if it exists.

Exceptions
std::runtime_errorin case of an error
Parameters
filepathpath to the file/directory this operation applies to
usernamename of the system user that should be new owner of the file
user_info_argpasswd structure for the system user that should be new owner of the file
sys_user_operationsobject for the system specific operation that should be used by the function

◆ set_prompt_password()

void mysqlrouter::set_prompt_password ( const std::function< std::string(const std::string &)> &  f)

Override default prompt password function.

◆ set_user()

void mysqlrouter::set_user ( const std::string &  username,
bool  permanently = false,
mysqlrouter::SysUserOperationsBase sys_user_operations = SysUserOperations::instance() 
)

Sets effective user of the calling process.

Exceptions
std::runtime_errorin case of an error
Parameters
usernamename of the system user that the process should switch to
permanentlyif it's tru then if the root is dropping privileges it can't be regained after this call
sys_user_operationsobject for the system specific operation that should be used by the function

◆ set_user_priv()

static void mysqlrouter::set_user_priv ( const std::string &  username,
struct passwd *  user_info_arg,
bool  permanently,
SysUserOperationsBase sys_user_operations 
)
static

◆ setup_metadata_session()

void mysqlrouter::setup_metadata_session ( MySQLSession session)

◆ skip()

static size_t mysqlrouter::skip ( size_t  pos_start,
size_t  match_len 
)
static

◆ split_addr_port() [1/2]

std::pair<std::string, uint16_t> mysqlrouter::split_addr_port ( const std::string  data)

Split host and port.

Parameters
dataa string with hostname and port
Returns
std::pair<string, uint16_t> containing address and port

◆ split_addr_port() [2/2]

std::pair<string, uint16_t> mysqlrouter::split_addr_port ( string  data)

◆ split_query()

static URIQuery mysqlrouter::split_query ( const string &  s)
static

◆ split_userinfo()

static void mysqlrouter::split_userinfo ( const string &  user_info,
string &  username,
string &  password 
)
static

◆ string_format()

string mysqlrouter::string_format ( const char *  format,
  ... 
)

Returns string formatted using given data.

Returns string formatted using given data accepting the same arguments and format specifies as the typical printf.

Parameters
formatspecify how to format the data
...variable argument list containing the data
Returns
formatted text as string

◆ strtoi_checked()

int mysqlrouter::strtoi_checked ( const char *  value,
signed int  default_result = 0 
)
noexcept

Converts char array to signed integer, intuitively.

Using strtol() can be daunting. This function wraps its with logic to ease its use. Features:

  • errno value is unaltered
  • on error, default value is returned
  • unlike strtol(), this function will fail (return default_result) if anything other than digits and sign are present in the char array. Inputs such as " 12" or "abc12.3" will fail, while strtol() would return 12.
Parameters
valuechar array to get converted
default_resultvalue to return in case of nullptr being passed

◆ strtoui_checked()

unsigned mysqlrouter::strtoui_checked ( const char *  value,
unsigned int  default_result = 0 
)
noexcept

Converts char array to unsigned integer, intuitively.

adding check for null parameter and some conversion restrictions.

Using strtoul() can be daunting. This function wraps its with logic to ease its use. Features:

  • errno value is unaltered
  • on error, default value is returned
  • unlike strtoul(), this function will fail (return default_result) if anything other than digits and sign are present in the char array. Inputs such as " 12" or "abc12.3" will fail, while strtoul() would return 12.
Parameters
valuechar array to get converted
default_resultvalue to return in case of nullptr being passed

◆ strtoX_checked_common()

template<typename RET >
static RET mysqlrouter::strtoX_checked_common ( const char *  value,
RET  default_value 
)
staticnoexcept

◆ substitute_envvar()

bool mysqlrouter::substitute_envvar ( std::string &  line)
noexcept

Substitutes placeholders of environment variables in a string.

Substitutes placeholders of environement variables in a string. A placeholder contains the name of the variable and will be fetched from the environment. The substitution is done in-place.

Note that it is not an error to pass a string with no variable to be substituted - in such case success will be returned, and the original string will remain unchanged. Also note, that if an error occurs, the resulting string value is undefined (it will be left in an inconsistent state).

Returns
bool (success flag)

◆ substitute_variable()

std::string mysqlrouter::substitute_variable ( const std::string &  s,
const std::string &  name,
const std::string &  value 
)

◆ to_string() [1/4]

std::string mysqlrouter::to_string ( const MetadataSchemaVersion version)

◆ to_string() [2/4]

template<size_t N>
std::string mysqlrouter::to_string ( const mysqlrouter::MetadataSchemaVersion(&)  version[N])

◆ to_string() [3/4]

std::string mysqlrouter::to_string ( const ClusterType  cluster_type)

◆ to_string() [4/4]

template<typename T >
std::string mysqlrouter::to_string ( const T &  data)

◆ update_router_info_v1()

static void mysqlrouter::update_router_info_v1 ( const uint32_t  router_id,
const std::string &  rw_endpoint,
const std::string &  ro_endpoint,
const std::string &  rw_x_endpoint,
const std::string &  ro_x_endpoint,
const std::string &  username,
MySQLSession mysql 
)
static

◆ update_router_info_v2()

static void mysqlrouter::update_router_info_v2 ( const uint32_t  router_id,
const std::string &  cluster_id,
const std::string &  rw_endpoint,
const std::string &  ro_endpoint,
const std::string &  rw_x_endpoint,
const std::string &  ro_x_endpoint,
const std::string &  username,
MySQLSession mysql 
)
static

◆ verify_router_id_is_ours_v1()

static void mysqlrouter::verify_router_id_is_ours_v1 ( const uint32_t  router_id,
const std::string &  hostname_override,
MySQLSession mysql,
mysql_harness::SocketOperationsBase socket_operations 
)
static

◆ verify_router_id_is_ours_v2()

static void mysqlrouter::verify_router_id_is_ours_v2 ( const uint32_t  router_id,
const std::string &  hostname_override,
MySQLSession mysql,
mysql_harness::SocketOperationsBase socket_operations 
)
static

Variable Documentation

◆ g_prompt_password

std::function<string(const string &)> mysqlrouter::g_prompt_password
static
Initial value:
=
static string default_prompt_password(const string &prompt)
Definition: utils.cc:387

◆ kDefaultSqlMode

constexpr const char* mysqlrouter::kDefaultSqlMode
Initial value:
=
"ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,"
"NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"

◆ kNewMetadataVersion

constexpr MetadataSchemaVersion mysqlrouter::kNewMetadataVersion {2, 0, 0}

◆ kRequiredBootstrapSchemaVersion

constexpr MetadataSchemaVersion mysqlrouter::kRequiredBootstrapSchemaVersion[]
Initial value:
{{1, 0, 0},
{2, 0, 0}}

◆ kRequiredRoutingMetadataSchemaVersion

constexpr MetadataSchemaVersion mysqlrouter::kRequiredRoutingMetadataSchemaVersion[]
Initial value:
{
{1, 0, 0}, {2, 0, 0}}

◆ kStrictDirectoryPerm

const perm_mode mysqlrouter::kStrictDirectoryPerm = S_IRWXU

Constant for directory accessible only for the owner.

◆ kUpgradeInProgressMetadataVersion

constexpr MetadataSchemaVersion mysqlrouter::kUpgradeInProgressMetadataVersion {0, 0, 0}